coverage_test.cpp 2.9 KB

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