diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index b819fd75598..0aabf245775 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -241,6 +241,19 @@ private slots: void test_projectInfoGenerator_useMacroInspectionReportForLanguageVersion(); void test_projectInfoGenerator_useCompilerFlagsForLanguageExtensions(); void test_projectInfoGenerator_projectFileKindsMatchProjectPartVersion(); + void test_headerPathFilter_builtin(); + void test_headerPathFilter_system(); + void test_headerPathFilter_user(); + void test_headerPathFilter_noProjectPathSet(); + void test_headerPathFilter_dontAddInvalidPath(); + void test_headerPathFilter_clangHeadersPath(); + void test_headerPathFilter_clangHeadersPathWitoutClangVersion(); + void test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderMacOs(); + void test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderLinux(); + void test_headerPathFilter_removeGccInternalPaths(); + void test_headerPathFilter_removeGccInternalPathsExceptForStandardPaths(); + void test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderNoVersion(); + void test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderAndroidClang(); #endif private: diff --git a/src/plugins/cpptools/cpptoolsunittestfiles.pri b/src/plugins/cpptools/cpptoolsunittestfiles.pri index 913a47e45ee..51f678120ea 100644 --- a/src/plugins/cpptools/cpptoolsunittestfiles.pri +++ b/src/plugins/cpptools/cpptoolsunittestfiles.pri @@ -9,13 +9,11 @@ HEADERS += \ $$PWD/senddocumenttracker.h \ $$PWD/projectpart.h \ $$PWD/cppprojectfilecategorizer.h \ - $$PWD/projectinfo.h \ - $$PWD/headerpathfilter.h + $$PWD/projectinfo.h SOURCES += \ $$PWD/cppprojectfile.cpp \ $$PWD/senddocumenttracker.cpp \ $$PWD/projectpart.cpp \ $$PWD/cppprojectfilecategorizer.cpp \ - $$PWD/projectinfo.cpp \ - $$PWD/headerpathfilter.cpp + $$PWD/projectinfo.cpp diff --git a/src/plugins/cpptools/projectinfo_test.cpp b/src/plugins/cpptools/projectinfo_test.cpp index 04b2940e333..ea3fc34514f 100644 --- a/src/plugins/cpptools/projectinfo_test.cpp +++ b/src/plugins/cpptools/projectinfo_test.cpp @@ -26,6 +26,7 @@ #include "cppprojectinfogenerator.h" #include "cppprojectpartchooser.h" #include "cpptoolsplugin.h" +#include "headerpathfilter.h" #include "projectinfo.h" #include @@ -33,6 +34,8 @@ #include +using namespace ProjectExplorer; + namespace CppTools { namespace Internal { @@ -467,5 +470,250 @@ void CppToolsPlugin::test_projectInfoGenerator_projectFileKindsMatchProjectPartV })); } +namespace { +class HeaderPathFilterTest +{ +public: + HeaderPathFilterTest() : project({}, Utils::FilePath::fromString("test")) + { + const auto headerPaths = {HeaderPath{"", HeaderPathType::BuiltIn}, + HeaderPath{"/builtin_path", HeaderPathType::BuiltIn}, + HeaderPath{"/system_path", HeaderPathType::System}, + HeaderPath{"/framework_path", HeaderPathType::Framework}, + HeaderPath{"/outside_project_user_path", HeaderPathType::User}, + HeaderPath{"/build/user_path", HeaderPathType::User}, + HeaderPath{"/buildb/user_path", HeaderPathType::User}, + HeaderPath{"/projectb/user_path", HeaderPathType::User}, + HeaderPath{"/project/user_path", HeaderPathType::User}}; + projectPart.headerPaths = headerPaths; + projectPart.project = &project; + } + + static HeaderPath builtIn(const QString &path) + { + return HeaderPath{path, HeaderPathType::BuiltIn}; + } + static HeaderPath system(const QString &path) + { + return HeaderPath{path, HeaderPathType::System}; + } + static HeaderPath framework(const QString &path) + { + return HeaderPath{path, HeaderPathType::Framework}; + } + static HeaderPath user(const QString &path) + { + return HeaderPath{path, HeaderPathType::User}; + } + + ProjectExplorer::Project project; + CppTools::ProjectPart projectPart; + CppTools::HeaderPathFilter filter{ + projectPart, CppTools::UseTweakedHeaderPaths::No, {}, {}, "/project", "/build"}; +}; +} + +void CppToolsPlugin::test_headerPathFilter_builtin() +{ + HeaderPathFilterTest t; + t.filter.process(); + + QCOMPARE(t.filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_system() +{ + HeaderPathFilterTest t; + t.filter.process(); + + QCOMPARE(t.filter.systemHeaderPaths, (HeaderPaths{ + t.system("/project/.pre_includes"), t.system("/system_path"), + t.framework("/framework_path"), t.user("/outside_project_user_path"), + t.user("/buildb/user_path"), t.user("/projectb/user_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_user() +{ + HeaderPathFilterTest t; + t.filter.process(); + + QCOMPARE(t.filter.userHeaderPaths, (HeaderPaths{t.user("/build/user_path"), + t.user("/project/user_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_noProjectPathSet() +{ + HeaderPathFilterTest t; + HeaderPathFilter filter{t.projectPart, UseTweakedHeaderPaths::No}; + filter.process(); + + QCOMPARE(filter.userHeaderPaths, (HeaderPaths{ + t.user("/outside_project_user_path"), t.user("/build/user_path"), + t.user("/buildb/user_path"), t.user("/projectb/user_path"), + t.user("/project/user_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_dontAddInvalidPath() +{ + HeaderPathFilterTest t; + t.filter.process(); + QCOMPARE(t.filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")})); + QCOMPARE(t.filter.systemHeaderPaths, HeaderPaths({ + t.system("/project/.pre_includes"), t.system("/system_path"), + t.framework("/framework_path"), t.user("/outside_project_user_path"), + t.user("/buildb/user_path"), t.user("/projectb/user_path")})); + QCOMPARE(t.filter.userHeaderPaths, HeaderPaths({t.user("/build/user_path"), + t.user("/project/user_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_clangHeadersPath() +{ + HeaderPathFilterTest t; + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir"); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("clang_dir"), + t.builtIn("/builtin_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_clangHeadersPathWitoutClangVersion() +{ + HeaderPathFilterTest t; + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("/builtin_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderMacOs() +{ + HeaderPathFilterTest t; + const auto builtIns = { + t.builtIn("/usr/include/c++/4.2.1"), t.builtIn("/usr/include/c++/4.2.1/backward"), + t.builtIn("/usr/local/include"), + t.builtIn("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/6.0/include"), + t.builtIn("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"), + t.builtIn("/usr/include") + }; + t.projectPart.toolChainTargetTriple = "x86_64-apple-darwin10"; + std::copy(builtIns.begin(), builtIns.end(), + std::inserter(t.projectPart.headerPaths, t.projectPart.headerPaths.begin())); + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir"); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{ + t.builtIn("/usr/include/c++/4.2.1"), t.builtIn("/usr/include/c++/4.2.1/backward"), + t.builtIn("/usr/local/include"), t.builtIn("clang_dir"), + t.builtIn("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"), + t.builtIn("/usr/include"), + t.builtIn("/builtin_path")})); +} + +void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderLinux() +{ + HeaderPathFilterTest t; + const auto builtIns = { + t.builtIn("/usr/include/c++/4.8"), t.builtIn("/usr/include/c++/4.8/backward"), + t.builtIn("/usr/include/x86_64-linux-gnu/c++/4.8"), + t.builtIn("/usr/local/include"), t.builtIn("/usr/lib/gcc/x86_64-linux-gnu/4.8/include"), + t.builtIn("/usr/include/x86_64-linux-gnu"), t.builtIn("/usr/include")}; + std::copy(builtIns.begin(), builtIns.end(), + std::inserter(t.projectPart.headerPaths, t.projectPart.headerPaths.begin())); + t.projectPart.toolChainTargetTriple = "x86_64-linux-gnu"; + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir"); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{ + t.builtIn("/usr/include/c++/4.8"), t.builtIn("/usr/include/c++/4.8/backward"), + t.builtIn("/usr/include/x86_64-linux-gnu/c++/4.8"), t.builtIn("/usr/local/include"), + t.builtIn("clang_dir"), t.builtIn("/usr/lib/gcc/x86_64-linux-gnu/4.8/include"), + t.builtIn("/usr/include/x86_64-linux-gnu"), t.builtIn("/usr/include"), + t.builtIn("/builtin_path")})); +} + +// GCC-internal include paths like /include and might confuse +// clang and should be filtered out. clang on the command line filters them out, too. +void CppToolsPlugin::test_headerPathFilter_removeGccInternalPaths() +{ + HeaderPathFilterTest t; + t.projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8("/usr/lib/gcc/x86_64-linux-gnu/7"); + t.projectPart.toolchainType = ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID; + t.projectPart.headerPaths = { + t.builtIn("/usr/lib/gcc/x86_64-linux-gnu/7/include"), + t.builtIn("/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed"), + }; + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir"); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{t.builtIn("clang_dir")})); +} + +// Some distributions ship the standard library headers in "/include/c++" (MinGW) +// or e.g. "/include/g++-v8" (Gentoo). +// Ensure that we do not remove include paths pointing there. +void CppToolsPlugin::test_headerPathFilter_removeGccInternalPathsExceptForStandardPaths() +{ + HeaderPathFilterTest t; + t.projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8( + "c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0"); + t.projectPart.toolchainType = ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID; + t.projectPart.headerPaths = { + t.builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++"), + t.builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32"), + t.builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward"), + }; + + HeaderPaths expected = t.projectPart.headerPaths; + expected.append(t.builtIn("clang_dir")); + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir"); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, expected); +} + +void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderNoVersion() +{ + HeaderPathFilterTest t; + t.projectPart.headerPaths = { + t.builtIn("C:/mingw/i686-w64-mingw32/include"), + t.builtIn("C:/mingw/i686-w64-mingw32/include/c++"), + t.builtIn("C:/mingw/i686-w64-mingw32/include/c++/i686-w64-mingw32"), + t.builtIn("C:/mingw/i686-w64-mingw32/include/c++/backward"), + }; + t.projectPart.toolChainTargetTriple = "x86_64-w64-windows-gnu"; + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir"); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{ + t.builtIn("C:/mingw/i686-w64-mingw32/include/c++"), + t.builtIn("C:/mingw/i686-w64-mingw32/include/c++/i686-w64-mingw32"), + t.builtIn("C:/mingw/i686-w64-mingw32/include/c++/backward"), + t.builtIn("clang_dir"), + t.builtIn("C:/mingw/i686-w64-mingw32/include")})); +} + +void CppToolsPlugin::test_headerPathFilter_clangHeadersAndCppIncludesPathsOrderAndroidClang() +{ + HeaderPathFilterTest t; + t.projectPart.headerPaths = { + t.builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include/i686-linux-android"), + t.builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include"), + t.builtIn("C:/Android/sdk/ndk-bundle/sources/android/support/include"), + t.builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include"), + t.builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include") + }; + t.projectPart.toolChainTargetTriple = "i686-linux-android"; + HeaderPathFilter filter(t.projectPart, UseTweakedHeaderPaths::Yes, "6.0", "clang_dir"); + filter.process(); + + QCOMPARE(filter.builtInHeaderPaths, (HeaderPaths{ + t.builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include"), + t.builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include"), + t.builtIn("clang_dir"), + t.builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include/i686-linux-android"), + t.builtIn("C:/Android/sdk/ndk-bundle/sources/android/support/include"), + t.builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include")})); +} + } // namespace Internal } // namespace CppTools diff --git a/tests/unit/unittest/CMakeLists.txt b/tests/unit/unittest/CMakeLists.txt index fda3b766031..b8164ea8e19 100644 --- a/tests/unit/unittest/CMakeLists.txt +++ b/tests/unit/unittest/CMakeLists.txt @@ -55,7 +55,6 @@ add_qtc_test(unittest GTEST gtest-llvm-printing.h gtest-qt-printing.cpp gtest-qt-printing.h gtest-std-printing.h - headerpathfilter-test.cpp highlightingresultreporter-test.cpp lastchangedrowid-test.cpp lineprefixer-test.cpp @@ -456,7 +455,6 @@ extend_qtc_test(unittest cppprojectfilecategorizer.cpp cppprojectfilecategorizer.h projectinfo.cpp projectinfo.h cppprojectpartchooser.cpp cppprojectpartchooser.h - headerpathfilter.cpp headerpathfilter.h ) extend_qtc_test(unittest diff --git a/tests/unit/unittest/headerpathfilter-test.cpp b/tests/unit/unittest/headerpathfilter-test.cpp deleted file mode 100644 index 36ac8ad8800..00000000000 --- a/tests/unit/unittest/headerpathfilter-test.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -****************************************************************************/ - -#include "googletest.h" - -#include -#include -#include - -namespace { - -using ProjectExplorer::HeaderPath; -using ProjectExplorer::HeaderPathType; - -MATCHER_P(HasBuiltIn, - path, - std::string(negation ? "isn't " : "is ") - + PrintToString(HeaderPath{QString::fromUtf8(path), HeaderPathType::BuiltIn})) -{ - return arg.path == QString::fromUtf8(path) && arg.type == HeaderPathType::BuiltIn; -} - -MATCHER_P(HasSystem, - path, - std::string(negation ? "isn't " : "is ") - + PrintToString(HeaderPath{QString::fromUtf8(path), HeaderPathType::System})) -{ - return arg.path == QString::fromUtf8(path) && arg.type == HeaderPathType::System; -} - -MATCHER_P(HasFramework, - path, - std::string(negation ? "isn't " : "is ") - + PrintToString(HeaderPath{QString::fromUtf8(path), HeaderPathType::Framework})) -{ - return arg.path == QString::fromUtf8(path) && arg.type == HeaderPathType::Framework; -} - -MATCHER_P(HasUser, - path, - std::string(negation ? "isn't " : "is ") - + PrintToString(HeaderPath{QString::fromUtf8(path), HeaderPathType::User})) -{ - return arg.path == QString::fromUtf8(path) && arg.type == HeaderPathType::User; -} - -class HeaderPathFilter : public testing::Test -{ -protected: - HeaderPathFilter() - { - auto headerPaths = {HeaderPath{"", HeaderPathType::BuiltIn}, - HeaderPath{"/builtin_path", HeaderPathType::BuiltIn}, - HeaderPath{"/system_path", HeaderPathType::System}, - HeaderPath{"/framework_path", HeaderPathType::Framework}, - HeaderPath{"/outside_project_user_path", HeaderPathType::User}, - HeaderPath{"/build/user_path", HeaderPathType::User}, - HeaderPath{"/buildb/user_path", HeaderPathType::User}, - HeaderPath{"/projectb/user_path", HeaderPathType::User}, - HeaderPath{"/project/user_path", HeaderPathType::User}}; - - projectPart.headerPaths = headerPaths; - projectPart.project = &project; - } - - static HeaderPath builtIn(const QString &path) - { - return HeaderPath{path, HeaderPathType::BuiltIn}; - } - -protected: - ProjectExplorer::Project project; - CppTools::ProjectPart projectPart; - CppTools::HeaderPathFilter filter{ - projectPart, CppTools::UseTweakedHeaderPaths::No, {}, {}, "/project", "/build"}; -}; - -TEST_F(HeaderPathFilter, BuiltIn) -{ - filter.process(); - - ASSERT_THAT(filter.builtInHeaderPaths, ElementsAre(HasBuiltIn("/builtin_path"))); -} - -TEST_F(HeaderPathFilter, System) -{ - filter.process(); - - ASSERT_THAT(filter.systemHeaderPaths, - ElementsAre(HasSystem("/project/.pre_includes"), - HasSystem("/system_path"), - HasFramework("/framework_path"), - HasUser("/outside_project_user_path"), - HasUser("/buildb/user_path"), - HasUser("/projectb/user_path"))); -} - -TEST_F(HeaderPathFilter, User) -{ - filter.process(); - - ASSERT_THAT(filter.userHeaderPaths, - ElementsAre(HasUser("/build/user_path"), HasUser("/project/user_path"))); -} - -TEST_F(HeaderPathFilter, NoProjectPathSet) -{ - CppTools::HeaderPathFilter filter{projectPart, CppTools::UseTweakedHeaderPaths::No}; - - filter.process(); - - ASSERT_THAT(filter.userHeaderPaths, - ElementsAre(HasUser("/outside_project_user_path"), - HasUser("/build/user_path"), - HasUser("/buildb/user_path"), - HasUser("/projectb/user_path"), - HasUser("/project/user_path"))); -} - -TEST_F(HeaderPathFilter, DontAddInvalidPath) -{ - filter.process(); - - ASSERT_THAT(filter, - AllOf(Field(&CppTools::HeaderPathFilter::builtInHeaderPaths, - ElementsAre(HasBuiltIn("/builtin_path"))), - Field(&CppTools::HeaderPathFilter::systemHeaderPaths, - ElementsAre(HasSystem("/project/.pre_includes"), - HasSystem("/system_path"), - HasFramework("/framework_path"), - HasUser("/outside_project_user_path"), - HasUser("/buildb/user_path"), - HasUser("/projectb/user_path"))), - Field(&CppTools::HeaderPathFilter::userHeaderPaths, - ElementsAre(HasUser("/build/user_path"), HasUser("/project/user_path"))))); -} - -TEST_F(HeaderPathFilter, ClangHeadersPath) -{ - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - "6.0", - CLANG_INCLUDE_DIR}; - - filter.process(); - - ASSERT_THAT(filter.builtInHeaderPaths, - ElementsAre(HasBuiltIn(CLANG_INCLUDE_DIR), HasBuiltIn("/builtin_path"))); -} - -TEST_F(HeaderPathFilter, ClangHeadersPathWitoutClangVersion) -{ - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes}; - - filter.process(); - - ASSERT_THAT(filter.builtInHeaderPaths, - ElementsAre(HasBuiltIn("/builtin_path"))); -} - -TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderMacOs) -{ - auto builtIns = { - builtIn("/usr/include/c++/4.2.1"), - builtIn("/usr/include/c++/4.2.1/backward"), - builtIn("/usr/local/include"), - builtIn("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/6.0/include"), - builtIn("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"), - builtIn("/usr/include") - }; - projectPart.toolChainTargetTriple = "x86_64-apple-darwin10"; - std::copy(builtIns.begin(), - builtIns.end(), - std::inserter(projectPart.headerPaths, projectPart.headerPaths.begin())); - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - "6.0", - CLANG_INCLUDE_DIR}; - - filter.process(); - - ASSERT_THAT(filter.builtInHeaderPaths, - ElementsAre(HasBuiltIn("/usr/include/c++/4.2.1"), - HasBuiltIn("/usr/include/c++/4.2.1/backward"), - HasBuiltIn("/usr/local/include"), - HasBuiltIn(CLANG_INCLUDE_DIR), - HasBuiltIn("/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"), - HasBuiltIn("/usr/include"), - HasBuiltIn("/builtin_path"))); -} - -TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderLinux) -{ - auto builtIns = { - builtIn("/usr/include/c++/4.8"), - builtIn("/usr/include/c++/4.8/backward"), - builtIn("/usr/include/x86_64-linux-gnu/c++/4.8"), - builtIn("/usr/local/include"), - builtIn("/usr/lib/gcc/x86_64-linux-gnu/4.8/include"), - builtIn("/usr/include/x86_64-linux-gnu"), - builtIn("/usr/include")}; - std::copy(builtIns.begin(), - builtIns.end(), - std::inserter(projectPart.headerPaths, projectPart.headerPaths.begin())); - projectPart.toolChainTargetTriple = "x86_64-linux-gnu"; - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - "6.0", - CLANG_INCLUDE_DIR}; - - filter.process(); - - ASSERT_THAT(filter.builtInHeaderPaths, - ElementsAre(HasBuiltIn("/usr/include/c++/4.8"), - HasBuiltIn("/usr/include/c++/4.8/backward"), - HasBuiltIn("/usr/include/x86_64-linux-gnu/c++/4.8"), - HasBuiltIn("/usr/local/include"), - HasBuiltIn(CLANG_INCLUDE_DIR), - HasBuiltIn("/usr/lib/gcc/x86_64-linux-gnu/4.8/include"), - HasBuiltIn("/usr/include/x86_64-linux-gnu"), - HasBuiltIn("/usr/include"), - HasBuiltIn("/builtin_path"))); -} - -// GCC-internal include paths like /include and might confuse -// clang and should be filtered out. clang on the command line filters them out, too. -TEST_F(HeaderPathFilter, RemoveGccInternalPaths) -{ - projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8("/usr/lib/gcc/x86_64-linux-gnu/7"); - projectPart.toolchainType = ProjectExplorer::Constants::GCC_TOOLCHAIN_TYPEID; - projectPart.headerPaths = { - builtIn("/usr/lib/gcc/x86_64-linux-gnu/7/include"), - builtIn("/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed"), - }; - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - "6.0", - CLANG_INCLUDE_DIR}; - - filter.process(); - - ASSERT_THAT(filter.builtInHeaderPaths, ElementsAre(HasBuiltIn(CLANG_INCLUDE_DIR))); -} - -// Some distributions ship the standard library headers in "/include/c++" (MinGW) -// or e.g. "/include/g++-v8" (Gentoo). -// Ensure that we do not remove include paths pointing there. -TEST_F(HeaderPathFilter, RemoveGccInternalPathsExceptForStandardPaths) -{ - projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8( - "c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0"); - projectPart.toolchainType = ProjectExplorer::Constants::MINGW_TOOLCHAIN_TYPEID; - projectPart.headerPaths = { - builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++"), - builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32"), - builtIn("c:/mingw/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward"), - }; - - auto expected = projectPart.headerPaths; - expected << builtIn(CLANG_INCLUDE_DIR); - - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - "6.0", - CLANG_INCLUDE_DIR}; - - filter.process(); - - ASSERT_THAT(filter.builtInHeaderPaths, ContainerEq(expected)); -} - -TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderNoVersion) -{ - projectPart.headerPaths = { - builtIn("C:/mingw/i686-w64-mingw32/include"), - builtIn("C:/mingw/i686-w64-mingw32/include/c++"), - builtIn("C:/mingw/i686-w64-mingw32/include/c++/i686-w64-mingw32"), - builtIn("C:/mingw/i686-w64-mingw32/include/c++/backward"), - }; - projectPart.toolChainTargetTriple = "x86_64-w64-windows-gnu"; - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - "6.0", - CLANG_INCLUDE_DIR}; - - filter.process(); - - ASSERT_THAT( - filter.builtInHeaderPaths, - ElementsAre(HasBuiltIn("C:/mingw/i686-w64-mingw32/include/c++"), - HasBuiltIn("C:/mingw/i686-w64-mingw32/include/c++/i686-w64-mingw32"), - HasBuiltIn("C:/mingw/i686-w64-mingw32/include/c++/backward"), - HasBuiltIn(CLANG_INCLUDE_DIR), - HasBuiltIn("C:/mingw/i686-w64-mingw32/include"))); -} - -TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderAndroidClang) -{ - projectPart.headerPaths = { - builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include/i686-linux-android"), - builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include"), - builtIn("C:/Android/sdk/ndk-bundle/sources/android/support/include"), - builtIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include"), - builtIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include") - }; - projectPart.toolChainTargetTriple = "i686-linux-android"; - CppTools::HeaderPathFilter filter{projectPart, - CppTools::UseTweakedHeaderPaths::Yes, - "6.0", - CLANG_INCLUDE_DIR}; - - filter.process(); - - ASSERT_THAT( - filter.builtInHeaderPaths, - ElementsAre(HasBuiltIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include"), - HasBuiltIn("C:/Android/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include"), - HasBuiltIn(CLANG_INCLUDE_DIR), - HasBuiltIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include/i686-linux-android"), - HasBuiltIn("C:/Android/sdk/ndk-bundle/sources/android/support/include"), - HasBuiltIn("C:/Android/sdk/ndk-bundle/sysroot/usr/include"))); -} - -} // namespace diff --git a/tests/unit/unittest/unittest.pro b/tests/unit/unittest/unittest.pro index c94c5f320de..99181e6b2db 100644 --- a/tests/unit/unittest/unittest.pro +++ b/tests/unit/unittest/unittest.pro @@ -97,7 +97,6 @@ SOURCES += \ mocktimer.cpp \ task.cpp \ compilationdatabaseutils-test.cpp \ - headerpathfilter-test.cpp \ sqlitecolumn-test.cpp \ sqlitedatabasebackend-test.cpp \ sqlitedatabase-test.cpp \ diff --git a/tests/unit/unittest/unittest.qbs b/tests/unit/unittest/unittest.qbs index 3120c3f2245..85226bb9685 100644 --- a/tests/unit/unittest/unittest.qbs +++ b/tests/unit/unittest/unittest.qbs @@ -190,7 +190,6 @@ Project { "gtest-llvm-printing.h", "gtest-qt-printing.cpp", "gtest-qt-printing.h", - "headerpathfilter-test.cpp", "lineprefixer-test.cpp", "matchingtext-test.cpp", "mimedatabase-utilities.cpp", @@ -489,8 +488,6 @@ Project { "cppprojectfilecategorizer.h", "cppprojectpartchooser.cpp", "cppprojectpartchooser.h", - "headerpathfilter.cpp", - "headerpathfilter.h", "projectinfo.cpp", "projectinfo.h", "projectpart.cpp",