coverage_test.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include <gtest/gtest.h>
  5. #include "absl/flags/flag.h"
  6. #include "toolchain/diagnostics/diagnostic_kind.h"
  7. #include "toolchain/testing/coverage_helper.h"
  8. ABSL_FLAG(std::string, testdata_manifest, "",
  9. "A path to a file containing repo-relative names of test files.");
  10. namespace Carbon {
  11. namespace {
  12. constexpr DiagnosticKind DiagnosticKinds[] = {
  13. #define CARBON_DIAGNOSTIC_KIND(Name) DiagnosticKind::Name,
  14. #include "toolchain/diagnostics/diagnostic_kind.def"
  15. };
  16. constexpr DiagnosticKind UntestedDiagnosticKinds[] = {
  17. // These exist only for unit tests.
  18. DiagnosticKind::TestDiagnostic,
  19. DiagnosticKind::TestDiagnosticNote,
  20. // These diagnose filesystem issues that are hard to unit test.
  21. DiagnosticKind::ErrorReadingFile,
  22. DiagnosticKind::ErrorStattingFile,
  23. DiagnosticKind::FileTooLarge,
  24. // Int literals are currently limited to i32. Once that's fixed, this
  25. // should be tested.
  26. DiagnosticKind::ArrayBoundTooLarge,
  27. // This isn't feasible to test with a normal testcase, but is tested in
  28. // lex/tokenized_buffer_test.cpp.
  29. DiagnosticKind::TooManyTokens,
  30. // TODO: Should look closer at these, but adding tests is a high risk of
  31. // loss in merge conflicts due to the amount of tests being changed right
  32. // now.
  33. DiagnosticKind::ExternLibraryInImporter,
  34. DiagnosticKind::ExternLibraryOnDefinition,
  35. DiagnosticKind::HexadecimalEscapeMissingDigits,
  36. DiagnosticKind::ImplOfUndefinedInterface,
  37. DiagnosticKind::IncompleteTypeInFunctionParam,
  38. DiagnosticKind::InvalidDigit,
  39. DiagnosticKind::InvalidDigitSeparator,
  40. DiagnosticKind::InvalidHorizontalWhitespaceInString,
  41. DiagnosticKind::MismatchedIndentInString,
  42. DiagnosticKind::ModifierPrivateNotAllowed,
  43. DiagnosticKind::MultiLineStringWithDoubleQuotes,
  44. DiagnosticKind::NameAmbiguousDueToExtend,
  45. DiagnosticKind::TooManyDigits,
  46. DiagnosticKind::UnaryOperatorRequiresWhitespace,
  47. DiagnosticKind::UnicodeEscapeSurrogate,
  48. DiagnosticKind::UnicodeEscapeTooLarge,
  49. DiagnosticKind::UnknownBaseSpecifier,
  50. DiagnosticKind::UnsupportedCRLineEnding,
  51. DiagnosticKind::UnsupportedLFCRLineEnding,
  52. };
  53. // Looks for diagnostic kinds that aren't covered by a file_test.
  54. TEST(Coverage, DiagnosticKind) {
  55. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  56. R"(^ *// CHECK:STDERR: .*\.carbon:.* \[(\w+)\]$)",
  57. llvm::ArrayRef(DiagnosticKinds),
  58. llvm::ArrayRef(UntestedDiagnosticKinds));
  59. }
  60. } // namespace
  61. } // namespace Carbon