mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 12:43:52 +00:00
Coverage to 100% (#929)
remove old code since all arguments are quoted now and the code was not being used, add coverage exclusion on some code that should never be executed and add an additional test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
c99918ea5a
commit
dd4bbd8847
@ -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.
|
/// 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);
|
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
|
/// get the value of an environmental variable or empty string if empty
|
||||||
CLI11_INLINE std::string get_environment_value(const std::string &env_name);
|
CLI11_INLINE std::string get_environment_value(const std::string &env_name);
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
@ -244,17 +244,6 @@ CLI11_INLINE std::size_t escape_detect(std::string &str, std::size_t offset) {
|
|||||||
return offset + 1;
|
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) {
|
std::string get_environment_value(const std::string &env_name) {
|
||||||
char *buffer = nullptr;
|
char *buffer = nullptr;
|
||||||
std::string ename_string;
|
std::string ename_string;
|
||||||
|
@ -135,7 +135,7 @@ CLI11_INLINE path_type check_path(const char *file) noexcept {
|
|||||||
switch(stat.type()) {
|
switch(stat.type()) {
|
||||||
case std::filesystem::file_type::none: // LCOV_EXCL_LINE
|
case std::filesystem::file_type::none: // LCOV_EXCL_LINE
|
||||||
case std::filesystem::file_type::not_found:
|
case std::filesystem::file_type::not_found:
|
||||||
return path_type::nonexistent;
|
return path_type::nonexistent; // LCOV_EXCL_LINE
|
||||||
case std::filesystem::file_type::directory:
|
case std::filesystem::file_type::directory:
|
||||||
return path_type::directory;
|
return path_type::directory;
|
||||||
case std::filesystem::file_type::symlink:
|
case std::filesystem::file_type::symlink:
|
||||||
|
@ -1101,6 +1101,42 @@ TEST_CASE_METHOD(TApp, "emptyVectorReturn", "[app]") {
|
|||||||
CHECK_FALSE(strs3.empty());
|
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]") {
|
TEST_CASE_METHOD(TApp, "RequiredOptsDoubleShort", "[app]") {
|
||||||
|
|
||||||
std::vector<std::string> strs;
|
std::vector<std::string> strs;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user