coverage_test.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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::Diagnostics {
  11. namespace {
  12. constexpr Kind Kinds[] = {
  13. #define CARBON_DIAGNOSTIC_KIND(Name) Kind::Name,
  14. #include "toolchain/diagnostics/diagnostic_kind.def"
  15. };
  16. constexpr Kind UntestedKinds[] = {
  17. // These exist only for unit tests.
  18. Kind::TestDiagnostic,
  19. Kind::TestDiagnosticNote,
  20. // Diagnosing erroneous install conditions, but test environments are
  21. // typically correct.
  22. Kind::CompilePreludeManifestError,
  23. Kind::DriverInstallInvalid,
  24. // These diagnose filesystem issues that are hard to unit test.
  25. Kind::ErrorReadingFile,
  26. Kind::ErrorStattingFile,
  27. Kind::FileTooLarge,
  28. Kind::FailureBuildingRuntimes,
  29. Kind::FailureRunningClang,
  30. Kind::FailureRunningClangToLink,
  31. // These aren't feasible to test with a normal testcase, but are tested in
  32. // lex/tokenized_buffer_test.cpp.
  33. Kind::TooManyTokens,
  34. Kind::UnsupportedCrLineEnding,
  35. Kind::UnsupportedLfCrLineEnding,
  36. // This is a little long but is tested in lex/numeric_literal_test.cpp.
  37. Kind::TooManyDigits,
  38. // Producing an emit failure may be infeasible.
  39. Kind::CodeGenUnableToEmit,
  40. // TODO: This is currently hard to test because it requires building and
  41. // importing a module, which attempts to create additional files with
  42. // unpredictable names in the module cache, which bazel doesn't permit.
  43. Kind::InCppModule,
  44. // TODO: This can only fire if the first message in a diagnostic is rooted
  45. // in a file other than the file being compiled. The language server
  46. // currently only supports compiling one file at a time. Do one of:
  47. // - When imports are supported, find a diagnostic whose first message isn't
  48. // in the current file.
  49. // - Require all diagnostics produced by compiling have their first location
  50. // be in the file being compiled, never an import.
  51. Kind::LanguageServerDiagnosticInWrongFile,
  52. };
  53. // Looks for diagnostic kinds that aren't covered by a file_test.
  54. TEST(Coverage, Kind) {
  55. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  56. R"(^ *// CHECK:STDERR: .* \[(\w+)\]$)",
  57. llvm::ArrayRef(Kinds),
  58. llvm::ArrayRef(UntestedKinds));
  59. }
  60. } // namespace
  61. } // namespace Carbon::Diagnostics