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