coverage_test.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // Diagnosing erroneous install conditions, but test environments are
  21. // typically correct.
  22. DiagnosticKind::CompilePreludeManifestError,
  23. DiagnosticKind::DriverInstallInvalid,
  24. // These diagnose filesystem issues that are hard to unit test.
  25. DiagnosticKind::ErrorReadingFile,
  26. DiagnosticKind::ErrorStattingFile,
  27. DiagnosticKind::FileTooLarge,
  28. // These aren't feasible to test with a normal testcase, but are tested in
  29. // lex/tokenized_buffer_test.cpp.
  30. DiagnosticKind::TooManyTokens,
  31. DiagnosticKind::UnsupportedCRLineEnding,
  32. DiagnosticKind::UnsupportedLFCRLineEnding,
  33. // This is a little long but is tested in lex/numeric_literal_test.cpp.
  34. DiagnosticKind::TooManyDigits,
  35. };
  36. // Looks for diagnostic kinds that aren't covered by a file_test.
  37. TEST(Coverage, DiagnosticKind) {
  38. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  39. R"(^ *// CHECK:STDERR: .* \[(\w+)\]$)",
  40. llvm::ArrayRef(DiagnosticKinds),
  41. llvm::ArrayRef(UntestedDiagnosticKinds));
  42. }
  43. } // namespace
  44. } // namespace Carbon