From 7fe65851d99465d8bd9506ba53d8772381666111 Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Wed, 30 Jan 2019 13:59:30 +0100 Subject: [PATCH] Clang: Extend ClangTool and CommandLineBuilder We now support source file and not only header files and the file path is now automatically added to the end. This removes quite some clutter. Change-Id: I74eabd262e6c7e5f4d523e3a3cd194bd3efe1ef3 Reviewed-by: Ivan Donchevskii --- src/libs/clangsupport/commandlinebuilder.h | 20 ++- .../source/builddependencycollector.cpp | 4 +- .../source/pchcreator.cpp | 6 +- .../source/pchcreator.h | 1 - .../source/clangtool.cpp | 25 ++-- .../source/clangtool.h | 2 +- .../source/symbolindexer.cpp | 5 +- tests/unit/unittest/clangquery-test.cpp | 12 +- .../unit/unittest/clangquerygatherer-test.cpp | 3 - .../unit/unittest/commandlinebuilder-test.cpp | 138 +++++++++++++----- tests/unit/unittest/pchcreator-test.cpp | 14 +- .../refactoringclientserverinprocess-test.cpp | 39 ++--- .../unit/unittest/refactoringserver-test.cpp | 40 ++--- .../unittest/sourcerangeextractor-test.cpp | 4 +- tests/unit/unittest/symbolfinder-test.cpp | 64 ++------ tests/unit/unittest/symbolindexer-test.cpp | 16 +- 16 files changed, 196 insertions(+), 197 deletions(-) diff --git a/src/libs/clangsupport/commandlinebuilder.h b/src/libs/clangsupport/commandlinebuilder.h index 03d042322d9..b270d75d850 100644 --- a/src/libs/clangsupport/commandlinebuilder.h +++ b/src/libs/clangsupport/commandlinebuilder.h @@ -35,12 +35,15 @@ namespace ClangBackEnd { +enum class InputFileType : unsigned char { Header, Source }; + template class CommandLineBuilder { public: CommandLineBuilder(const ProjectInfo &projectInfo, const Utils::SmallStringVector &toolChainArguments = {}, + InputFileType sourceType = InputFileType::Header, FilePathView sourcePath = {}, FilePathView outputPath = {}, FilePathView includePchPath = {}) @@ -49,7 +52,7 @@ public: addCompiler(projectInfo.language); addToolChainArguments(toolChainArguments); - addLanguage(projectInfo); + addLanguage(projectInfo, sourceType); addLanguageVersion(projectInfo); addNoStdIncAndNoStdLibInc(); addCompilerMacros(projectInfo.compilerMacros); @@ -76,26 +79,27 @@ public: commandLine.emplace_back(argument); } - static const char *language(const ProjectInfo &projectInfo) + static const char *language(const ProjectInfo &projectInfo, InputFileType sourceType) { switch (projectInfo.language) { case Utils::Language::C: if (projectInfo.languageExtension && Utils::LanguageExtension::ObjectiveC) - return "objective-c-header"; + return sourceType == InputFileType::Header ? "objective-c-header" : "objective-c"; - return "c-header"; + return sourceType == InputFileType::Header ? "c-header" : "c"; case Utils::Language::Cxx: if (projectInfo.languageExtension && Utils::LanguageExtension::ObjectiveC) - return "objective-c++-header"; + return sourceType == InputFileType::Header ? "objective-c++-header" + : "objective-c++"; } - return "c++-header"; + return sourceType == InputFileType::Header ? "c++-header" : "c++"; } - void addLanguage(const ProjectInfo &projectInfo) + void addLanguage(const ProjectInfo &projectInfo, InputFileType sourceType) { commandLine.emplace_back("-x"); - commandLine.emplace_back(language(projectInfo)); + commandLine.emplace_back(language(projectInfo, sourceType)); } const char *standardLanguageVersion(Utils::LanguageVersion languageVersion) diff --git a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp index 6647d02531d..ec5f3bdcb00 100644 --- a/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp +++ b/src/tools/clangpchmanagerbackend/source/builddependencycollector.cpp @@ -47,8 +47,8 @@ FilePathIds operator+(const FilePathIds &first, const FilePathIds &second) BuildDependency BuildDependencyCollector::create(const ProjectPartContainer &projectPart) { - CommandLineBuilder builder{ - projectPart, projectPart.toolChainArguments}; + CommandLineBuilder + builder{projectPart, projectPart.toolChainArguments, InputFileType::Source}; addFiles(projectPart.sourcePathIds, builder.commandLine); diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp index 4333d5706ac..845c92412a4 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.cpp +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.cpp @@ -72,7 +72,6 @@ Utils::SmallString PchCreator::generatePchIncludeFileContent(const FilePathIds & return fileContent; } - bool PchCreator::generatePch() { clang::tooling::ClangTool tool = m_clangTool.createOutputTool(); @@ -95,12 +94,12 @@ FilePath PchCreator::generatePchFilePath() const } Utils::SmallStringVector PchCreator::generateClangCompilerArguments(const PchTask &pchTask, - FilePathView sourceFilePath, FilePathView pchOutputPath) { CommandLineBuilder builder{pchTask, pchTask.toolChainArguments, - sourceFilePath, + InputFileType::Header, + {}, pchOutputPath, pchTask.systemPchPath}; @@ -115,7 +114,6 @@ void PchCreator::generatePch(PchTask &&pchTask) FilePath headerFilePath{m_environment.pchBuildDirectory().toStdString(), "dummy.h"}; Utils::SmallStringVector commandLine = generateClangCompilerArguments(pchTask, - headerFilePath, pchOutputPath); m_clangTool.addFile(std::move(headerFilePath), std::move(content), std::move(commandLine)); diff --git a/src/tools/clangpchmanagerbackend/source/pchcreator.h b/src/tools/clangpchmanagerbackend/source/pchcreator.h index 37d0c7c8a1e..6e889ab5657 100644 --- a/src/tools/clangpchmanagerbackend/source/pchcreator.h +++ b/src/tools/clangpchmanagerbackend/source/pchcreator.h @@ -85,7 +85,6 @@ public: FilePath generatePchFilePath() const; static Utils::SmallStringVector generateClangCompilerArguments(const PchTask &pchTask, - FilePathView includePchHeaderPath, FilePathView pchPath); const ClangTool &clangTool() const diff --git a/src/tools/clangrefactoringbackend/source/clangtool.cpp b/src/tools/clangrefactoringbackend/source/clangtool.cpp index 5ae87793dbd..1798504a692 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.cpp +++ b/src/tools/clangrefactoringbackend/source/clangtool.cpp @@ -52,6 +52,9 @@ void ClangTool::addFile(FilePath &&filePath, { NativeFilePath nativeFilePath{filePath}; + if (commandLine.back() != nativeFilePath.path()) + commandLine.emplace_back(nativeFilePath.path()); + m_compilationDatabase.addFile(nativeFilePath, std::move(commandLine)); m_sourceFilePaths.push_back(Utils::SmallStringView{nativeFilePath}); @@ -60,15 +63,8 @@ void ClangTool::addFile(FilePath &&filePath, void ClangTool::addFiles(const FilePaths &filePaths, const Utils::SmallStringVector &arguments) { - for (const FilePath &filePath : filePaths) { - std::string filePathStr(filePath.path()); - auto commandLine = arguments; - NativeFilePath nativeFilePath{filePath}; - - commandLine.push_back(nativeFilePath.path()); - - addFile(filePath.clone(), {}, std::move(commandLine)); - } + for (const FilePath &filePath : filePaths) + addFile(filePath.clone(), {}, arguments.clone()); } void ClangTool::addUnsavedFiles(const V2::FileContainers &unsavedFiles) @@ -104,13 +100,14 @@ clang::tooling::ClangTool ClangTool::createTool() const clang::tooling::ClangTool tool(m_compilationDatabase, m_sourceFilePaths); for (const auto &fileContent : m_fileContents) { - if (!fileContent.content.empty()) - tool.mapVirtualFile(toStringRef(fileContent.filePath), fileContent.content); + if (fileContent.content.hasContent()) + tool.mapVirtualFile(toStringRef(fileContent.filePath), toStringRef(fileContent.content)); } - for (const auto &unsavedFileContent : m_unsavedFileContents) - tool.mapVirtualFile(toStringRef(unsavedFileContent.filePath), - toStringRef(unsavedFileContent.content)); + for (const auto &unsavedFileContent : m_unsavedFileContents) { + tool.mapVirtualFile(toStringRef(unsavedFileContent.filePath), + toStringRef(unsavedFileContent.content)); + } tool.mapVirtualFile("/dummyFile", "#pragma once"); diff --git a/src/tools/clangrefactoringbackend/source/clangtool.h b/src/tools/clangrefactoringbackend/source/clangtool.h index e3ff8357998..2abad0f49b5 100644 --- a/src/tools/clangrefactoringbackend/source/clangtool.h +++ b/src/tools/clangrefactoringbackend/source/clangtool.h @@ -50,7 +50,7 @@ struct FileContent {} NativeFilePath filePath; - std::string content; + Utils::SmallString content; }; struct UnsavedFileContent diff --git a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp index 2ee454eadb1..d3d0f4a505e 100644 --- a/src/tools/clangrefactoringbackend/source/symbolindexer.cpp +++ b/src/tools/clangrefactoringbackend/source/symbolindexer.cpp @@ -107,6 +107,7 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart) using Builder = CommandLineBuilder; Builder commandLineBuilder{projectPart, projectPart.toolChainArguments, + InputFileType::Source, {}, {}, optionalProjectPartPch @@ -181,8 +182,8 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId, auto pchPath = optionalProjectPartPch ? optionalProjectPartPch.value().pchPath : FilePath{}; - CommandLineBuilder builder{ - artefact, artefact.toolChainArguments, {}, {}, pchPath}; + CommandLineBuilder + builder{artefact, artefact.toolChainArguments, InputFileType::Source, {}, {}, pchPath}; auto indexing = [projectPartId = artefact.projectPartId, arguments=builder.commandLine, filePathId, this]( SymbolsCollectorInterface &symbolsCollector) { diff --git a/tests/unit/unittest/clangquery-test.cpp b/tests/unit/unittest/clangquery-test.cpp index 35842e01439..77a049210b7 100644 --- a/tests/unit/unittest/clangquery-test.cpp +++ b/tests/unit/unittest/clangquery-test.cpp @@ -96,7 +96,7 @@ TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange) ::ClangQuery query(filePathCache); query.addFile({TESTDATA_DIR "/query_simplefunction.cpp"}, "#include \"unsaved.h\"", - {"cc", toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(), "-std=c++14"}); + {"cc", "-std=c++14"}); query.setQuery("functionDecl()"); ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR, "unsaved.h"}, "void unsaved();", {}}; query.addUnsavedFiles({unsavedFile}); @@ -110,9 +110,7 @@ TEST_F(ClangQuerySlowTest, SourceRangeInUnsavedFileDeclarationRange) TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed) { ::ClangQuery query(filePathCache); - query.addFile({TESTDATA_DIR "/foo.cpp"}, - "void f() {}", - {"cc", toNativePath(TESTDATA_DIR "/foo.cpp").path(), "-std=c++14"}); + query.addFile({TESTDATA_DIR "/foo.cpp"}, "void f() {}", {"cc", "-std=c++14"}); query.setQuery("functionDecl()"); query.findLocations(); @@ -124,9 +122,7 @@ TEST_F(ClangQuerySlowTest, FileIsNotExistingButTheUnsavedDataIsParsed) TEST_F(ClangQuerySlowTest, DISABLED_SourceRangeInUnsavedFileDeclarationRangeOverride) // seems not to work in Clang { ::ClangQuery query(filePathCache); - query.addFile({TESTDATA_DIR "/query_simplefunction.cpp"}, - "void f() {}", - {"cc", toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(), "-std=c++14"}); + query.addFile({TESTDATA_DIR "/query_simplefunction.cpp"}, "void f() {}", {"cc", "-std=c++14"}); query.setQuery("functionDecl()"); ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR "/query_simplefunction.cpp"}, "void unsaved();", @@ -226,12 +222,10 @@ void ClangQuery::SetUp() simpleFunctionQuery.addFile({TESTDATA_DIR "/query_simplefunction.cpp"}, "", {"cc", - toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(), "-std=c++14"}); simpleClassQuery.addFile({TESTDATA_DIR "/query_simpleclass.cpp"}, "", {"cc", - toNativePath(TESTDATA_DIR "/query_simpleclass.cpp").path(), "-std=c++14"}); } } // namespace diff --git a/tests/unit/unittest/clangquerygatherer-test.cpp b/tests/unit/unittest/clangquerygatherer-test.cpp index b0ea9cb3e0e..3b5f9239fed 100644 --- a/tests/unit/unittest/clangquerygatherer-test.cpp +++ b/tests/unit/unittest/clangquerygatherer-test.cpp @@ -88,19 +88,16 @@ protected: FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, sourceContent.clone(), {"cc", - toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path(), "-I", TESTDATA_DIR}}; FileContainer source2{{TESTDATA_DIR, "query_simplefunction2.cpp"}, {}, {"cc", - toNativePath(TESTDATA_DIR "/query_simplefunction2.cpp").path(), "-I", TESTDATA_DIR}}; FileContainer source3{{TESTDATA_DIR, "query_simplefunction3.cpp"}, {}, {"cc", - toNativePath(TESTDATA_DIR "/query_simplefunction3.cpp").path(), "-I", TESTDATA_DIR}}; Utils::SmallString unsavedContent{"void f();"}; diff --git a/tests/unit/unittest/commandlinebuilder-test.cpp b/tests/unit/unittest/commandlinebuilder-test.cpp index 9de48fe0d55..3ec2b032246 100644 --- a/tests/unit/unittest/commandlinebuilder-test.cpp +++ b/tests/unit/unittest/commandlinebuilder-test.cpp @@ -37,6 +37,7 @@ template using Builder = ClangBackEnd::CommandLineBuilder; using ClangBackEnd::IncludeSearchPathType; +using ClangBackEnd::InputFileType; template class CommandLineBuilder : public testing::Test @@ -124,30 +125,41 @@ TYPED_TEST_SUITE(CommandLineBuilder, ProjectInfos); TYPED_TEST(CommandLineBuilder, AddToolChainArguments) { - Builder builder{this->emptyProjectInfo, {"-m64", "-PIC"}, {}}; + Builder builder{this->emptyProjectInfo, {"-m64", "-PIC"}, InputFileType::Header, {}}; ASSERT_THAT(builder.commandLine, AllOf(Contains("-m64"), Contains("-PIC"))); } -TYPED_TEST(CommandLineBuilder, CTask) +TYPED_TEST(CommandLineBuilder, CHeader) { this->emptyProjectInfo.language = Utils::Language::C; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT( builder.commandLine, ElementsAre("clang", "-x", "c-header", "-std=c11", "-nostdinc", "-nostdinc++", toNativePath("/source/file.c").path())); } -TYPED_TEST(CommandLineBuilder, ObjectiveCTask) +TYPED_TEST(CommandLineBuilder, CSource) +{ + this->emptyProjectInfo.language = Utils::Language::C; + this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; + + Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.c"}; + + ASSERT_THAT(builder.commandLine, + ElementsAre("clang", "-x", "c", "-std=c11", "-nostdinc", "-nostdinc++", "/source/file.c")); +} + +TYPED_TEST(CommandLineBuilder, ObjectiveCHeader) { this->emptyProjectInfo.language = Utils::Language::C; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, ElementsAre("clang", @@ -159,12 +171,30 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCTask) toNativePath("/source/file.c").path())); } -TYPED_TEST(CommandLineBuilder, CppTask) +TYPED_TEST(CommandLineBuilder, ObjectiveCSource) +{ + this->emptyProjectInfo.language = Utils::Language::C; + this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; + this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; + + Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.c"}; + + ASSERT_THAT(builder.commandLine, + ElementsAre("clang", + "-x", + "objective-c", + "-std=c11", + "-nostdinc", + "-nostdinc++", + "/source/file.c")); +} + +TYPED_TEST(CommandLineBuilder, CppHeader) { this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, ElementsAre("clang++", @@ -176,13 +206,25 @@ TYPED_TEST(CommandLineBuilder, CppTask) toNativePath("/source/file.cpp").path())); } -TYPED_TEST(CommandLineBuilder, ObjectiveCppTask) +TYPED_TEST(CommandLineBuilder, CppSource) +{ + this->emptyProjectInfo.language = Utils::Language::Cxx; + this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; + + Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.cpp"}; + + ASSERT_THAT( + builder.commandLine, + ElementsAre("clang++", "-x", "c++", "-std=c++98", "-nostdinc", "-nostdinc++", "/source/file.cpp")); +} + +TYPED_TEST(CommandLineBuilder, ObjectiveCppHeader) { this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, ElementsAre("clang++", @@ -194,12 +236,30 @@ TYPED_TEST(CommandLineBuilder, ObjectiveCppTask) toNativePath("/source/file.cpp").path())); } +TYPED_TEST(CommandLineBuilder, ObjectiveCppSource) +{ + this->emptyProjectInfo.language = Utils::Language::Cxx; + this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::ObjectiveC; + this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; + + Builder builder{this->emptyProjectInfo, {}, InputFileType::Source, "/source/file.cpp"}; + + ASSERT_THAT(builder.commandLine, + ElementsAre("clang++", + "-x", + "objective-c++", + "-std=c++98", + "-nostdinc", + "-nostdinc++", + "/source/file.cpp")); +} + TYPED_TEST(CommandLineBuilder, Cpp98) { this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=c++98")); } @@ -209,7 +269,7 @@ TYPED_TEST(CommandLineBuilder, Cpp03) this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX03; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=c++03")); } @@ -219,7 +279,7 @@ TYPED_TEST(CommandLineBuilder, Cpp11) this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX11; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=c++11")); } @@ -229,7 +289,7 @@ TYPED_TEST(CommandLineBuilder, Cpp14) this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX14; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=c++14")); } @@ -239,7 +299,7 @@ TYPED_TEST(CommandLineBuilder, Cpp17) this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX17; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=c++17")); } @@ -249,7 +309,7 @@ TYPED_TEST(CommandLineBuilder, Cpp20) this->emptyProjectInfo.language = Utils::Language::Cxx; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX2a; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=c++2a")); } @@ -260,7 +320,7 @@ TYPED_TEST(CommandLineBuilder, GnuCpp98) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX98; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu++98")); } @@ -271,7 +331,7 @@ TYPED_TEST(CommandLineBuilder, GnuCpp03) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX03; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu++03")); } @@ -282,7 +342,7 @@ TYPED_TEST(CommandLineBuilder, GnuCpp11) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX11; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu++11")); } @@ -293,7 +353,7 @@ TYPED_TEST(CommandLineBuilder, GnuCpp14) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX14; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu++14")); } @@ -304,7 +364,7 @@ TYPED_TEST(CommandLineBuilder, GnuCpp17) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX17; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu++17")); } @@ -315,7 +375,7 @@ TYPED_TEST(CommandLineBuilder, GnuCpp20) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::CXX2a; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu++2a")); } @@ -325,7 +385,7 @@ TYPED_TEST(CommandLineBuilder, C89) this->emptyProjectInfo.language = Utils::Language::C; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C89; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=c89")); } @@ -335,7 +395,7 @@ TYPED_TEST(CommandLineBuilder, C99) this->emptyProjectInfo.language = Utils::Language::C; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C99; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=c99")); } @@ -345,7 +405,7 @@ TYPED_TEST(CommandLineBuilder, C11) this->emptyProjectInfo.language = Utils::Language::C; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=c11")); } @@ -355,7 +415,7 @@ TYPED_TEST(CommandLineBuilder, C18) this->emptyProjectInfo.language = Utils::Language::C; this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C18; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=c18")); } @@ -366,7 +426,7 @@ TYPED_TEST(CommandLineBuilder, GnuC89) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C89; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu89")); } @@ -377,7 +437,7 @@ TYPED_TEST(CommandLineBuilder, GnuC99) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C99; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu99")); } @@ -388,7 +448,7 @@ TYPED_TEST(CommandLineBuilder, GnuC11) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C11; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu11")); } @@ -399,7 +459,7 @@ TYPED_TEST(CommandLineBuilder, GnuC18) this->emptyProjectInfo.languageVersion = Utils::LanguageVersion::C18; this->emptyProjectInfo.languageExtension = Utils::LanguageExtension::Gnu; - Builder builder{this->emptyProjectInfo, {}, "/source/file.c"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.c"}; ASSERT_THAT(builder.commandLine, Contains("-std=gnu18")); } @@ -414,7 +474,7 @@ TYPED_TEST(CommandLineBuilder, IncludesOrder) {"/system/foo", 3, IncludeSearchPathType::Framework}, {"/builtin/bar", 2, IncludeSearchPathType::BuiltIn}, {"/builtin/foo", 1, IncludeSearchPathType::BuiltIn}}; - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, ElementsAre("clang++", @@ -448,7 +508,7 @@ TYPED_TEST(CommandLineBuilder, EmptySourceFile) TYPED_TEST(CommandLineBuilder, SourceFile) { - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp"}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp"}; ASSERT_THAT(builder.commandLine, ElementsAre("clang++", @@ -463,7 +523,7 @@ TYPED_TEST(CommandLineBuilder, SourceFile) TYPED_TEST(CommandLineBuilder, EmptyOutputFile) { - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp", ""}; + Builder builder{this->emptyProjectInfo, {}, InputFileType::Header, "/source/file.cpp", ""}; ASSERT_THAT(builder.commandLine, ElementsAre("clang++", @@ -477,7 +537,11 @@ TYPED_TEST(CommandLineBuilder, EmptyOutputFile) TYPED_TEST(CommandLineBuilder, OutputFile) { - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp", "/output/file.o"}; + Builder builder{this->emptyProjectInfo, + {}, + InputFileType::Header, + "/source/file.cpp", + "/output/file.o"}; ASSERT_THAT(builder.commandLine, ElementsAre("clang++", @@ -493,7 +557,12 @@ TYPED_TEST(CommandLineBuilder, OutputFile) TYPED_TEST(CommandLineBuilder, IncludePchPath) { - Builder builder{this->emptyProjectInfo, {}, "/source/file.cpp", "/output/file.o", "/pch/file.pch"}; + Builder builder{this->emptyProjectInfo, + {}, + InputFileType::Header, + "/source/file.cpp", + "/output/file.o", + "/pch/file.pch"}; ASSERT_THAT(builder.commandLine, ElementsAre("clang++", @@ -527,4 +596,5 @@ TYPED_TEST(CommandLineBuilder, CompilerMacros) "-DER=2", "-DYI=1")); } + } // namespace diff --git a/tests/unit/unittest/pchcreator-test.cpp b/tests/unit/unittest/pchcreator-test.cpp index 8a1e1ffa8ef..d44e72ee6f5 100644 --- a/tests/unit/unittest/pchcreator-test.cpp +++ b/tests/unit/unittest/pchcreator-test.cpp @@ -133,9 +133,7 @@ TEST_F(PchCreator, CreateProjectPartPchFileContent) TEST_F(PchCreator, CreateProjectPartClangCompilerArguments) { - auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1), - "project.h", - "project.pch"); + auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1), "project.pch"); ASSERT_THAT(arguments, ElementsAre("clang++", @@ -151,17 +149,14 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArguments) "-isystem", toNativePath(TESTDATA_DIR "/builddependencycollector/system").path(), "-o", - "project.pch", - "project.h")); + "project.pch")); } TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch) { pchTask1.systemPchPath = "system.pch"; - auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1), - "project.h", - "project.pch"); + auto arguments = creator.generateClangCompilerArguments(std::move(pchTask1), "project.pch"); ASSERT_THAT(arguments, ElementsAre("clang++", @@ -181,8 +176,7 @@ TEST_F(PchCreator, CreateProjectPartClangCompilerArgumentsWithSystemPch) "-Xclang", "system.pch", "-o", - "project.pch", - "project.h")); + "project.pch")); } TEST_F(PchCreatorVerySlowTest, ProjectPartPchsSendToPchManagerClient) diff --git a/tests/unit/unittest/refactoringclientserverinprocess-test.cpp b/tests/unit/unittest/refactoringclientserverinprocess-test.cpp index 659dcf735fa..c6e4d59c3a1 100644 --- a/tests/unit/unittest/refactoringclientserverinprocess-test.cpp +++ b/tests/unit/unittest/refactoringclientserverinprocess-test.cpp @@ -103,12 +103,8 @@ TEST_F(RefactoringClientServerInProcess, SendSourceLocationsForRenamingMessage) TEST_F(RefactoringClientServerInProcess, SendRequestSourceLocationsForRenamingMessage) { - RequestSourceLocationsForRenamingMessage message{{TESTDATA_DIR, "renamevariable.cpp"}, - 1, - 5, - "int v;\n\nint x = v + 3;\n", - {"cc", "renamevariable.cpp"}, - 1}; + RequestSourceLocationsForRenamingMessage message{ + {TESTDATA_DIR, "renamevariable.cpp"}, 1, 5, "int v;\n\nint x = v + 3;\n", {"cc"}, 1}; EXPECT_CALL(mockRefactoringServer, requestSourceLocationsForRenamingMessage(message)); @@ -153,15 +149,10 @@ TEST_F(RefactoringClientServerInProcess, SendProgressMessage) TEST_F(RefactoringClientServerInProcess, RequestSourceRangesAndDiagnosticsForQueryMessage) { - RequestSourceRangesForQueryMessage message{"functionDecl()", - {{{TESTDATA_DIR, "query_simplefunction.cpp"}, - "void f();", - {"cc", "query_simplefunction.cpp"}, - 1}}, - {{{TESTDATA_DIR, "query_simplefunction.h"}, - "void f();", - {}, - 1}}}; + RequestSourceRangesForQueryMessage message{ + "functionDecl()", + {{{TESTDATA_DIR, "query_simplefunction.cpp"}, "void f();", {"cc"}, 1}}, + {{{TESTDATA_DIR, "query_simplefunction.h"}, "void f();", {}, 1}}}; EXPECT_CALL(mockRefactoringServer, requestSourceRangesForQueryMessage(message)); @@ -171,15 +162,15 @@ TEST_F(RefactoringClientServerInProcess, RequestSourceRangesAndDiagnosticsForQue TEST_F(RefactoringClientServerInProcess, RequestSourceRangesForQueryMessage) { - RequestSourceRangesForQueryMessage message{"functionDecl()", - {{{TESTDATA_DIR, "query_simplefunction.cpp"}, - "void f();", - {"cc", "query_simplefunction.cpp"}, - 1}}, - {{{TESTDATA_DIR, "query_simplefunction.h"}, - "void f();", - {}, - 1}}}; + RequestSourceRangesForQueryMessage message{ + "functionDecl()", + {{{TESTDATA_DIR, "query_simplefunction.cpp"}, + "void f();", + { + "cc", + }, + 1}}, + {{{TESTDATA_DIR, "query_simplefunction.h"}, "void f();", {}, 1}}}; EXPECT_CALL(mockRefactoringServer, requestSourceRangesForQueryMessage(message)); diff --git a/tests/unit/unittest/refactoringserver-test.cpp b/tests/unit/unittest/refactoringserver-test.cpp index 56f5e6950dd..7ac60c45d1c 100644 --- a/tests/unit/unittest/refactoringserver-test.cpp +++ b/tests/unit/unittest/refactoringserver-test.cpp @@ -100,9 +100,7 @@ protected: ClangBackEnd::GeneratedFiles generatedFiles; ClangBackEnd::RefactoringServer refactoringServer{mockSymbolIndexing, filePathCache, generatedFiles}; Utils::SmallString sourceContent{"void f()\n {}"}; - FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, - sourceContent.clone(), - {"cc", toNativePath(TESTDATA_DIR "/query_simplefunction.cpp").path()}}; + FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, sourceContent.clone(), {"cc"}}; QTemporaryFile temporaryFile{Utils::TemporaryDirectory::masterDirectoryPath() + "/clangQuery-XXXXXX.cpp"}; int processingSlotCount = 2; @@ -113,12 +111,8 @@ using RefactoringServerVerySlowTest = RefactoringServer; TEST_F(RefactoringServerSlowTest, RequestSourceLocationsForRenamingMessage) { - RequestSourceLocationsForRenamingMessage message{{TESTDATA_DIR, "renamevariable.cpp"}, - 1, - 5, - "int v;\n\nint x = v + 3;\n", - {"cc", "renamevariable.cpp"}, - 1}; + RequestSourceLocationsForRenamingMessage message{ + {TESTDATA_DIR, "renamevariable.cpp"}, 1, 5, "int v;\n\nint x = v + 3;\n", {"cc"}, 1}; EXPECT_CALL(mockRefactoringClient, sourceLocationsForRenamingMessage( @@ -152,13 +146,9 @@ TEST_F(RefactoringServerSlowTest, RequestSingleSourceRangesAndDiagnosticsWithUns Utils::SmallString unsavedContent{"void f();"}; FileContainer source{{TESTDATA_DIR, "query_simplefunction.cpp"}, "#include \"query_simplefunction.h\"", - {"cc", "query_simplefunction.cpp"}}; - FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"}, - unsavedContent.clone(), - {}}; - RequestSourceRangesForQueryMessage message{"functionDecl()", - {source.clone()}, - {unsaved.clone()}}; + {"cc"}}; + FileContainer unsaved{{TESTDATA_DIR, "query_simplefunction.h"}, unsavedContent.clone(), {}}; + RequestSourceRangesForQueryMessage message{"functionDecl()", {source.clone()}, {unsaved.clone()}}; EXPECT_CALL(mockRefactoringClient, sourceRangesForQueryMessage( @@ -267,11 +257,10 @@ TEST_F(RefactoringServer, PollTimerNotIsActiveAfterCanceling) TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSourceRange) { - RequestSourceRangesAndDiagnosticsForQueryMessage message( - "functionDecl()", - {FilePath(temporaryFile.fileName()), - "void f() {}", - {"cc", toNativePath(temporaryFile.fileName()).path()}}); + RequestSourceRangesAndDiagnosticsForQueryMessage message("functionDecl()", + {FilePath(temporaryFile.fileName()), + "void f() {}", + {"cc"}}); EXPECT_CALL(mockRefactoringClient, sourceRangesAndDiagnosticsForQueryMessage( @@ -287,11 +276,10 @@ TEST_F(RefactoringServerSlowTest, ForValidRequestSourceRangesAndDiagnosticsGetSo TEST_F(RefactoringServerSlowTest, ForInvalidRequestSourceRangesAndDiagnosticsGetDiagnostics) { - RequestSourceRangesAndDiagnosticsForQueryMessage message( - "func()", - {FilePath(temporaryFile.fileName()), - "void f() {}", - {"cc", toNativePath(temporaryFile.fileName()).path()}}); + RequestSourceRangesAndDiagnosticsForQueryMessage message("func()", + {FilePath(temporaryFile.fileName()), + "void f() {}", + {"cc"}}); EXPECT_CALL(mockRefactoringClient, sourceRangesAndDiagnosticsForQueryMessage( diff --git a/tests/unit/unittest/sourcerangeextractor-test.cpp b/tests/unit/unittest/sourcerangeextractor-test.cpp index 171db9b956d..552cde08acd 100644 --- a/tests/unit/unittest/sourcerangeextractor-test.cpp +++ b/tests/unit/unittest/sourcerangeextractor-test.cpp @@ -57,9 +57,7 @@ protected: void TearDown() override; protected: - TestClangTool clangTool{{TESTDATA_DIR "/sourcerangeextractor_location.cpp"}, - "", - {"cc", "sourcerangeextractor_location.cpp"}}; + TestClangTool clangTool{{TESTDATA_DIR "/sourcerangeextractor_location.cpp"}, "", {"cc"}}; ClangBackEnd::SourceRangesContainer sourceRangesContainer; const clang::SourceManager &sourceManager{clangTool.sourceManager()}; Sqlite::Database database{":memory:", Sqlite::JournalMode::Memory}; diff --git a/tests/unit/unittest/symbolfinder-test.cpp b/tests/unit/unittest/symbolfinder-test.cpp index 1dad3184d68..8f29fe02da7 100644 --- a/tests/unit/unittest/symbolfinder-test.cpp +++ b/tests/unit/unittest/symbolfinder-test.cpp @@ -75,9 +75,7 @@ TEST_F(SymbolFinder, FileContentFilePath) TEST_F(SymbolFinderSlowTest, FindName) { Finder finder(1, 5, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "int variable;", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path()}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "int variable;", {"cc"}); finder.findSymbol(); @@ -87,9 +85,7 @@ TEST_F(SymbolFinderSlowTest, FindName) TEST_F(SymbolFinderSlowTest, FindNameInUnsavedFile) { Finder finder(1, 5, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "int newVariable;", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path()}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "int newVariable;", {"cc"}); finder.findSymbol(); @@ -99,9 +95,7 @@ TEST_F(SymbolFinderSlowTest, FindNameInUnsavedFile) TEST_F(SymbolFinderSlowTest, FindUsrs) { Finder finder(1, 5, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "int variable;", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "int variable;", {"cc", "-std=c++14"}); finder.findSymbol(); @@ -111,9 +105,7 @@ TEST_F(SymbolFinderSlowTest, FindUsrs) TEST_F(SymbolFinderSlowTest, VariableDeclarationSourceLocations) { Finder finder(1, 5, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "", {"cc", "-std=c++14"}); finder.findSymbol(); @@ -125,9 +117,7 @@ TEST_F(SymbolFinderSlowTest, VariableDeclarationSourceLocations) TEST_F(SymbolFinderSlowTest, VariableUsageSourceLocations) { Finder finder(3, 9, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "", {"cc", "-std=c++14"}); finder.findSymbol(); @@ -139,9 +129,7 @@ TEST_F(SymbolFinderSlowTest, VariableUsageSourceLocations) TEST_F(SymbolFinderSlowTest, TemplateMemberVariableDeclarationSourceLocations) { Finder finder(8, 18, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "", {"cc", "-std=c++14"}); finder.findSymbol(); @@ -154,9 +142,7 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableDeclarationSourceLocations) TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageSourceLocations) { Finder finder(15, 14, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "", {"cc", "-std=c++14"}); finder.findSymbol(); @@ -169,9 +155,7 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageSourceLocations) TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageInLambdaSourceLocations) { Finder finder(18, 19, filePathCaching); - finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/renamevariable.cpp").path(), "-std=c++14"}); + finder.addFile({TESTDATA_DIR "/renamevariable.cpp"}, "", {"cc", "-std=c++14"}); finder.findSymbol(); @@ -184,9 +168,7 @@ TEST_F(SymbolFinderSlowTest, TemplateMemberVariableUsageInLambdaSourceLocations) TEST_F(SymbolFinderSlowTest, CursorOverMacroDefintionSymbolName) { Finder finder(1, 9, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); @@ -196,9 +178,7 @@ TEST_F(SymbolFinderSlowTest, CursorOverMacroDefintionSymbolName) TEST_F(SymbolFinderSlowTest, CursorOverMacroExpansionSymbolName) { Finder finder(10, 10, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); @@ -208,9 +188,7 @@ TEST_F(SymbolFinderSlowTest, CursorOverMacroExpansionSymbolName) TEST_F(SymbolFinderSlowTest, FindMacroDefinition) { Finder finder(1, 9, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); @@ -221,9 +199,7 @@ TEST_F(SymbolFinderSlowTest, FindMacroDefinition) TEST_F(SymbolFinderSlowTest, FindMacroExpansion) { Finder finder(1, 9, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); @@ -234,9 +210,7 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansion) TEST_F(SymbolFinderSlowTest, DoNotFindUndedefinedMacroExpansion) { Finder finder(1, 9, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); @@ -247,9 +221,7 @@ TEST_F(SymbolFinderSlowTest, DoNotFindUndedefinedMacroExpansion) TEST_F(SymbolFinderSlowTest, FindMacroDefinitionFromMacroExpansion) { Finder finder(10, 10, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); @@ -261,9 +233,7 @@ TEST_F(SymbolFinderSlowTest, FindMacroDefinitionFromMacroExpansion) TEST_F(SymbolFinderSlowTest, FindMacroExpansionBeforeMacroExpansionWithCursor) { Finder finder(12, 10, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); @@ -274,9 +244,7 @@ TEST_F(SymbolFinderSlowTest, FindMacroExpansionBeforeMacroExpansionWithCursor) TEST_F(SymbolFinderSlowTest, FindMacroExpansionAfterMacroExpansionWithCursor) { Finder finder(10, 10, filePathCaching); - finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, - "", - {"cc", toNativePath(TESTDATA_DIR "/symbolfinder_macro.cpp").path()}); + finder.addFile({TESTDATA_DIR "/symbolfinder_macro.cpp"}, "", {"cc"}); finder.findSymbol(); diff --git a/tests/unit/unittest/symbolindexer-test.cpp b/tests/unit/unittest/symbolindexer-test.cpp index ce0fadfdf8c..0db32d658c7 100644 --- a/tests/unit/unittest/symbolindexer-test.cpp +++ b/tests/unit/unittest/symbolindexer-test.cpp @@ -267,7 +267,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesInCollector) ElementsAre("clang++", "-Wno-pragma-once-outside-header", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++", @@ -297,7 +297,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithPrecompiledHeaderInColl ElementsAre("clang++", "-Wno-pragma-once-outside-header", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++", @@ -330,7 +330,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsAddFilesWithoutPrecompiledHeaderInC ElementsAre("clang++", "-Wno-pragma-once-outside-header", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++", @@ -510,7 +510,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithoutProjectPartArtifact) ElementsAre("clang++", "-Wno-pragma-once-outside-header", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++", @@ -562,7 +562,7 @@ TEST_F(SymbolIndexer, UpdateProjectPartsCallsInOrderWithProjectPartArtifact) ElementsAre("clang++", "-Wno-pragma-once-outside-header", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++", @@ -618,7 +618,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathCallsInOrder) ElementsAre("clang++", "-DFOO", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++", @@ -680,7 +680,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsUsingPrecompiledHeader) ElementsAre("clang++", "-DFOO", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++", @@ -715,7 +715,7 @@ TEST_F(SymbolIndexer, UpdateChangedPathIsNotUsingPrecompiledHeaderIfItNotExists) ElementsAre("clang++", "-DFOO", "-x", - "c++-header", + "c++", "-std=c++14", "-nostdinc", "-nostdinc++",