Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 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 | |
| 10 | #include "clang/Basic/Diagnostic.h" |
| 11 | #include "clang/Basic/DiagnosticIDs.h" |
| 12 | #include "gtest/gtest.h" |
| 13 | |
| 14 | using namespace llvm; |
| 15 | using namespace clang; |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | // Check that DiagnosticErrorTrap works with SuppressAllDiagnostics. |
| 20 | TEST(DiagnosticTest, suppressAndTrap) { |
| 21 | DiagnosticsEngine Diags(new DiagnosticIDs(), |
| 22 | new DiagnosticOptions, |
| 23 | new IgnoringDiagConsumer()); |
| 24 | Diags.setSuppressAllDiagnostics(true); |
| 25 | |
| 26 | { |
| 27 | DiagnosticErrorTrap trap(Diags); |
| 28 | |
| 29 | // Diag that would set UncompilableErrorOccurred and ErrorOccurred. |
| 30 | Diags.Report(diag::err_target_unknown_triple) << "unknown"; |
| 31 | |
| 32 | // Diag that would set UnrecoverableErrorOccurred and ErrorOccurred. |
| 33 | Diags.Report(diag::err_cannot_open_file) << "file" << "error"; |
| 34 | |
| 35 | // Diag that would set FatalErrorOccurred |
| 36 | // (via non-note following a fatal error). |
| 37 | Diags.Report(diag::warn_mt_message) << "warning"; |
| 38 | |
| 39 | EXPECT_TRUE(trap.hasErrorOccurred()); |
| 40 | EXPECT_TRUE(trap.hasUnrecoverableErrorOccurred()); |
| 41 | } |
| 42 | |
| 43 | EXPECT_FALSE(Diags.hasErrorOccurred()); |
| 44 | EXPECT_FALSE(Diags.hasFatalErrorOccurred()); |
| 45 | EXPECT_FALSE(Diags.hasUncompilableErrorOccurred()); |
| 46 | EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred()); |
| 47 | } |
| 48 | |
| 49 | } |