forked from qt-creator/qt-creator
CppTools: Move HeaderPathsFilter tests to plugin
Change-Id: Iecbb0942bed51002e85b96f6cc2ab034622cd07f Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -241,6 +241,19 @@ private slots:
|
|||||||
void test_projectInfoGenerator_useMacroInspectionReportForLanguageVersion();
|
void test_projectInfoGenerator_useMacroInspectionReportForLanguageVersion();
|
||||||
void test_projectInfoGenerator_useCompilerFlagsForLanguageExtensions();
|
void test_projectInfoGenerator_useCompilerFlagsForLanguageExtensions();
|
||||||
void test_projectInfoGenerator_projectFileKindsMatchProjectPartVersion();
|
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
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -9,13 +9,11 @@ HEADERS += \
|
|||||||
$$PWD/senddocumenttracker.h \
|
$$PWD/senddocumenttracker.h \
|
||||||
$$PWD/projectpart.h \
|
$$PWD/projectpart.h \
|
||||||
$$PWD/cppprojectfilecategorizer.h \
|
$$PWD/cppprojectfilecategorizer.h \
|
||||||
$$PWD/projectinfo.h \
|
$$PWD/projectinfo.h
|
||||||
$$PWD/headerpathfilter.h
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/cppprojectfile.cpp \
|
$$PWD/cppprojectfile.cpp \
|
||||||
$$PWD/senddocumenttracker.cpp \
|
$$PWD/senddocumenttracker.cpp \
|
||||||
$$PWD/projectpart.cpp \
|
$$PWD/projectpart.cpp \
|
||||||
$$PWD/cppprojectfilecategorizer.cpp \
|
$$PWD/cppprojectfilecategorizer.cpp \
|
||||||
$$PWD/projectinfo.cpp \
|
$$PWD/projectinfo.cpp
|
||||||
$$PWD/headerpathfilter.cpp
|
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "cppprojectinfogenerator.h"
|
#include "cppprojectinfogenerator.h"
|
||||||
#include "cppprojectpartchooser.h"
|
#include "cppprojectpartchooser.h"
|
||||||
#include "cpptoolsplugin.h"
|
#include "cpptoolsplugin.h"
|
||||||
|
#include "headerpathfilter.h"
|
||||||
#include "projectinfo.h"
|
#include "projectinfo.h"
|
||||||
|
|
||||||
#include <projectexplorer/toolchainconfigwidget.h>
|
#include <projectexplorer/toolchainconfigwidget.h>
|
||||||
@@ -33,6 +34,8 @@
|
|||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
namespace CppTools {
|
namespace CppTools {
|
||||||
namespace Internal {
|
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 <installdir>/include and <installdir/include-next> 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 "<installdir>/include/c++" (MinGW)
|
||||||
|
// or e.g. "<installdir>/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 Internal
|
||||||
} // namespace CppTools
|
} // namespace CppTools
|
||||||
|
@@ -55,7 +55,6 @@ add_qtc_test(unittest GTEST
|
|||||||
gtest-llvm-printing.h
|
gtest-llvm-printing.h
|
||||||
gtest-qt-printing.cpp gtest-qt-printing.h
|
gtest-qt-printing.cpp gtest-qt-printing.h
|
||||||
gtest-std-printing.h
|
gtest-std-printing.h
|
||||||
headerpathfilter-test.cpp
|
|
||||||
highlightingresultreporter-test.cpp
|
highlightingresultreporter-test.cpp
|
||||||
lastchangedrowid-test.cpp
|
lastchangedrowid-test.cpp
|
||||||
lineprefixer-test.cpp
|
lineprefixer-test.cpp
|
||||||
@@ -456,7 +455,6 @@ extend_qtc_test(unittest
|
|||||||
cppprojectfilecategorizer.cpp cppprojectfilecategorizer.h
|
cppprojectfilecategorizer.cpp cppprojectfilecategorizer.h
|
||||||
projectinfo.cpp projectinfo.h
|
projectinfo.cpp projectinfo.h
|
||||||
cppprojectpartchooser.cpp cppprojectpartchooser.h
|
cppprojectpartchooser.cpp cppprojectpartchooser.h
|
||||||
headerpathfilter.cpp headerpathfilter.h
|
|
||||||
)
|
)
|
||||||
|
|
||||||
extend_qtc_test(unittest
|
extend_qtc_test(unittest
|
||||||
|
@@ -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 <cpptools/headerpathfilter.h>
|
|
||||||
#include <projectexplorer/project.h>
|
|
||||||
#include <projectexplorer/projectexplorerconstants.h>
|
|
||||||
|
|
||||||
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 <installdir>/include and <installdir/include-next> 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 "<installdir>/include/c++" (MinGW)
|
|
||||||
// or e.g. "<installdir>/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
|
|
@@ -97,7 +97,6 @@ SOURCES += \
|
|||||||
mocktimer.cpp \
|
mocktimer.cpp \
|
||||||
task.cpp \
|
task.cpp \
|
||||||
compilationdatabaseutils-test.cpp \
|
compilationdatabaseutils-test.cpp \
|
||||||
headerpathfilter-test.cpp \
|
|
||||||
sqlitecolumn-test.cpp \
|
sqlitecolumn-test.cpp \
|
||||||
sqlitedatabasebackend-test.cpp \
|
sqlitedatabasebackend-test.cpp \
|
||||||
sqlitedatabase-test.cpp \
|
sqlitedatabase-test.cpp \
|
||||||
|
@@ -190,7 +190,6 @@ Project {
|
|||||||
"gtest-llvm-printing.h",
|
"gtest-llvm-printing.h",
|
||||||
"gtest-qt-printing.cpp",
|
"gtest-qt-printing.cpp",
|
||||||
"gtest-qt-printing.h",
|
"gtest-qt-printing.h",
|
||||||
"headerpathfilter-test.cpp",
|
|
||||||
"lineprefixer-test.cpp",
|
"lineprefixer-test.cpp",
|
||||||
"matchingtext-test.cpp",
|
"matchingtext-test.cpp",
|
||||||
"mimedatabase-utilities.cpp",
|
"mimedatabase-utilities.cpp",
|
||||||
@@ -489,8 +488,6 @@ Project {
|
|||||||
"cppprojectfilecategorizer.h",
|
"cppprojectfilecategorizer.h",
|
||||||
"cppprojectpartchooser.cpp",
|
"cppprojectpartchooser.cpp",
|
||||||
"cppprojectpartchooser.h",
|
"cppprojectpartchooser.h",
|
||||||
"headerpathfilter.cpp",
|
|
||||||
"headerpathfilter.h",
|
|
||||||
"projectinfo.cpp",
|
"projectinfo.cpp",
|
||||||
"projectinfo.h",
|
"projectinfo.h",
|
||||||
"projectpart.cpp",
|
"projectpart.cpp",
|
||||||
|
Reference in New Issue
Block a user