Skip to content

Commit

Permalink
Adding test for #87
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Apr 8, 2018
1 parent 4f6bbba commit 0959430
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## In progress
## Version 1.5: Optional

This version has some internal cleanup and improved support for the newest compilers.

This version introduced support for optionals, along with clarification and examples of custom conversion overloads. Enums now have been dropped from the automatic conversion system, allowing explicit protection for out-of-range ints (or a completely custom conversion). This version has some internal cleanup and improved support for the newest compilers. Several bugs were fixed, as well.

Note: This is the final release with `requires`, please switch to `needs`.

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ Significant features and/or improvements to the code were contributed by:
* [Lucas Czech](https://github.com/lczech)
* [Mathias Soeken](https://github.com/msoeken)
* [Nathan Hourt](https://github.com/nathanhourt)
* [Stéphane Del Pino](https://github.com/delpinux)
* [Anton](https://github.com/SX91)
CLI11 was developed at the [University of Cincinnati] to support of the [GooFit] library under [NSF Award 1414736]. Version 0.9 was featured in a [DIANA/HEP] meeting at CERN ([see the slides][DIANA slides]). Please give it a try! Feedback is always welcome.
Expand Down
18 changes: 18 additions & 0 deletions tests/AppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,3 +1458,21 @@ TEST_F(TApp, ThrowingTransform) {
EXPECT_EQ(e.what(), std::string("--mess: My Message"));
}
}

// #87
TEST_F(TApp, CustomDoubleOption) {

std::pair<int, float> custom_opt;

auto opt = app.add_option("posit", [&custom_opt](CLI::results_t vals) {
custom_opt = {stol(vals.at(0)), stod(vals.at(1))};
return true;
});
opt->set_custom_option("INT FLOAT", 2);

args = {"12", "1.5"};

run();
EXPECT_EQ(custom_opt.first, 12);
EXPECT_FLOAT_EQ(custom_opt.second, 1.5);
}
16 changes: 16 additions & 0 deletions tests/HelpTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,19 @@ TEST_F(CapturedHelp, RepacedError) {
EXPECT_THAT(err.str(), HasSubstr("Thing"));
EXPECT_THAT(err.str(), HasSubstr("Usage"));
}

// #87
TEST(THelp, CustomDoubleOption) {

std::pair<int, float> custom_opt;

CLI::App app;

auto opt = app.add_option("posit", [&custom_opt](CLI::results_t vals) {
custom_opt = {stol(vals.at(0)), stod(vals.at(1))};
return true;
});
opt->set_custom_option("INT FLOAT", 2);

EXPECT_THAT(app.help(), Not(HasSubstr("x 2")));
}

0 comments on commit 0959430

Please sign in to comment.