Skip to content

Commit

Permalink
update for coverage tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Oct 5, 2024
1 parent 88b03dd commit d0a80b5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ ignore:
- "docs"
- "test_package"
- "fuzz"

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no
8 changes: 4 additions & 4 deletions include/CLI/TypeTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ bool integral_conversion(const std::string &input, T &output) noexcept {
nstring.erase(std::remove(nstring.begin(), nstring.end(), '\''), nstring.end());
return integral_conversion(nstring, output);
}
if(input.compare(0, 2, "0o") == 0) {
if(input.compare(0, 2, "0o") == 0||input.compare(0, 2, "0O") == 0) {
val = nullptr;
errno = 0;
output_ll = std::strtoull(input.c_str() + 2, &val, 8);
Expand All @@ -914,7 +914,7 @@ bool integral_conversion(const std::string &input, T &output) noexcept {
output = static_cast<T>(output_ll);
return (val == (input.c_str() + input.size()) && static_cast<std::uint64_t>(output) == output_ll);
}
if(input.compare(0, 2, "0b") == 0) {
if(input.compare(0, 2, "0b") == 0||input.compare(0, 2, "0B") == 0) {
val = nullptr;
errno = 0;
output_ll = std::strtoull(input.c_str() + 2, &val, 2);
Expand Down Expand Up @@ -955,7 +955,7 @@ bool integral_conversion(const std::string &input, T &output) noexcept {
nstring.erase(std::remove(nstring.begin(), nstring.end(), '\''), nstring.end());
return integral_conversion(nstring, output);
}
if(input.compare(0, 2, "0o") == 0) {
if(input.compare(0, 2, "0o") == 0 || input.compare(0, 2, "0O")==0) {
val = nullptr;
errno = 0;
output_ll = std::strtoll(input.c_str() + 2, &val, 8);
Expand All @@ -965,7 +965,7 @@ bool integral_conversion(const std::string &input, T &output) noexcept {
output = static_cast<T>(output_ll);
return (val == (input.c_str() + input.size()) && static_cast<std::int64_t>(output) == output_ll);
}
if(input.compare(0, 2, "0b") == 0) {
if(input.compare(0, 2, "0b") == 0 ||input.compare(0, 2, "0B")==0) {
val = nullptr;
errno = 0;
output_ll = std::strtoll(input.c_str() + 2, &val, 2);
Expand Down
2 changes: 1 addition & 1 deletion include/CLI/impl/Formatter_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ CLI11_INLINE std::string Formatter::make_help(const App *app, std::string name,
// This immediately forwards to the make_expanded method. This is done this way so that subcommands can
// have overridden formatters
if(mode == AppFormatMode::Sub)
return make_expanded(app, AppFormatMode::Normal);
return make_expanded(app, mode);

std::stringstream out;
if((app->get_name().empty()) && (app->get_parent() != nullptr)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/OptionTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ static const std::map<std::string, std::int64_t> testValuesInt{
{"-995'862'275", -995862275},
{"0b11010110", 0xD6},
{"0b1101'0110", 0xD6},
{"0B11010110", 0xD6},
{"0B1101'0110", 0xD6},
{"1_2_3_4_5", 12345},
};

Expand Down Expand Up @@ -309,6 +311,10 @@ TEST_CASE_METHOD(TApp, "intConversionsErange", "[optiontype]") {
args = {"--val", "0b1011000001101011001100110011111000101010101011111111111111111111111001010111011100"};

CHECK_THROWS_AS(run(), CLI::ParseError);

args = {"--val", "0B1011000001101011001100110011111000101010101011111111111111111111111001010111011100"};

CHECK_THROWS_AS(run(), CLI::ParseError);
}

static const std::map<std::string, std::uint64_t> testValuesUInt{
Expand All @@ -329,6 +335,8 @@ static const std::map<std::string, std::uint64_t> testValuesUInt{
{"995'862'275", 995862275},
{"0b11010110", 0xD6},
{"0b1101'0110", 0xD6},
{"0B11010110", 0xD6},
{"0B1101'0110", 0xD6},
{"1_2_3_4_5", 12345},
};

Expand Down Expand Up @@ -358,6 +366,10 @@ TEST_CASE_METHOD(TApp, "uintConversionsErange", "[optiontype]") {
args = {"--val", "0b1011000001101011001100110011111000101010101011111111111111111111111001010111011100"};

CHECK_THROWS_AS(run(), CLI::ParseError);

args = {"--val", "0B1011000001101011001100110011111000101010101011111111111111111111111001010111011100"};

CHECK_THROWS_AS(run(), CLI::ParseError);
}

TEST_CASE_METHOD(TApp, "CharOption", "[optiontype]") {
Expand Down

0 comments on commit d0a80b5

Please sign in to comment.