Added filesystem .. test

Supporting relative paths
This commit is contained in:
Mitchell Grenier 2015-03-03 14:39:30 -08:00
parent 6ad580a5de
commit 93577f3ab2
2 changed files with 40 additions and 0 deletions

View File

@ -505,12 +505,25 @@ Status resolveFilePattern(std::vector<std::string> components,
Status resolveFilePattern(const boost::filesystem::path& fs_path,
std::vector<std::string>& results) {
if (fs_path.string()[0] != '/') {
return resolveFilePattern(split(boost::filesystem::current_path().string() +
"/" + fs_path.string(),
"/"),
results);
}
return resolveFilePattern(split(fs_path.string(), "/"), results);
}
Status resolveFilePattern(const boost::filesystem::path& fs_path,
std::vector<std::string>& results,
ReturnSetting setting) {
if (fs_path.string()[0] != '/') {
return resolveFilePattern(split(boost::filesystem::current_path().string() +
"/" + fs_path.string(),
"/"),
results,
setting);
}
return resolveFilePattern(split(fs_path.string(), "/"), results, setting);
}

View File

@ -204,6 +204,33 @@ TEST_F(FilesystemTests, test_letter_wild_opt) {
EXPECT_NE(std::find(all.begin(), all.end(), kFakeDirectory + "/door.txt"),
all.end());
}
TEST_F(FilesystemTests, test_dotdot) {
std::vector<std::string> all;
auto status = resolveFilePattern(kFakeDirectory + "/deep11/deep2/../../%",
all, REC_LIST_FILES);
EXPECT_TRUE(status.ok());
EXPECT_EQ(all.size(), 3);
EXPECT_NE(std::find(all.begin(), all.end(),
kFakeDirectory + "/deep11/deep2/../../door.txt"),
all.end());
}
TEST_F(FilesystemTests, test_dotdot_relative) {
std::vector<std::string> all;
auto status =
resolveFilePattern("../../../../tools/tests/%", all, REC_LIST_ALL);
EXPECT_TRUE(status.ok());
bool found = false;
for (const auto& file : all) {
if (file.find("test.config")) {
found = true;
break;
}
}
EXPECT_TRUE(found);
}
}
int main(int argc, char* argv[]) {