DiagnosticTest.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //===- unittests/Basic/DiagnosticTest.cpp -- Diagnostic engine tests ------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "clang/Basic/Diagnostic.h"
  10. #include "clang/Basic/DiagnosticIDs.h"
  11. #include "gtest/gtest.h"
  12. using namespace llvm;
  13. using namespace clang;
  14. namespace {
  15. // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
  16. TEST(DiagnosticTest, suppressAndTrap) {
  17. DiagnosticsEngine Diags(new DiagnosticIDs(),
  18. new DiagnosticOptions,
  19. new IgnoringDiagConsumer());
  20. Diags.setSuppressAllDiagnostics(true);
  21. {
  22. DiagnosticErrorTrap trap(Diags);
  23. // Diag that would set UncompilableErrorOccurred and ErrorOccurred.
  24. Diags.Report(diag::err_target_unknown_triple) << "unknown";
  25. // Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
  26. Diags.Report(diag::err_cannot_open_file) << "file" << "error";
  27. // Diag that would set FatalErrorOccurred
  28. // (via non-note following a fatal error).
  29. Diags.Report(diag::warn_mt_message) << "warning";
  30. EXPECT_TRUE(trap.hasErrorOccurred());
  31. EXPECT_TRUE(trap.hasUnrecoverableErrorOccurred());
  32. }
  33. EXPECT_FALSE(Diags.hasErrorOccurred());
  34. EXPECT_FALSE(Diags.hasFatalErrorOccurred());
  35. EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
  36. EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
  37. }
  38. }