forked from qt-creator/qt-creator
Clang: Use full paths in compilation database for symbol collector
We we FilePath and NativeFilePath so that compiler warns us if we mix them up. Change-Id: I33d7abc7e4e724dff2a9b2b9b23deea8b358ccfd Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -24,8 +24,10 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "googletest.h"
|
||||
#include "filesystem-utilities.h"
|
||||
|
||||
#include <refactoringcompilationdatabase.h>
|
||||
#include <nativefilepath.h>
|
||||
|
||||
#include <utils/smallstring.h>
|
||||
|
||||
@@ -38,16 +40,16 @@ using testing::PrintToString;
|
||||
|
||||
namespace {
|
||||
|
||||
MATCHER_P3(IsCompileCommand, directory, fileName, commandLine,
|
||||
std::string(negation ? "isn't" : "is")
|
||||
+ " compile command with directory "+ PrintToString(directory)
|
||||
+ ", file name " + PrintToString(fileName)
|
||||
+ " and command line " + PrintToString(commandLine)
|
||||
)
|
||||
MATCHER_P3(IsCompileCommand,
|
||||
directory,
|
||||
filePath,
|
||||
commandLine,
|
||||
std::string(negation ? "isn't" : "is") + " compile command with directory "
|
||||
+ PrintToString(directory) + ", file name " + PrintToString(filePath)
|
||||
+ " and command line " + PrintToString(commandLine))
|
||||
{
|
||||
if (arg.Directory != directory
|
||||
|| arg.Filename != fileName
|
||||
|| arg.CommandLine != commandLine)
|
||||
if (arg.Directory != std::string(directory) || arg.Filename != std::string(filePath)
|
||||
|| arg.CommandLine != commandLine)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -56,7 +58,11 @@ MATCHER_P3(IsCompileCommand, directory, fileName, commandLine,
|
||||
class RefactoringCompilationDatabase : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp();
|
||||
RefactoringCompilationDatabase()
|
||||
{
|
||||
database.addFile(ClangBackEnd::NativeFilePathView{temporarySourceFilePath},
|
||||
{"cc", toNativePath(temporaryDirectoryPath + "/data.cpp").path(), "-DNO_DEBUG"});
|
||||
}
|
||||
|
||||
protected:
|
||||
ClangBackEnd::RefactoringCompilationDatabase database;
|
||||
@@ -76,18 +82,28 @@ TEST_F(RefactoringCompilationDatabase, CompileCommandForFilePath)
|
||||
{
|
||||
auto compileCommands = database.getAllCompileCommands();
|
||||
|
||||
ASSERT_THAT(compileCommands, Contains(IsCompileCommand(temporaryDirectoryPath,
|
||||
"data.cpp",
|
||||
std::vector<std::string>{"cc", "data.cpp", "-DNO_DEBUG"})));
|
||||
ASSERT_THAT(compileCommands,
|
||||
Contains(IsCompileCommand(
|
||||
temporaryDirectoryPath,
|
||||
toNativePath(temporaryDirectoryPath + "/data.cpp").path(),
|
||||
std::vector<std::string>{
|
||||
"cc",
|
||||
std::string(toNativePath(temporaryDirectoryPath + "/data.cpp").path()),
|
||||
"-DNO_DEBUG"})));
|
||||
}
|
||||
|
||||
TEST_F(RefactoringCompilationDatabase, NoCompileCommandForFilePath)
|
||||
{
|
||||
auto compileCommands = database.getAllCompileCommands();
|
||||
|
||||
ASSERT_THAT(compileCommands, Not(Contains(IsCompileCommand(temporaryDirectoryPath,
|
||||
"data.cpp2",
|
||||
std::vector<std::string>{"cc", "data.cpp", "-DNO_DEBUG"}))));
|
||||
ASSERT_THAT(compileCommands,
|
||||
Not(Contains(IsCompileCommand(
|
||||
temporaryDirectoryPath,
|
||||
toNativePath(temporaryDirectoryPath + "/data.cpp2").path(),
|
||||
std::vector<std::string>{
|
||||
"cc",
|
||||
std::string(toNativePath(temporaryDirectoryPath + "/data.cpp").path()),
|
||||
"-DNO_DEBUG"}))));
|
||||
}
|
||||
|
||||
TEST_F(RefactoringCompilationDatabase, FilePaths)
|
||||
@@ -96,10 +112,4 @@ TEST_F(RefactoringCompilationDatabase, FilePaths)
|
||||
|
||||
ASSERT_THAT(filePaths, Contains(std::string(temporarySourceFilePath)));
|
||||
}
|
||||
|
||||
void RefactoringCompilationDatabase::SetUp()
|
||||
{
|
||||
database.addFile(std::string(temporaryDirectoryPath), "data.cpp", {"cc", "data.cpp", "-DNO_DEBUG"});
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user