mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-01 13:13:53 +00:00
Adding tests and shorter Error defs
This commit is contained in:
parent
4b0f6dbfd6
commit
a20efe069c
@ -62,52 +62,42 @@ struct Combiner {
|
||||
|
||||
namespace CLI {
|
||||
|
||||
class Error : public std::runtime_error {
|
||||
public:
|
||||
struct Error : public std::runtime_error {
|
||||
Error(std::string parent, std::string name) : runtime_error(parent + ": " + name) {}
|
||||
};
|
||||
|
||||
class BadNameString : public Error {
|
||||
public:
|
||||
struct BadNameString : public Error {
|
||||
BadNameString(std::string name) : Error("BadNameString", name) {}
|
||||
};
|
||||
|
||||
class CallForHelp : public Error {
|
||||
public:
|
||||
struct CallForHelp : public Error {
|
||||
CallForHelp() : Error("CallForHelp","") {}
|
||||
};
|
||||
|
||||
class ParseError : public Error {
|
||||
public:
|
||||
struct ParseError : public Error {
|
||||
ParseError(std::string name) : Error("ParseError", name) {}
|
||||
};
|
||||
|
||||
class OptionAlreadyAdded : public Error {
|
||||
public:
|
||||
struct OptionAlreadyAdded : public Error {
|
||||
OptionAlreadyAdded(std::string name) : Error("OptionAlreadyAdded", name) {}
|
||||
};
|
||||
|
||||
class OptionNotFound : public Error {
|
||||
public:
|
||||
struct OptionNotFound : public Error {
|
||||
OptionNotFound(std::string name) : Error("OptionNotFound", name) {}
|
||||
};
|
||||
|
||||
class RequiredError : public Error {
|
||||
public:
|
||||
struct RequiredError : public Error {
|
||||
RequiredError(std::string name) : Error("RequiredError", name) {}
|
||||
};
|
||||
|
||||
class ExtraPositionalsError : public Error {
|
||||
public:
|
||||
struct ExtraPositionalsError : public Error {
|
||||
ExtraPositionalsError(std::string name) : Error("ExtraPositionalsError", name) {}
|
||||
};
|
||||
|
||||
class HorribleError : public Error {
|
||||
public:
|
||||
struct HorribleError : public Error {
|
||||
HorribleError(std::string name) : Error("HorribleError", "(You should never see this error) " + name) {}
|
||||
};
|
||||
class IncorrectConstruction : public Error {
|
||||
public:
|
||||
struct IncorrectConstruction : public Error {
|
||||
IncorrectConstruction(std::string name) : Error("IncorrectConstruction", name) {}
|
||||
};
|
||||
|
||||
|
@ -170,10 +170,8 @@ TEST_F(TApp, Reset) {
|
||||
|
||||
}
|
||||
|
||||
struct TSubcom : public TApp {
|
||||
};
|
||||
|
||||
TEST_F(TSubcom, Basic) {
|
||||
TEST_F(TApp, Basic) {
|
||||
auto sub1 = app.add_subcommand("sub1");
|
||||
auto sub2 = app.add_subcommand("sub2");
|
||||
|
||||
@ -192,3 +190,55 @@ TEST_F(TSubcom, Basic) {
|
||||
run();
|
||||
EXPECT_EQ(sub2, app.get_subcommand());
|
||||
}
|
||||
|
||||
|
||||
struct SubcommandProgram : public TApp {
|
||||
|
||||
CLI::App* start;
|
||||
CLI::App* stop;
|
||||
|
||||
int dummy;
|
||||
std::string file;
|
||||
int count;
|
||||
|
||||
SubcommandProgram() {
|
||||
start = app.add_subcommand("start", "Start prog");
|
||||
stop = app.add_subcommand("stop", "Stop prog");
|
||||
|
||||
app.add_flag("d", dummy, "My dummy var");
|
||||
start->add_option("f,file", file, "File name");
|
||||
stop->add_flag("c,count", count, "Some flag opt");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(SubcommandProgram, Working) {
|
||||
args = {"-d", "start", "-ffilename"};
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(1, dummy);
|
||||
EXPECT_EQ(start, app.get_subcommand());
|
||||
EXPECT_EQ("filename", file);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(SubcommandProgram, Spare) {
|
||||
args = {"extra", "-d", "start", "-ffilename"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ExtraPositionalsError);
|
||||
}
|
||||
|
||||
TEST_F(SubcommandProgram, SpareSub) {
|
||||
args = {"-d", "start", "spare", "-ffilename"};
|
||||
|
||||
EXPECT_THROW(run(), CLI::ExtraPositionalsError);
|
||||
}
|
||||
|
||||
// TODO: Add positionals
|
||||
// TODO: Add vector arguments
|
||||
// TODO: Maybe add function to call on subcommand parse?
|
||||
// TODO: Check help output
|
||||
// TODO: Add default/type info to help
|
||||
// TODO: Add set checking
|
||||
// TODO: Try all of the options together
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user