mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-03 14:03:52 +00:00
IncorrectConstruction
This commit is contained in:
parent
2af5577b39
commit
58655472f7
@ -154,7 +154,9 @@ public:
|
||||
Option* expected(int value) {
|
||||
if(value == 0)
|
||||
throw IncorrectConstruction("Cannot set 0 expected, use a flag instead");
|
||||
if(!allow_vector_ && value != 1)
|
||||
else if(expected_ == 0)
|
||||
throw IncorrectConstruction("Cannot make a flag take arguments!");
|
||||
else if(!allow_vector_ && value != 1)
|
||||
throw IncorrectConstruction("You can only change the Expected arguments for vectors");
|
||||
expected_ = value;
|
||||
return this;
|
||||
|
@ -74,3 +74,50 @@ TEST_F(TApp, MultipleSubcomNoMatchingInplace2) {
|
||||
EXPECT_NO_THROW(first->ignore_case());
|
||||
EXPECT_NO_THROW(second->ignore_case());
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionFlagPositional1) {
|
||||
EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionFlagPositional2) {
|
||||
int x;
|
||||
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionFlagPositional3) {
|
||||
bool x;
|
||||
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionFlagExpected) {
|
||||
auto cat = app.add_flag("--cat");
|
||||
EXPECT_THROW(cat->expected(1), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionOptionAsFlag) {
|
||||
int x;
|
||||
auto cat = app.add_option("--cat", x);
|
||||
EXPECT_THROW(cat->expected(0), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionOptionAsVector) {
|
||||
int x;
|
||||
auto cat = app.add_option("--cat", x);
|
||||
EXPECT_THROW(cat->expected(2), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionVectorAsFlag) {
|
||||
std::vector<int> x;
|
||||
auto cat = app.add_option("--cat", x);
|
||||
EXPECT_THROW(cat->expected(0), CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionRequiresCannotFind) {
|
||||
auto cat = app.add_flag("--cat");
|
||||
EXPECT_THROW(cat->requires("--nothing"),CLI::IncorrectConstruction);
|
||||
}
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionExcludesCannotFind) {
|
||||
auto cat = app.add_flag("--cat");
|
||||
EXPECT_THROW(cat->excludes("--nothing"),CLI::IncorrectConstruction);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user