test/cli_argument_parser: add a test for dealing with "empty" command lines
parent
8835b90398
commit
db6e543c5c
|
@ -152,6 +152,37 @@ int main(int argc, char* argv[]) {
|
||||||
delete[] validTestParameterList;
|
delete[] validTestParameterList;
|
||||||
std::cout << "Passed valid input test." << std::endl;
|
std::cout << "Passed valid input test." << std::endl;
|
||||||
|
|
||||||
|
// empty input (valid and invalid) #################################
|
||||||
|
std::vector<CLI::Flag> emptyTestFlags;
|
||||||
|
|
||||||
|
std::vector<CLI::UnpositionalArgument> emptyTestUnpositionalArguments;
|
||||||
|
|
||||||
|
std::vector<CLI::PositionalArgument> emptyTestPositionalArguments;
|
||||||
|
|
||||||
|
const char** emptyTestParameterList = new const char*[1];
|
||||||
|
// The command is always a part of a command line, even if it is empty
|
||||||
|
// otherwise. Therefore, I think it is reasonable to assume that it
|
||||||
|
// will always be available.
|
||||||
|
emptyTestParameterList[0] = "test";
|
||||||
|
int emptyTestParameterCount = 1;
|
||||||
|
|
||||||
|
// valid
|
||||||
|
CLI::ArgumentsParser validEmptyTestParameterParser = CLI::ArgumentsParser(emptyTestParameterCount, emptyTestParameterList, emptyTestFlags, emptyTestUnpositionalArguments, emptyTestPositionalArguments);
|
||||||
|
ASSERT(!validEmptyTestParameterParser.wrongUsage);
|
||||||
|
ASSERT(validEmptyTestParameterParser.programName == std::string("test"));
|
||||||
|
|
||||||
|
//invalid
|
||||||
|
emptyTestPositionalArguments.push_back(CLI::PositionalArgument("argument", "positional argument"));
|
||||||
|
|
||||||
|
CLI::ArgumentsParser invalidEmptyTestParameterParser = CLI::ArgumentsParser(emptyTestParameterCount, emptyTestParameterList, emptyTestFlags, emptyTestUnpositionalArguments, emptyTestPositionalArguments);
|
||||||
|
ASSERT(invalidEmptyTestParameterParser.wrongUsage);
|
||||||
|
ASSERT(invalidEmptyTestParameterParser.programName == std::string("test"));
|
||||||
|
ASSERT(invalidEmptyTestParameterParser.getPositionalArgument(0).isError);
|
||||||
|
ASSERT(invalidEmptyTestParameterParser.getPositionalArgument(0).errorCode == ErrorCodes::NOT_PRESENT);
|
||||||
|
|
||||||
|
delete[] emptyTestParameterList;
|
||||||
|
std::cout << "Passed empty input test." << std::endl;
|
||||||
|
|
||||||
//TODO add tests for invalid input
|
//TODO add tests for invalid input
|
||||||
std::cerr << "TODO: invalid input tests" << std::endl;
|
std::cerr << "TODO: invalid input tests" << std::endl;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue