coverage_test.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 can only fire if the first message in a diagnostic is rooted
  38. // in a file other than the file being compiled. The language server
  39. // currently only supports compiling one file at a time. Do one of:
  40. // - When imports are supported, find a diagnostic whose first message isn't
  41. // in the current file.
  42. // - Require all diagnostics produced by compiling have their first location
  43. // be in the file being compiled, never an import.
  44. Kind::LanguageServerDiagnosticInWrongFile,
  45. // TODO: This can only fire if we attempt to convert a non-reference
  46. // expression to a durable reference binding. At the moment, the only time
  47. // we attempt reference binding is within a `var` pattern, where the
  48. // conversion cannot fail. This should be covered once we support `ref`
  49. // binding syntax.
  50. Kind::ConversionFailureNonRefToRef,
  51. };
  52. // Looks for diagnostic kinds that aren't covered by a file_test.
  53. TEST(Coverage, Kind) {
  54. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  55. R"(^ *// CHECK:STDERR: .* \[(\w+)\]$)",
  56. llvm::ArrayRef(Kinds),
  57. llvm::ArrayRef(UntestedKinds));
  58. }
  59. } // namespace
  60. } // namespace Carbon::Diagnostics