coverage_test.cpp 2.6 KB

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