coverage_test.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. // These aren't feasible to test with a normal testcase, but are tested in
  29. // lex/tokenized_buffer_test.cpp.
  30. Kind::TooManyTokens,
  31. Kind::UnsupportedCrLineEnding,
  32. Kind::UnsupportedLfCrLineEnding,
  33. // This is a little long but is tested in lex/numeric_literal_test.cpp.
  34. Kind::TooManyDigits,
  35. // Producing an emit failure may be infeasible.
  36. Kind::CodeGenUnableToEmit,
  37. // TODO: This is currently hard to test because it requires building and
  38. // importing a module, which attempts to create additional files with
  39. // unpredictable names in the module cache, which bazel doesn't permit.
  40. Kind::InCppModule,
  41. // TODO: This can only fire if the first message in a diagnostic is rooted
  42. // in a file other than the file being compiled. The language server
  43. // currently only supports compiling one file at a time. Do one of:
  44. // - When imports are supported, find a diagnostic whose first message isn't
  45. // in the current file.
  46. // - Require all diagnostics produced by compiling have their first location
  47. // be in the file being compiled, never an import.
  48. Kind::LanguageServerDiagnosticInWrongFile,
  49. // TODO: This can only fire if we attempt to convert a non-reference
  50. // expression to a durable reference binding. At the moment, the only time
  51. // we attempt reference binding is within a `var` pattern, where the
  52. // conversion cannot fail. This should be covered once we support `ref`
  53. // binding syntax.
  54. Kind::ConversionFailureNonRefToRef,
  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