CompilationDatabase: Fix unit-test

Change-Id: I2a2e2b5ead35236f11e6f9f0ec15608b30335fd1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-04-26 14:09:21 +02:00
committed by Ivan Donchevskii
parent 24263717f3
commit d4c5a6f9b2

View File

@@ -29,6 +29,7 @@
#include <projectexplorer/headerpath.h> #include <projectexplorer/headerpath.h>
#include <projectexplorer/projectmacro.h> #include <projectexplorer/projectmacro.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/hostosinfo.h>
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace CompilationDatabaseProjectManager; using namespace CompilationDatabaseProjectManager;
@@ -68,10 +69,15 @@ TEST_F(CompilationDatabaseUtils, FilterFromFilename)
TEST_F(CompilationDatabaseUtils, FilterArguments) TEST_F(CompilationDatabaseUtils, FilterArguments)
{ {
using Utils::HostOsInfo;
const char winPath1[] = "C:\\Qt\\5.9.2\\mingw53_32\\include";
const char otherPath1[] = "/Qt/5.9.2/mingw53_32/include";
const char winPath2[] = "C:\\Qt\\5.9.2\\mingw53_32\\include\\QtWidgets";
const char otherPath2[] = "/Qt/5.9.2/mingw53_32/include/QtWidgets";
fileName = "compileroptionsbuilder.cpp"; fileName = "compileroptionsbuilder.cpp";
workingDir = "C:/build-qtcreator-MinGW_32bit-Debug"; workingDir = "C:/build-qtcreator-MinGW_32bit-Debug";
flags = filterFromFileName(QStringList { flags = filterFromFileName(
"clang++", QStringList{"clang++",
"-c", "-c",
"-m32", "-m32",
"-target", "-target",
@@ -84,35 +90,38 @@ TEST_F(CompilationDatabaseUtils, FilterArguments)
"-DQT_CREATOR", "-DQT_CREATOR",
"-fPIC", "-fPIC",
"-I", "-I",
"C:\\Qt\\5.9.2\\mingw53_32\\include", QString::fromUtf8(HostOsInfo::isWindowsHost() ? winPath1 : otherPath1),
"-I", "-I",
"C:\\Qt\\5.9.2\\mingw53_32\\include\\QtWidgets", QString::fromUtf8(HostOsInfo::isWindowsHost() ? winPath2 : otherPath2),
"-x", "-x",
"c++", "c++",
"C:\\qt-creator\\src\\plugins\\cpptools\\compileroptionsbuilder.cpp" "C:\\qt-creator\\src\\plugins\\cpptools\\compileroptionsbuilder.cpp"},
}, "compileroptionsbuilder"); "compileroptionsbuilder");
filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind); filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind);
ASSERT_THAT(flags, Eq(QStringList{"-m32", ASSERT_THAT(flags,
Eq(QStringList{"-m32",
"-target", "-target",
"i686-w64-mingw32", "i686-w64-mingw32",
"-std=gnu++14", "-std=gnu++14",
"-fcxx-exceptions", "-fcxx-exceptions",
"-fexceptions"})); "-fexceptions"}));
ASSERT_THAT(headerPaths, Eq(HeaderPaths{ ASSERT_THAT(headerPaths,
{"C:\\Qt\\5.9.2\\mingw53_32\\include", HeaderPathType::User}, Eq(HeaderPaths{{QString::fromUtf8(HostOsInfo::isWindowsHost() ? winPath1 : otherPath1),
{"C:\\Qt\\5.9.2\\mingw53_32\\include\\QtWidgets", HeaderPathType::User} HeaderPathType::User},
})); {QString::fromUtf8(HostOsInfo::isWindowsHost() ? winPath2 : otherPath2),
ASSERT_THAT(macros, Eq(Macros{ HeaderPathType::User}}));
{"UNICODE", "1"}, ASSERT_THAT(macros,
Eq(Macros{{"UNICODE", "1"},
{"RELATIVE_PLUGIN_PATH", "\"../lib/qtcreator/plugins\""}, {"RELATIVE_PLUGIN_PATH", "\"../lib/qtcreator/plugins\""},
{"QT_CREATOR", "1"} {"QT_CREATOR", "1"}}));
}));
ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CXXSource); ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CXXSource);
} }
static QString kCmakeCommand = "C:\\PROGRA~2\\MICROS~2\\2017\\COMMUN~1\\VC\\Tools\\MSVC\\1415~1.267\\bin\\HostX64\\x64\\cl.exe " static QString kCmakeCommand
= "C:\\PROGRA~2\\MICROS~2\\2017\\COMMUN~1\\VC\\Tools\\MSVC\\1415~1.267\\bin\\HostX64\\x64\\cl."
"exe "
"/nologo " "/nologo "
"/TP " "/TP "
"-DUNICODE " "-DUNICODE "
@@ -163,19 +172,12 @@ TEST_F(CompilationDatabaseUtils, FilterCommand)
filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind); filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind);
ASSERT_THAT(flags, Eq(QStringList{"/Zc:inline", ASSERT_THAT(flags, Eq(QStringList{"/Zc:inline", "/Zc:strictStrings", "/Zc:rvalueCast", "/Zi"}));
"/Zc:strictStrings", ASSERT_THAT(headerPaths,
"/Zc:rvalueCast", Eq(HeaderPaths{{"C:/build-qt_llvm-msvc2017_64bit-Debug/tools\\clang\\lib\\Sema",
"/Zi"})); HeaderPathType::User}}));
ASSERT_THAT(headerPaths, Eq(HeaderPaths{ ASSERT_THAT(macros,
{"tools\\clang\\lib\\Sema", HeaderPathType::User} Eq(Macros{{"UNICODE", "1"}, {"_HAS_EXCEPTIONS", "0"}, {"WIN32", "1"}, {"_WINDOWS", "1"}}));
}));
ASSERT_THAT(macros, Eq(Macros{
{"UNICODE", "1"},
{"_HAS_EXCEPTIONS", "0"},
{"WIN32", "1"},
{"_WINDOWS", "1"}
}));
ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CXXSource); ASSERT_THAT(fileKind, CppTools::ProjectFile::Kind::CXXSource);
} }
@@ -208,4 +210,4 @@ TEST_F(CompilationDatabaseUtils, SkipOutputFiles)
ASSERT_THAT(flags.isEmpty(), true); ASSERT_THAT(flags.isEmpty(), true);
} }
} } // namespace