blob: 4ffa0837bd6e76ce5160a7c8f35700cedea6e82c [file] [log] [blame]
Stephen Hines0e2c34f2015-03-23 12:09:02 -07001//===- 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
14using namespace llvm;
15using namespace clang;
16
17namespace {
18
19// Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
20TEST(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
Pirama Arumuga Nainar4967a712016-09-19 22:19:55 -070049// Check that FatalsAsErrors works as intended
50TEST(DiagnosticTest, fatalsAsErrors) {
51 DiagnosticsEngine Diags(new DiagnosticIDs(),
52 new DiagnosticOptions,
53 new IgnoringDiagConsumer());
54 Diags.setFatalsAsError(true);
55
56 // Diag that would set UncompilableErrorOccurred and ErrorOccurred.
57 Diags.Report(diag::err_target_unknown_triple) << "unknown";
58
59 // Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
60 Diags.Report(diag::err_cannot_open_file) << "file" << "error";
61
62 // Diag that would set FatalErrorOccurred
63 // (via non-note following a fatal error).
64 Diags.Report(diag::warn_mt_message) << "warning";
65
66 EXPECT_TRUE(Diags.hasErrorOccurred());
67 EXPECT_FALSE(Diags.hasFatalErrorOccurred());
68 EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
69 EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
70}
71
Stephen Hines0e2c34f2015-03-23 12:09:02 -070072}