mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 14:03:52 +00:00
Adding test, fixing option name to single name in message
This commit is contained in:
parent
85857d99e1
commit
44de4de118
@ -437,7 +437,7 @@ class Option : public OptionBase<Option> {
|
||||
for(const std::function<std::string(std::string &)> &vali : validators_) {
|
||||
std::string err_msg = vali(result);
|
||||
if(!err_msg.empty())
|
||||
throw ValidationError(get_name() + ": " + err_msg);
|
||||
throw ValidationError(single_name() + ": " + err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1172,8 +1172,8 @@ TEST_F(TApp, SetWithDefaultsIC) {
|
||||
EXPECT_THROW(run(), CLI::ConversionError);
|
||||
}
|
||||
|
||||
// Added to test defaults on dual method
|
||||
TEST_F(TApp, OrderedModifingValidators) {
|
||||
// Added to test ->transform
|
||||
TEST_F(TApp, OrderedModifingTransforms) {
|
||||
std::vector<std::string> val;
|
||||
auto m = app.add_option("-m", val);
|
||||
m->transform([](std::string x) { return x + "1"; });
|
||||
@ -1185,3 +1185,24 @@ TEST_F(TApp, OrderedModifingValidators) {
|
||||
|
||||
EXPECT_EQ(val, std::vector<std::string>({"one12", "two12"}));
|
||||
}
|
||||
|
||||
TEST_F(TApp, ThrowingTransform) {
|
||||
std::string val;
|
||||
auto m = app.add_option("-m,--mess", val);
|
||||
m->transform([](std::string x) -> std::string { throw CLI::ValidationError("My Message"); });
|
||||
|
||||
EXPECT_NO_THROW(run());
|
||||
app.reset();
|
||||
|
||||
args = {"-mone"};
|
||||
|
||||
ASSERT_THROW(run(), CLI::ValidationError);
|
||||
|
||||
app.reset();
|
||||
|
||||
try {
|
||||
run();
|
||||
} catch(const CLI::ValidationError &e) {
|
||||
EXPECT_EQ(e.what(), std::string("--mess: My Message"));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user