coverage_test.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // These aren't feasible to test with a normal testcase, but are tested in
  25. // lex/tokenized_buffer_test.cpp.
  26. DiagnosticKind::TooManyTokens,
  27. DiagnosticKind::UnsupportedCRLineEnding,
  28. DiagnosticKind::UnsupportedLFCRLineEnding,
  29. // This is a little long but is tested in lex/numeric_literal_test.cpp.
  30. DiagnosticKind::TooManyDigits,
  31. };
  32. // Looks for diagnostic kinds that aren't covered by a file_test.
  33. TEST(Coverage, DiagnosticKind) {
  34. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  35. R"(^ *// CHECK:STDERR: .*\.carbon:.* \[(\w+)\]$)",
  36. llvm::ArrayRef(DiagnosticKinds),
  37. llvm::ArrayRef(UntestedDiagnosticKinds));
  38. }
  39. } // namespace
  40. } // namespace Carbon