DiagnosticTest.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // Check that FatalsAsErrors works as intended
  39. TEST(DiagnosticTest, fatalsAsErrors) {
  40. DiagnosticsEngine Diags(new DiagnosticIDs(),
  41. new DiagnosticOptions,
  42. new IgnoringDiagConsumer());
  43. Diags.setFatalsAsError(true);
  44. // Diag that would set UncompilableErrorOccurred and ErrorOccurred.
  45. Diags.Report(diag::err_target_unknown_triple) << "unknown";
  46. // Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
  47. Diags.Report(diag::err_cannot_open_file) << "file" << "error";
  48. // Diag that would set FatalErrorOccurred
  49. // (via non-note following a fatal error).
  50. Diags.Report(diag::warn_mt_message) << "warning";
  51. EXPECT_TRUE(Diags.hasErrorOccurred());
  52. EXPECT_FALSE(Diags.hasFatalErrorOccurred());
  53. EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
  54. EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
  55. }
  56. }