coverage_test.cpp 2.8 KB

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