coverage_test.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // TODO: This can only fire if the first message in a diagnostic is rooted
  36. // in a file other than the file being compiled. The language server
  37. // currently only supports compiling one file at a time. Do one of:
  38. // - When imports are supported, find a diagnostic whose first message isn't
  39. // in the current file.
  40. // - Require all diagnostics produced by compiling have their first location
  41. // be in the file being compiled, never an import.
  42. DiagnosticKind::LanguageServerDiagnosticInWrongFile,
  43. };
  44. // Looks for diagnostic kinds that aren't covered by a file_test.
  45. TEST(Coverage, DiagnosticKind) {
  46. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  47. R"(^ *// CHECK:STDERR: .* \[(\w+)\]$)",
  48. llvm::ArrayRef(DiagnosticKinds),
  49. llvm::ArrayRef(UntestedDiagnosticKinds));
  50. }
  51. } // namespace
  52. } // namespace Carbon