jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch uses a different command-line arguments to test
`clang::tooling::ToolInvocation` in order to simplify downstream integration.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D110160
Files:
clang/unittests/Tooling/ToolingTest.cpp
Index: clang/unittests/Tooling/ToolingTest.cpp
===================================================================
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -15,6 +15,7 @@
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
#include "clang/Tooling/ArgumentsAdjusters.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "clang/Tooling/Tooling.h"
@@ -224,16 +225,6 @@
EXPECT_TRUE(Invocation.run());
}
-struct ErrorCountingDiagnosticConsumer : public DiagnosticConsumer {
- ErrorCountingDiagnosticConsumer() : NumErrorsSeen(0) {}
- void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
- const Diagnostic &Info) override {
- if (DiagLevel == DiagnosticsEngine::Level::Error)
- ++NumErrorsSeen;
- }
- unsigned NumErrorsSeen;
-};
-
TEST(ToolInvocation, DiagnosticsEngineProperlyInitializedForCC1Construction) {
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(
new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
@@ -245,24 +236,23 @@
std::vector<std::string> Args;
Args.push_back("tool-executable");
- Args.push_back("-target");
- // Invalid argument that by default results in an error diagnostic:
- Args.push_back("i386-apple-ios14.0-simulator");
- // Argument that downgrades the error into a warning:
- Args.push_back("-Wno-error=invalid-ios-deployment-target");
+ // Invalid argument (non-existent sysroot path) that will result in a warning.
+ Args.push_back("-isysroot");
+ Args.push_back("/dev/null/sysroot");
+ // Argument that will suppress the warning above.
+ Args.push_back("-Wno-missing-sysroot");
Args.push_back("-fsyntax-only");
Args.push_back("test.cpp");
clang::tooling::ToolInvocation Invocation(
Args, std::make_unique<SyntaxOnlyAction>(), Files.get());
InMemoryFileSystem->addFile(
- "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
- ErrorCountingDiagnosticConsumer Consumer;
+ "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void a() {}\n"));
+ TextDiagnosticBuffer Consumer;
Invocation.setDiagnosticConsumer(&Consumer);
EXPECT_TRUE(Invocation.run());
- // Check that `-Wno-error=invalid-ios-deployment-target` downgraded the error
- // into a warning.
- EXPECT_EQ(Consumer.NumErrorsSeen, 0u);
+ // Check that the warning was ignored due to `-Wno-missing-sysroot`.
+ EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 0u);
}
TEST(ToolInvocation, CustomDiagnosticOptionsOverwriteParsedOnes) {
@@ -276,28 +266,29 @@
std::vector<std::string> Args;
Args.push_back("tool-executable");
- Args.push_back("-target");
- // Invalid argument that by default results in an error diagnostic:
- Args.push_back("i386-apple-ios14.0-simulator");
- // Argument that downgrades the error into a warning:
- Args.push_back("-Wno-error=invalid-ios-deployment-target");
+ // Invalid argument (non-existent sysroot path) that will result in a warning.
+ Args.push_back("-isysroot");
+ Args.push_back("/dev/null/sysroot");
+ // Argument that will suppress the warning above.
+ Args.push_back("-Wno-missing-sysroot");
Args.push_back("-fsyntax-only");
Args.push_back("test.cpp");
clang::tooling::ToolInvocation Invocation(
Args, std::make_unique<SyntaxOnlyAction>(), Files.get());
InMemoryFileSystem->addFile(
- "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
- ErrorCountingDiagnosticConsumer Consumer;
+ "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void a() {}\n"));
+ TextDiagnosticBuffer Consumer;
Invocation.setDiagnosticConsumer(&Consumer);
+ // Inject custom `DiagnosticOptions` for command-line parsing.
auto DiagOpts = llvm::makeIntrusiveRefCnt<DiagnosticOptions>();
Invocation.setDiagnosticOptions(&*DiagOpts);
EXPECT_TRUE(Invocation.run());
- // Check that `-Wno-error=invalid-ios-deployment-target` didn't downgrade the
- // error into a warning due to being overwritten by custom diagnostic options.
- EXPECT_EQ(Consumer.NumErrorsSeen, 1u);
+ // Check that the warning was issued during command-line parsing due to the
+ // custom `DiagnosticOptions` without `-Wno-missing-sysroot`.
+ EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 1u);
}
struct DiagnosticConsumerExpectingSourceManager : public DiagnosticConsumer {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits