1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 20:23:55 +00:00

Adding Validator tests, fixed a bug

This commit is contained in:
Henry Fredrick Schreiner 2017-03-08 08:25:10 -05:00
parent 3d664b7100
commit e23f56551d
2 changed files with 27 additions and 1 deletions

View File

@ -51,7 +51,7 @@ bool ExistingDirectory(std::string filename) {
return true; return true;
} else { } else {
std::cerr << "Directory is actually a file: " << filename << std::endl; std::cerr << "Directory is actually a file: " << filename << std::endl;
return true; return false;
} }
} }

View File

@ -83,6 +83,32 @@ TEST(Validators, FileNotExists) {
EXPECT_TRUE(CLI::NonexistentPath(myfile)); EXPECT_TRUE(CLI::NonexistentPath(myfile));
} }
TEST(Validators, FileIsDir) {
std::string mydir{"../tests"};
EXPECT_FALSE(CLI::ExistingFile(mydir));
}
TEST(Validators, DirectoryExists) {
std::string mydir{"../tests"};
EXPECT_TRUE(CLI::ExistingDirectory(mydir));
}
TEST(Validators, DirectoryNotExists) {
std::string mydir{"nondirectory"};
EXPECT_FALSE(CLI::ExistingDirectory(mydir));
}
TEST(Validators, DirectoryIsFile) {
std::string myfile{"TestFileNotUsed.txt"};
EXPECT_TRUE(CLI::NonexistentPath(myfile));
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
EXPECT_TRUE(ok);
EXPECT_FALSE(CLI::ExistingDirectory(myfile));
std::remove(myfile.c_str());
EXPECT_TRUE(CLI::NonexistentPath(myfile));
}
// Yes, this is testing an app_helper :) // Yes, this is testing an app_helper :)
TEST(AppHelper, TempfileCreated) { TEST(AppHelper, TempfileCreated) {
std::string name = "TestFileNotUsed.txt"; std::string name = "TestFileNotUsed.txt";