ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
return [](const CommandLineArguments &Args, StringRef /*unused*/) {
CommandLineArguments AdjustedArgs;
+ bool HasSyntaxOnly = false;
for (size_t i = 0, e = Args.size(); i < e; ++i) {
StringRef Arg = Args[i];
// FIXME: Remove options that generate output.
if (!Arg.startswith("-fcolor-diagnostics") &&
!Arg.startswith("-fdiagnostics-color"))
AdjustedArgs.push_back(Args[i]);
+ if (Arg == "-fsyntax-only")
+ HasSyntaxOnly = true;
}
- AdjustedArgs.push_back("-fsyntax-only");
+ if (!HasSyntaxOnly)
+ AdjustedArgs.push_back("-fsyntax-only");
return AdjustedArgs;
};
}
EXPECT_FALSE(Found);
}
+TEST(ClangToolTest, NoDoubleSyntaxOnly) {
+ FixedCompilationDatabase Compilations("/", {"-fsyntax-only"});
+
+ ClangTool Tool(Compilations, std::vector<std::string>(1, "/a.cc"));
+ Tool.mapVirtualFile("/a.cc", "void a() {}");
+
+ std::unique_ptr<FrontendActionFactory> Action(
+ newFrontendActionFactory<SyntaxOnlyAction>());
+
+ size_t SyntaxOnlyCount = 0;
+ ArgumentsAdjuster CheckSyntaxOnlyAdjuster =
+ [&SyntaxOnlyCount](const CommandLineArguments &Args,
+ StringRef /*unused*/) {
+ for (llvm::StringRef Arg : Args) {
+ if (Arg == "-fsyntax-only")
+ ++SyntaxOnlyCount;
+ }
+ return Args;
+ };
+
+ Tool.clearArgumentsAdjusters();
+ Tool.appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
+ Tool.appendArgumentsAdjuster(CheckSyntaxOnlyAdjuster);
+ Tool.run(Action.get());
+ EXPECT_EQ(SyntaxOnlyCount, 1U);
+}
+
TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
FixedCompilationDatabase Compilations("/", std::vector<std::string>());
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(