Commit e23f56551dbbfbf0eef14244b46daee016eae962
1 parent
3d664b71
Adding Validator tests, fixed a bug
Showing
2 changed files
with
27 additions
and
1 deletions
include/CLI/Validators.hpp
| @@ -51,7 +51,7 @@ bool ExistingDirectory(std::string filename) { | @@ -51,7 +51,7 @@ bool ExistingDirectory(std::string filename) { | ||
| 51 | return true; | 51 | return true; |
| 52 | } else { | 52 | } else { |
| 53 | std::cerr << "Directory is actually a file: " << filename << std::endl; | 53 | std::cerr << "Directory is actually a file: " << filename << std::endl; |
| 54 | - return true; | 54 | + return false; |
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | 57 |
tests/HelpersTest.cpp
| @@ -83,6 +83,32 @@ TEST(Validators, FileNotExists) { | @@ -83,6 +83,32 @@ TEST(Validators, FileNotExists) { | ||
| 83 | EXPECT_TRUE(CLI::NonexistentPath(myfile)); | 83 | EXPECT_TRUE(CLI::NonexistentPath(myfile)); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | +TEST(Validators, FileIsDir) { | ||
| 87 | + std::string mydir{"../tests"}; | ||
| 88 | + EXPECT_FALSE(CLI::ExistingFile(mydir)); | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +TEST(Validators, DirectoryExists) { | ||
| 92 | + std::string mydir{"../tests"}; | ||
| 93 | + EXPECT_TRUE(CLI::ExistingDirectory(mydir)); | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +TEST(Validators, DirectoryNotExists) { | ||
| 97 | + std::string mydir{"nondirectory"}; | ||
| 98 | + EXPECT_FALSE(CLI::ExistingDirectory(mydir)); | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +TEST(Validators, DirectoryIsFile) { | ||
| 102 | + std::string myfile{"TestFileNotUsed.txt"}; | ||
| 103 | + EXPECT_TRUE(CLI::NonexistentPath(myfile)); | ||
| 104 | + bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file | ||
| 105 | + EXPECT_TRUE(ok); | ||
| 106 | + EXPECT_FALSE(CLI::ExistingDirectory(myfile)); | ||
| 107 | + | ||
| 108 | + std::remove(myfile.c_str()); | ||
| 109 | + EXPECT_TRUE(CLI::NonexistentPath(myfile)); | ||
| 110 | +} | ||
| 111 | + | ||
| 86 | // Yes, this is testing an app_helper :) | 112 | // Yes, this is testing an app_helper :) |
| 87 | TEST(AppHelper, TempfileCreated) { | 113 | TEST(AppHelper, TempfileCreated) { |
| 88 | std::string name = "TestFileNotUsed.txt"; | 114 | std::string name = "TestFileNotUsed.txt"; |