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,77 +69,85 @@ 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",
"i686-w64-mingw32", "i686-w64-mingw32",
"-std=gnu++14", "-std=gnu++14",
"-fcxx-exceptions", "-fcxx-exceptions",
"-fexceptions", "-fexceptions",
"-DUNICODE", "-DUNICODE",
"-DRELATIVE_PLUGIN_PATH=\"../lib/qtcreator/plugins\"", "-DRELATIVE_PLUGIN_PATH=\"../lib/qtcreator/plugins\"",
"-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,
"-target", Eq(QStringList{"-m32",
"i686-w64-mingw32", "-target",
"-std=gnu++14", "i686-w64-mingw32",
"-fcxx-exceptions", "-std=gnu++14",
"-fexceptions"})); "-fcxx-exceptions",
ASSERT_THAT(headerPaths, Eq(HeaderPaths{ "-fexceptions"}));
{"C:\\Qt\\5.9.2\\mingw53_32\\include", HeaderPathType::User}, ASSERT_THAT(headerPaths,
{"C:\\Qt\\5.9.2\\mingw53_32\\include\\QtWidgets", HeaderPathType::User} Eq(HeaderPaths{{QString::fromUtf8(HostOsInfo::isWindowsHost() ? winPath1 : otherPath1),
})); HeaderPathType::User},
ASSERT_THAT(macros, Eq(Macros{ {QString::fromUtf8(HostOsInfo::isWindowsHost() ? winPath2 : otherPath2),
{"UNICODE", "1"}, HeaderPathType::User}}));
{"RELATIVE_PLUGIN_PATH", "\"../lib/qtcreator/plugins\""}, ASSERT_THAT(macros,
{"QT_CREATOR", "1"} Eq(Macros{{"UNICODE", "1"},
})); {"RELATIVE_PLUGIN_PATH", "\"../lib/qtcreator/plugins\""},
{"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
"/nologo " = "C:\\PROGRA~2\\MICROS~2\\2017\\COMMUN~1\\VC\\Tools\\MSVC\\1415~1.267\\bin\\HostX64\\x64\\cl."
"/TP " "exe "
"-DUNICODE " "/nologo "
"-D_HAS_EXCEPTIONS=0 " "/TP "
"-Itools\\clang\\lib\\Sema " "-DUNICODE "
"/DWIN32 " "-D_HAS_EXCEPTIONS=0 "
"/D_WINDOWS " "-Itools\\clang\\lib\\Sema "
"/Zc:inline " "/DWIN32 "
"/Zc:strictStrings " "/D_WINDOWS "
"/Oi " "/Zc:inline "
"/Zc:rvalueCast " "/Zc:strictStrings "
"/W4 " "/Oi "
"-wd4141 " "/Zc:rvalueCast "
"-wd4146 " "/W4 "
"/MDd " "-wd4141 "
"/Zi " "-wd4146 "
"/Ob0 " "/MDd "
"/Od " "/Zi "
"/RTC1 " "/Ob0 "
"/EHs-c- " "/Od "
"/GR " "/RTC1 "
"/Fotools\\clang\\lib\\Sema\\CMakeFiles\\clangSema.dir\\SemaCodeComplete.cpp.obj " "/EHs-c- "
"/FdTARGET_COMPILE_PDB " "/GR "
"/FS " "/Fotools\\clang\\lib\\Sema\\CMakeFiles\\clangSema.dir\\SemaCodeComplete.cpp.obj "
"-c " "/FdTARGET_COMPILE_PDB "
"C:\\qt_llvm\\tools\\clang\\lib\\Sema\\SemaCodeComplete.cpp"; "/FS "
"-c "
"C:\\qt_llvm\\tools\\clang\\lib\\Sema\\SemaCodeComplete.cpp";
TEST_F(CompilationDatabaseUtils, SplitFlags) TEST_F(CompilationDatabaseUtils, SplitFlags)
{ {
@@ -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);
} }
@@ -192,7 +194,7 @@ TEST_F(CompilationDatabaseUtils, FileKindDifferentFromExtension)
TEST_F(CompilationDatabaseUtils, FileKindDifferentFromExtension2) TEST_F(CompilationDatabaseUtils, FileKindDifferentFromExtension2)
{ {
fileName = "foo.cpp"; fileName = "foo.cpp";
flags = QStringList{"-x", "c"}; flags = QStringList{"-x", "c"};
filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind); filteredFlags(fileName, workingDir, flags, headerPaths, macros, fileKind);
@@ -208,4 +210,4 @@ TEST_F(CompilationDatabaseUtils, SkipOutputFiles)
ASSERT_THAT(flags.isEmpty(), true); ASSERT_THAT(flags.isEmpty(), true);
} }
} } // namespace