Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage to 100% #929

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/CLI/StringTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ CLI11_INLINE std::vector<std::string> split_up(std::string str, char delimiter =
/// the return value is the offset+1 which is required by the find_and_modify function.
CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset);

/// Add quotes if the string contains spaces
CLI11_INLINE std::string &add_quotes_if_needed(std::string &str);

/// get the value of an environmental variable or empty string if empty
CLI11_INLINE std::string get_environment_value(const std::string &env_name);
} // namespace detail
Expand Down
11 changes: 0 additions & 11 deletions include/CLI/impl/StringTools_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,6 @@ CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset) {
return offset + 1;
}

CLI11_INLINE std::string &add_quotes_if_needed(std::string &str) {
if((str.front() != '"' && str.front() != '\'') || str.front() != str.back()) {
char quote = str.find('"') < str.find('\'') ? '\'' : '"';
if(str.find(' ') != std::string::npos) {
str.insert(0, 1, quote);
str.append(1, quote);
}
}
return str;
}

std::string get_environment_value(const std::string &env_name) {
char *buffer = nullptr;
std::string ename_string;
Expand Down
2 changes: 1 addition & 1 deletion include/CLI/impl/Validators_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ CLI11_INLINE path_type check_path(const char *file) noexcept {
switch(stat.type()) {
case std::filesystem::file_type::none: // LCOV_EXCL_LINE
case std::filesystem::file_type::not_found:
return path_type::nonexistent;
return path_type::nonexistent; // LCOV_EXCL_LINE
case std::filesystem::file_type::directory:
return path_type::directory;
case std::filesystem::file_type::symlink:
Expand Down
36 changes: 36 additions & 0 deletions tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,42 @@ TEST_CASE_METHOD(TApp, "emptyVectorReturn", "[app]") {
CHECK_FALSE(strs3.empty());
}

TEST_CASE_METHOD(TApp, "emptyVectorReturnReduce", "[app]") {

std::vector<std::string> strs;
std::vector<std::string> strs2;
std::vector<std::string> strs3;
auto *opt1 = app.add_option("--str", strs)->required()->expected(0, 2);
app.add_option("--str3", strs3)->expected(1, 3);
app.add_option("--str2", strs2)->expected(1, 1)->take_first();
args = {"--str"};

CHECK_NOTHROW(run());
CHECK(std::vector<std::string>({""}) == strs);
args = {"--str", "one", "two"};

run();

CHECK(std::vector<std::string>({"one", "two"}) == strs);

args = {"--str", "{}", "--str2", "{}", "test"};

run();

CHECK(strs.empty());
CHECK(std::vector<std::string>{"{}"} == strs2);
opt1->default_str("{}");
args = {"--str"};

CHECK_NOTHROW(run());
CHECK(strs.empty());
opt1->required(false);
args = {"--str3", "{}"};

CHECK_NOTHROW(run());
CHECK_FALSE(strs3.empty());
}

TEST_CASE_METHOD(TApp, "RequiredOptsDoubleShort", "[app]") {

std::vector<std::string> strs;
Expand Down