coverage_test.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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::IncompleteTypeInFunctionParam,
  37. DiagnosticKind::InvalidDigit,
  38. DiagnosticKind::InvalidDigitSeparator,
  39. DiagnosticKind::InvalidHorizontalWhitespaceInString,
  40. DiagnosticKind::MismatchedIndentInString,
  41. DiagnosticKind::ModifierPrivateNotAllowed,
  42. DiagnosticKind::MultiLineStringWithDoubleQuotes,
  43. DiagnosticKind::NameAmbiguousDueToExtend,
  44. DiagnosticKind::TooManyDigits,
  45. DiagnosticKind::UnaryOperatorRequiresWhitespace,
  46. DiagnosticKind::UnicodeEscapeSurrogate,
  47. DiagnosticKind::UnicodeEscapeTooLarge,
  48. DiagnosticKind::UnknownBaseSpecifier,
  49. DiagnosticKind::UnsupportedCRLineEnding,
  50. DiagnosticKind::UnsupportedLFCRLineEnding,
  51. };
  52. // Looks for diagnostic kinds that aren't covered by a file_test.
  53. TEST(Coverage, DiagnosticKind) {
  54. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  55. R"(^ *// CHECK:STDERR: .*\.carbon:.* \[(\w+)\]$)",
  56. llvm::ArrayRef(DiagnosticKinds),
  57. llvm::ArrayRef(UntestedDiagnosticKinds));
  58. }
  59. } // namespace
  60. } // namespace Carbon