logic: paths in ProjectSettings relative to file not working directory

This change checks all paths in the ProjectSettings file for relativity and makes them relative to the location of the
ProjectSettings file if necessary. The paths are also correctly saved relative to the file.
This commit is contained in:
Eberhard Graether
2015-07-29 22:20:26 +02:00
parent 336df76912
commit 5f25311389
31 changed files with 407 additions and 148 deletions
+8 -8
View File
@@ -7,9 +7,9 @@ class FileManagerTestSuite : public CxxTest::TestSuite
public:
void test_file_manager_is_created_empty()
{
std::vector<std::string> sourcePaths;
std::vector<FilePath> sourcePaths;
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
std::vector<std::string> includePaths;
std::vector<FilePath> includePaths;
includePaths.push_back("./data/FileManagerTestSuite/include/");
std::vector<std::string> sourceExtensions;
sourceExtensions.push_back(".cpp");
@@ -27,9 +27,9 @@ public:
void test_file_manager_has_added_file_paths_after_first_fetch()
{
std::vector<std::string> sourcePaths;
std::vector<FilePath> sourcePaths;
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
std::vector<std::string> includePaths;
std::vector<FilePath> includePaths;
includePaths.push_back("./data/FileManagerTestSuite/include/");
std::vector<std::string> sourceExtensions;
sourceExtensions.push_back(".cpp");
@@ -46,9 +46,9 @@ public:
void test_file_manager_has_no_added_file_paths_after_second_fetch()
{
std::vector<std::string> sourcePaths;
std::vector<FilePath> sourcePaths;
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
std::vector<std::string> includePaths;
std::vector<FilePath> includePaths;
includePaths.push_back("./data/FileManagerTestSuite/include/");
std::vector<std::string> sourceExtensions;
sourceExtensions.push_back(".cpp");
@@ -66,9 +66,9 @@ public:
void test_file_manager_has_updated_file_paths_after_second_fetch()
{
std::vector<std::string> sourcePaths;
std::vector<FilePath> sourcePaths;
sourcePaths.push_back("./data/FileManagerTestSuite/src/");
std::vector<std::string> includePaths;
std::vector<FilePath> includePaths;
includePaths.push_back("./data/FileManagerTestSuite/include/");
std::vector<std::string> sourceExtensions;
sourceExtensions.push_back(".cpp");
+57 -1
View File
@@ -5,6 +5,13 @@
class FilePathTestSuite : public CxxTest::TestSuite
{
public:
void test_file_path_gets_created_empty()
{
FilePath path;
TS_ASSERT_EQUALS(path.str(), "");
}
void test_file_path_gets_created_with_char_array()
{
FilePath path("data/FilePathTestSuite/main.cpp");
@@ -28,6 +35,15 @@ public:
TS_ASSERT_EQUALS(path, path2);
}
void test_file_path_empty()
{
FilePath path1("data/FilePathTestSuite/a.cpp");
FilePath path2;
TS_ASSERT(!path1.empty());
TS_ASSERT(path2.empty());
}
void test_file_path_exists()
{
FilePath path("data/FilePathTestSuite/a.cpp");
@@ -42,6 +58,39 @@ public:
TS_ASSERT(!path.exists());
}
void test_file_path_is_directory()
{
FilePath path("data/FilePathTestSuite/a.cpp");
TS_ASSERT(!path.isDirectory());
TS_ASSERT(path.parentDirectory().isDirectory());
}
void test_file_path_is_absolute()
{
FilePath path("data/FilePathTestSuite/a.cpp");
TS_ASSERT(!path.isAbsolute());
TS_ASSERT(path.absolute().isAbsolute());
}
void test_file_path_parent_directory()
{
FilePath path("data/FilePathTestSuite/a.cpp");
TS_ASSERT(path.parentDirectory().str() == "data/FilePathTestSuite");
TS_ASSERT(path.parentDirectory().parentDirectory().str() == "data");
}
void test_file_path_relative_to_other_path()
{
FilePath pathA("data/FilePathTestSuite/a.cpp");
FilePath pathB("data/FilePathTestSuite/test/c.h");
TS_ASSERT_EQUALS(pathA.relativeTo(pathB).str(), "../a.cpp");
TS_ASSERT_EQUALS(pathB.relativeTo(pathA).str(), "test/c.h");
}
void test_file_path_file_name()
{
FilePath path("data/FilePathTestSuite/abc.h");
@@ -86,11 +135,18 @@ public:
void test_file_path_equals_relative_and_absolute_paths()
{
FilePath pathA("data/FilePathTestSuite/a.cpp");
FilePath pathA2(pathA.absoluteStr());
FilePath pathA2(pathA.absolute());
TS_ASSERT_EQUALS(pathA, pathA2);
}
void test_file_path_equals_absolute_and_canonical_paths()
{
FilePath path("data/../data/FilePathTestSuite/./a.cpp");
TS_ASSERT_EQUALS(path.absolute(), path.canonical());
}
void test_file_path_compares_paths_with_posix_and_windows_format()
{
#ifdef _WIN32
+2 -3
View File
@@ -78,11 +78,10 @@ public:
extensions.push_back(".hpp");
extensions.push_back(".cpp");
std::vector<std::string> directoryPaths;
std::vector<FilePath> directoryPaths;
directoryPaths.push_back("./data/FileSystemTestSuite");
std::vector<FileInfo> files =
FileSystem::getFileInfosFromDirectoryPaths(directoryPaths, extensions);
std::vector<FileInfo> files = FileSystem::getFileInfosFromPaths(directoryPaths, extensions);
TS_ASSERT_EQUALS(files.size(), 5);
}
+5 -5
View File
@@ -114,20 +114,20 @@ public:
void test_load_source_path_from_file()
{
ProjectSettings::getInstance()->load("data/SettingsTestSuite/settings.xml");
std::vector<std::string> paths = ProjectSettings::getInstance()->getSourcePaths();
std::vector<FilePath> paths = ProjectSettings::getInstance()->getSourcePaths();
TS_ASSERT_EQUALS(paths.size(), 1);
TS_ASSERT_EQUALS(paths[0], "data");
TS_ASSERT_EQUALS(paths[0].str(), "data/SettingsTestSuite/data");
}
void test_load_header_search_paths_from_file()
{
ProjectSettings::getInstance()->load("data/SettingsTestSuite/settings.xml");
std::vector<std::string> paths = ProjectSettings::getInstance()->getHeaderSearchPaths();
std::vector<FilePath> paths = ProjectSettings::getInstance()->getHeaderSearchPaths();
TS_ASSERT_EQUALS(paths.size(), 2);
TS_ASSERT_EQUALS(paths[0], "data/");
TS_ASSERT_EQUALS(paths[1], "src/");
TS_ASSERT_EQUALS(paths[0].str(), "data/SettingsTestSuite/data/");
TS_ASSERT_EQUALS(paths[1].str(), "data/SettingsTestSuite/src/");
}
private:
+2 -2
View File
@@ -2,8 +2,8 @@
TestFileManager::TestFileManager()
: FileManager(
std::vector<std::string>(),
std::vector<std::string>(),
std::vector<FilePath>(),
std::vector<FilePath>(),
std::vector<std::string>(),
std::vector<std::string>()
)