coverage_test.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. // TODO: LanguageServerDiagnosticInWrongFile currently has coverage, but
  17. // mainly due to incorrect behavior in C++ diagnostics. See
  18. // language_server/testdata/text_document/open_with_cpp_nonexistent.carbon.
  19. // Leaving this TODO here until it's more precisely tested, because the C++
  20. // diagnostics should be fixed (removing coverage); see below TODO.
  21. //
  22. // TODO: This can only fire if the first message in a diagnostic is rooted
  23. // in a file other than the file being compiled. The language server
  24. // currently only supports compiling one file at a time. Do one of:
  25. // - When imports are supported, find a diagnostic whose first message isn't
  26. // in the current file.
  27. // - Require all diagnostics produced by compiling have their first location
  28. // be in the file being compiled, never an import.
  29. // Kind::LanguageServerDiagnosticInWrongFile,
  30. constexpr Kind UntestedKinds[] = {
  31. // These exist only for unit tests.
  32. Kind::TestDiagnostic,
  33. Kind::TestDiagnosticNote,
  34. // Diagnosing erroneous install conditions, but test environments are
  35. // typically correct.
  36. Kind::CompilePreludeManifestError,
  37. Kind::DriverInstallInvalid,
  38. // These diagnose filesystem issues that are hard to unit test.
  39. Kind::ErrorReadingFile,
  40. Kind::ErrorStattingFile,
  41. Kind::FileTooLarge,
  42. // These aren't feasible to test with a normal testcase, but are tested in
  43. // lex/tokenized_buffer_test.cpp.
  44. Kind::TooManyTokens,
  45. Kind::UnsupportedCrLineEnding,
  46. Kind::UnsupportedLfCrLineEnding,
  47. // This is a little long but is tested in lex/numeric_literal_test.cpp.
  48. Kind::TooManyDigits,
  49. };
  50. // Looks for diagnostic kinds that aren't covered by a file_test.
  51. TEST(Coverage, Kind) {
  52. Testing::TestKindCoverage(absl::GetFlag(FLAGS_testdata_manifest),
  53. R"(^ *// CHECK:STDERR: .* \[(\w+)\]$)",
  54. llvm::ArrayRef(Kinds),
  55. llvm::ArrayRef(UntestedKinds));
  56. }
  57. } // namespace
  58. } // namespace Carbon::Diagnostics