summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-12-05 21:52:58 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-12-05 21:52:58 +0000
commit8c585cdfb1053afa9b1c81bd0db1f1c3c20d1d67 (patch)
treed5e71018b6a48822c632d3951d5c80bff1d4046e /unittests
parentdcbb8fe6d53e6737e198954850aaa33cf19bdd1d (diff)
Make DiagnosticErrorTrap work even if SuppressAllDiagnostics is enabled.
Patch by Brad King! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223525 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Basic/CMakeLists.txt1
-rw-r--r--unittests/Basic/DiagnosticTest.cpp49
2 files changed, 50 insertions, 0 deletions
diff --git a/unittests/Basic/CMakeLists.txt b/unittests/Basic/CMakeLists.txt
index b8f69bf357..3cb3cb8d3c 100644
--- a/unittests/Basic/CMakeLists.txt
+++ b/unittests/Basic/CMakeLists.txt
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_unittest(BasicTests
CharInfoTest.cpp
+ DiagnosticTest.cpp
FileManagerTest.cpp
SourceManagerTest.cpp
VirtualFileSystemTest.cpp
diff --git a/unittests/Basic/DiagnosticTest.cpp b/unittests/Basic/DiagnosticTest.cpp
new file mode 100644
index 0000000000..fa2b56e083
--- /dev/null
+++ b/unittests/Basic/DiagnosticTest.cpp
@@ -0,0 +1,49 @@
+//===- unittests/Basic/DiagnosticTest.cpp -- Diagnostic engine tests ------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+// Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
+TEST(DiagnosticTest, suppressAndTrap) {
+ DiagnosticsEngine Diags(new DiagnosticIDs(),
+ new DiagnosticOptions,
+ new IgnoringDiagConsumer());
+ Diags.setSuppressAllDiagnostics(true);
+
+ {
+ DiagnosticErrorTrap trap(Diags);
+
+ // Diag that would set UncompilableErrorOccurred and ErrorOccurred.
+ Diags.Report(diag::err_target_unknown_triple) << "unknown";
+
+ // Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
+ Diags.Report(diag::err_cannot_open_file) << "file" << "error";
+
+ // Diag that would set FatalErrorOccurred
+ // (via non-note following a fatal error).
+ Diags.Report(diag::warn_mt_message) << "warning";
+
+ EXPECT_TRUE(trap.hasErrorOccurred());
+ EXPECT_TRUE(trap.hasUnrecoverableErrorOccurred());
+ }
+
+ EXPECT_FALSE(Diags.hasErrorOccurred());
+ EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+ EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+ EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+}
+
+}