coverage_test.cpp 2.8 KB

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