2014-12-06 05:52:58 +08:00
|
|
|
//===- 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());
|
|
|
|
}
|
|
|
|
|
2017-05-03 08:28:49 +08:00
|
|
|
// Check that SuppressAfterFatalError works as intended
|
|
|
|
TEST(DiagnosticTest, suppressAfterFatalError) {
|
|
|
|
for (unsigned Suppress = 0; Suppress != 2; ++Suppress) {
|
|
|
|
DiagnosticsEngine Diags(new DiagnosticIDs(),
|
|
|
|
new DiagnosticOptions,
|
|
|
|
new IgnoringDiagConsumer());
|
|
|
|
Diags.setSuppressAfterFatalError(Suppress);
|
2016-03-01 18:56:19 +08:00
|
|
|
|
2017-05-03 08:28:49 +08:00
|
|
|
// Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
|
|
|
|
Diags.Report(diag::err_cannot_open_file) << "file" << "error";
|
2016-03-01 18:56:19 +08:00
|
|
|
|
2017-05-03 08:28:49 +08:00
|
|
|
// Diag that would set FatalErrorOccurred
|
|
|
|
// (via non-note following a fatal error).
|
|
|
|
Diags.Report(diag::warn_mt_message) << "warning";
|
2016-03-01 18:56:19 +08:00
|
|
|
|
2017-05-03 08:28:49 +08:00
|
|
|
EXPECT_TRUE(Diags.hasErrorOccurred());
|
|
|
|
EXPECT_TRUE(Diags.hasFatalErrorOccurred());
|
|
|
|
EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
|
|
|
|
EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
|
2016-03-01 18:56:19 +08:00
|
|
|
|
2017-05-03 08:28:49 +08:00
|
|
|
// The warning should be emitted and counted only if we're not suppressing
|
|
|
|
// after fatal errors.
|
|
|
|
EXPECT_EQ(Diags.getNumWarnings(), Suppress ? 0u : 1u);
|
|
|
|
}
|
2016-03-01 18:56:19 +08:00
|
|
|
}
|
|
|
|
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|