Compare commits

...

4 Commits

Author SHA1 Message Date
BodgeMaster a51c65c9f2 test/javacompat: get rid of a compiler warning 2022-07-20 19:22:06 +02:00
BodgeMaster 8bb0732cc6 Build system: add single-threaded compile mode to test script 2022-07-20 19:20:27 +02:00
BodgeMaster 0dcc579bb5 test/cli_arguments_parser: extend some tests, implement all remaining parser tests except checking for error messages 2022-07-20 19:16:02 +02:00
BodgeMaster db3b133f88 lib/cli: fix trailing incomplete unpositional arguments
The parser used to rely on the next iteration of the loop to detect
if an unpositional argument was missing its value, this has now been
fixed by adding an additional check on unpositional arguments waiting
for a value that detects if the end of the loop has been reached
2022-07-20 18:30:25 +02:00
4 changed files with 347 additions and 16 deletions

View File

@ -15,6 +15,13 @@
# version 3 along with this program.
# If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
if [ "$(tr '[:upper:]' '[:lower:]' <<< $SINGLE)" = "yes" ]; then
echo "Building tests in single-threaded mode."
WAIT_ANYWAY="wait"
else
WAIT_ANYWAY=""
fi
if [ -z "$CXX" ]; then
CXX="c++"
fi
@ -44,6 +51,7 @@ COMPILE_COMMANDS=(
for command in ${!COMPILE_COMMANDS[@]}; do
echo "${COMPILE_COMMANDS[command]}"
${COMPILE_COMMANDS[command]} &
$WAIT_ANYWAY
done
wait

View File

@ -107,6 +107,10 @@ namespace CLI {
// unpositional argument
argumentsByLongName[argumentName]->present = true;
argumentWaitingForValue = argumentsByLongName[argumentName];
if (i+1 == argc) {
this->wrongUsage = true;
this->wrongUsageMessages.push_back(std::string("Argument expects value but has none: ")+argumentName);
}
} else {
this->wrongUsage = true;
this->wrongUsageMessages.push_back(std::string("Unknown argument or flag: ")+argument);
@ -129,23 +133,27 @@ namespace CLI {
// length is defined as
// (std::__cxx11::basic_string<char>::size_type ?)
// starting at 1 because 0 is '-'
for (int i=1; i<(int) argument.length(); i++) {
for (int j=1; j<(int) argument.length(); j++) {
//is argument or flag?
if (flagsByShortName.contains(argument[i])) {
flagsByShortName[argument[i]]->present = true;
} else if (argumentsByShortName.contains(argument[i])) {
argumentsByShortName[argument[i]]->present = true;
if (flagsByShortName.contains(argument[j])) {
flagsByShortName[argument[j]]->present = true;
} else if (argumentsByShortName.contains(argument[j])) {
argumentsByShortName[argument[j]]->present = true;
//FIXME: see above
if (i+1==(int) argument.length()) {
argumentWaitingForValue = argumentsByShortName[argument[i]];
if (j+1==(int) argument.length()) {
argumentWaitingForValue = argumentsByShortName[argument[j]];
if (i+1 == argc) {
this->wrongUsage = true;
this->wrongUsageMessages.push_back(std::string("Argument expects value but has none: ")+argument.substr(j, 1));
}
} else {
//assume the rest of the argv is a concatenated argument value
argumentsByShortName[argument[i]]->value = argument.substr(i+1, argument.length()-i-1);
argumentsByShortName[argument[j]]->value = argument.substr(j+1, argument.length()-j-1);
break;
}
} else {
this->wrongUsage = true;
this->wrongUsageMessages.push_back(std::string("Unknown argument or flag(s): ")+argument.substr(i, argument.length()-i));
this->wrongUsageMessages.push_back(std::string("Unknown argument or flag(s): ")+argument.substr(j, argument.length()-j));
// err on the side of caution to ensure that
// no unwanted options get activated on programs
// that deal gracefully with unrecognized command

View File

@ -226,6 +226,48 @@ int main(int argc, char* argv[]) {
ASSERT(unknownFlagMixedTestParser.getFlag(std::string("four")).value);
delete[] unknownFlagTestParameterList;
std::vector<CLI::Flag> unknownLongFlagTestFlags;
unknownLongFlagTestFlags.push_back(CLI::Flag('0', "zero", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('1', "one", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('2', "two", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('3', "three","test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('4', "four", "test flag"));
unknownLongFlagTestFlags.push_back(CLI::Flag('5', "five", "test flag"));
std::vector<CLI::UnpositionalArgument> unknownLongFlagTestUnpositionalArguments;
std::vector<CLI::PositionalArgument> unknownLongFlagTestPositionalArguments;
const char** unknownLongFlagTestParameterList = new const char*[7];
unknownLongFlagTestParameterList[0] = "test";
unknownLongFlagTestParameterList[1] = "--a";
unknownLongFlagTestParameterList[2] = "-1";
unknownLongFlagTestParameterList[3] = "-2";
unknownLongFlagTestParameterList[4] = "-3";
unknownLongFlagTestParameterList[5] = "-4";
unknownLongFlagTestParameterList[6] = "-5";
int unknownLongFlagStandaloneTestParameterCount = 2;
CLI::ArgumentsParser unknownLongFlagStandaloneTestParser = CLI::ArgumentsParser(unknownLongFlagStandaloneTestParameterCount, unknownLongFlagTestParameterList, unknownLongFlagTestFlags, unknownLongFlagTestUnpositionalArguments, unknownLongFlagTestPositionalArguments);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag('1').isError);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag('1').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(!unknownLongFlagStandaloneTestParser.getFlag('1').value);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).isError);
ASSERT(unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(!unknownLongFlagStandaloneTestParser.getFlag(std::string("four")).value);
int unknownLongFlagMixedTestParameterCount = 7;
CLI::ArgumentsParser unknownLongFlagMixedTestParser = CLI::ArgumentsParser(unknownLongFlagMixedTestParameterCount, unknownLongFlagTestParameterList, unknownLongFlagTestFlags, unknownLongFlagTestUnpositionalArguments, unknownLongFlagTestPositionalArguments);
ASSERT(unknownLongFlagMixedTestParser.getFlag('1').isError);
ASSERT(unknownLongFlagMixedTestParser.getFlag('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongFlagMixedTestParser.getFlag('1').value);
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).isError);
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongFlagMixedTestParser.getFlag(std::string("four")).value);
delete[] unknownLongFlagTestParameterList;
std::cout << "Passed unknown flag test." << std::endl;
// unknown unpositional argument ###################################
@ -233,12 +275,12 @@ int main(int argc, char* argv[]) {
std::vector<CLI::Flag> unknownArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> unknownArgumentTestUnpositionalArguments;
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test flag"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test flag"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test flag"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test flag"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test flag"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test flag"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
unknownArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> unknownArgumentTestPositionalArguments;
@ -271,7 +313,280 @@ int main(int argc, char* argv[]) {
ASSERT(unknownArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "d");
delete[] unknownArgumentTestParameterList;
std::vector<CLI::Flag> unknownLongArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> unknownLongArgumentTestUnpositionalArguments;
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
unknownLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> unknownLongArgumentTestPositionalArguments;
const char** unknownLongArgumentTestParameterList = new const char*[7];
unknownLongArgumentTestParameterList[0] = "test";
unknownLongArgumentTestParameterList[1] = "--a=123";
unknownLongArgumentTestParameterList[2] = "-1a";
unknownLongArgumentTestParameterList[3] = "-2b";
unknownLongArgumentTestParameterList[4] = "-3c";
unknownLongArgumentTestParameterList[5] = "-4d";
unknownLongArgumentTestParameterList[6] = "-5e";
int unknownLongArgumentStandaloneTestParameterCount = 2;
CLI::ArgumentsParser unknownLongArgumentStandaloneTestParser = CLI::ArgumentsParser(unknownLongArgumentStandaloneTestParameterCount, unknownLongArgumentTestParameterList, unknownLongArgumentTestFlags, unknownLongArgumentTestUnpositionalArguments, unknownLongArgumentTestPositionalArguments);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument('1').isError);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument('1').value == "");
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(unknownLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
int unknownLongArgumentMixedTestParameterCount = 7;
CLI::ArgumentsParser unknownLongArgumentMixedTestParser = CLI::ArgumentsParser(unknownLongArgumentMixedTestParameterCount, unknownLongArgumentTestParameterList, unknownLongArgumentTestFlags, unknownLongArgumentTestUnpositionalArguments, unknownLongArgumentTestPositionalArguments);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument('1').isError);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument('1').value == "a");
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(unknownLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "d");
delete[] unknownLongArgumentTestParameterList;
std::cout << "Passed unknown unpositional argument test." << std::endl;
// incomplete unpositional argument ###################################
std::vector<CLI::Flag> incompleteArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> incompleteArgumentTestUnpositionalArguments;
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
incompleteArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> incompleteArgumentTestPositionalArguments;
const char** incompleteArgumentTestParameterList = new const char*[6];
incompleteArgumentTestParameterList[0] = "test";
incompleteArgumentTestParameterList[1] = "-1";
incompleteArgumentTestParameterList[2] = "-2b";
incompleteArgumentTestParameterList[3] = "-3c";
incompleteArgumentTestParameterList[4] = "-4";
incompleteArgumentTestParameterList[5] = "-5e";
int incompleteArgumentStandaloneTestParameterCount = 2;
CLI::ArgumentsParser incompleteArgumentStandaloneTestParser = CLI::ArgumentsParser(incompleteArgumentStandaloneTestParameterCount, incompleteArgumentTestParameterList, incompleteArgumentTestFlags, incompleteArgumentTestUnpositionalArguments, incompleteArgumentTestPositionalArguments);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(incompleteArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
int incompleteArgumentMixedTestParameterCount = 6;
CLI::ArgumentsParser incompleteArgumentMixedTestParser = CLI::ArgumentsParser(incompleteArgumentMixedTestParameterCount, incompleteArgumentTestParameterList, incompleteArgumentTestFlags, incompleteArgumentTestUnpositionalArguments, incompleteArgumentTestPositionalArguments);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "");
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').isError);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteArgumentMixedTestParser.getUnpositionalArgument('5').value == "e");
delete[] incompleteArgumentTestParameterList;
std::vector<CLI::Flag> incompleteLongArgumentTestFlags;
std::vector<CLI::UnpositionalArgument> incompleteLongArgumentTestUnpositionalArguments;
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('0', "zero", "zero", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('1', "one", "one", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('2', "two", "two", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('3', "three","three","test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('4', "four", "four", "test argument"));
incompleteLongArgumentTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('5', "five", "five", "test argument"));
std::vector<CLI::PositionalArgument> incompleteLongArgumentTestPositionalArguments;
const char** incompleteLongArgumentTestParameterList = new const char*[8];
incompleteLongArgumentTestParameterList[0] = "test";
incompleteLongArgumentTestParameterList[1] = "--one";
incompleteLongArgumentTestParameterList[2] = "--two";
incompleteLongArgumentTestParameterList[3] = "b";
incompleteLongArgumentTestParameterList[4] = "-3c";
incompleteLongArgumentTestParameterList[5] = "positional_arg";
incompleteLongArgumentTestParameterList[6] = "--four";
incompleteLongArgumentTestParameterList[7] = "--five=e";
int incompleteLongArgumentStandaloneTestParameterCount = 2;
CLI::ArgumentsParser incompleteLongArgumentStandaloneTestParser = CLI::ArgumentsParser(incompleteLongArgumentStandaloneTestParameterCount, incompleteLongArgumentTestParameterList, incompleteLongArgumentTestFlags, incompleteLongArgumentTestUnpositionalArguments, incompleteLongArgumentTestPositionalArguments);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(incompleteLongArgumentStandaloneTestParser.getUnpositionalArgument(std::string("four")).value == "");
int incompleteLongArgumentMixedTestParameterCount = 8;
CLI::ArgumentsParser incompleteLongArgumentMixedTestParser = CLI::ArgumentsParser(incompleteLongArgumentMixedTestParameterCount, incompleteLongArgumentTestParameterList, incompleteLongArgumentTestFlags, incompleteLongArgumentTestUnpositionalArguments, incompleteLongArgumentTestPositionalArguments);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('1').isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('1').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('1').value == "");
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('2').isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('2').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('2').value == "b");
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument(std::string("four")).value == "");
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').isError);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(incompleteLongArgumentMixedTestParser.getUnpositionalArgument('5').value == "e");
delete[] incompleteLongArgumentTestParameterList;
std::cout << "Passed incomplete unpositional argument test." << std::endl;
// too few positional arguments
std::vector<CLI::Flag> tooFewArgumentsTestFlags;
tooFewArgumentsTestFlags.push_back(CLI::Flag('a', "aaaaa", "test flag"));
std::vector<CLI::UnpositionalArgument> tooFewArgumentsTestUnpositionalArguments;
tooFewArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('b', "bbbbb", "b", "test argument"));
tooFewArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('c', "ccccc", "c", "test argument"));
tooFewArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('d', "ddddd", "d", "test argument"));
std::vector<CLI::PositionalArgument> tooFewArgumentsTestPositionalArguments;
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument0", "test argument"));
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument1", "test argument"));
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument2", "test argument"));
tooFewArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument3", "test argument"));
const char** tooFewArgumentsTestParameterList = new const char*[10];
tooFewArgumentsTestParameterList[0] = "test";
tooFewArgumentsTestParameterList[1] = "positional_arg_0";
tooFewArgumentsTestParameterList[2] = "-a";//
tooFewArgumentsTestParameterList[3] = "-b";
tooFewArgumentsTestParameterList[4] = "1";
tooFewArgumentsTestParameterList[5] = "-c5";
tooFewArgumentsTestParameterList[6] = "positional_arg_1";
tooFewArgumentsTestParameterList[7] = "--ddddd";
tooFewArgumentsTestParameterList[8] = "ddd";
tooFewArgumentsTestParameterList[9] = "positional_arg_2";
int tooFewArgumentsStandaloneTestParameterCount = 2;
CLI::ArgumentsParser tooFewArgumentsStandaloneTestParser = CLI::ArgumentsParser(tooFewArgumentsStandaloneTestParameterCount, tooFewArgumentsTestParameterList, tooFewArgumentsTestFlags, tooFewArgumentsTestUnpositionalArguments, tooFewArgumentsTestPositionalArguments);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(0).isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(1).isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(1).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getPositionalArgument(1).value == "");
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('b').value == "");
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('c').value == "");
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsStandaloneTestParser.getUnpositionalArgument('d').value == "");
int tooFewArgumentsMixedTestParameterCount = 10;
CLI::ArgumentsParser tooFewArgumentsMixedTestParser = CLI::ArgumentsParser(tooFewArgumentsMixedTestParameterCount, tooFewArgumentsTestParameterList, tooFewArgumentsTestFlags, tooFewArgumentsTestUnpositionalArguments, tooFewArgumentsTestPositionalArguments);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(0).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(1).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(1).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(1).value == "positional_arg_1");
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(2).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(2).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(2).value == "positional_arg_2");
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).isError);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooFewArgumentsMixedTestParser.getPositionalArgument(3).value == "");
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('b').value == "1");
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('c').value == "5");
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooFewArgumentsMixedTestParser.getUnpositionalArgument('d').value == "ddd");
delete[] tooFewArgumentsTestParameterList;
std::cout << "Passed too few positional arguments test." << std::endl;
// too many positional arguments
std::vector<CLI::Flag> tooManyArgumentsTestFlags;
tooManyArgumentsTestFlags.push_back(CLI::Flag('a', "aaaaa", "test flag"));
std::vector<CLI::UnpositionalArgument> tooManyArgumentsTestUnpositionalArguments;
tooManyArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('b', "bbbbb", "b", "test argument"));
tooManyArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('c', "ccccc", "c", "test argument"));
tooManyArgumentsTestUnpositionalArguments.push_back(CLI::UnpositionalArgument('d', "ddddd", "d", "test argument"));
std::vector<CLI::PositionalArgument> tooManyArgumentsTestPositionalArguments;
tooManyArgumentsTestPositionalArguments.push_back(CLI::PositionalArgument("argument0", "test argument"));
const char** tooManyArgumentsTestParameterList = new const char*[10];
tooManyArgumentsTestParameterList[0] = "test";
tooManyArgumentsTestParameterList[1] = "positional_arg_0";
tooManyArgumentsTestParameterList[2] = "positional_arg_1";
tooManyArgumentsTestParameterList[3] = "-a";//
tooManyArgumentsTestParameterList[4] = "-b";
tooManyArgumentsTestParameterList[5] = "1";
tooManyArgumentsTestParameterList[6] = "-c5";
tooManyArgumentsTestParameterList[7] = "--ddddd";
tooManyArgumentsTestParameterList[8] = "ddd";
tooManyArgumentsTestParameterList[9] = "positional_arg_2";
int tooManyArgumentsStandaloneTestParameterCount = 3;
CLI::ArgumentsParser tooManyArgumentsStandaloneTestParser = CLI::ArgumentsParser(tooManyArgumentsStandaloneTestParameterCount, tooManyArgumentsTestParameterList, tooManyArgumentsTestFlags, tooManyArgumentsTestUnpositionalArguments, tooManyArgumentsTestPositionalArguments);
ASSERT(tooManyArgumentsStandaloneTestParser.getPositionalArgument(0).isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsStandaloneTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('b').value == "");
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('c').value == "");
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::NOT_PRESENT);
ASSERT(tooManyArgumentsStandaloneTestParser.getUnpositionalArgument('d').value == "");
int tooManyArgumentsMixedTestParameterCount = 10;
CLI::ArgumentsParser tooManyArgumentsMixedTestParser = CLI::ArgumentsParser(tooManyArgumentsMixedTestParameterCount, tooManyArgumentsTestParameterList, tooManyArgumentsTestFlags, tooManyArgumentsTestUnpositionalArguments, tooManyArgumentsTestPositionalArguments);
ASSERT(tooManyArgumentsMixedTestParser.getPositionalArgument(0).isError);
ASSERT(tooManyArgumentsMixedTestParser.getPositionalArgument(0).errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getPositionalArgument(0).value == "positional_arg_0");
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('b').isError);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('b').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('b').value == "1");
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('c').isError);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('c').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('c').value == "5");
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').isError);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').errorCode == ErrorCodes::WRONG_USAGE);
ASSERT(tooManyArgumentsMixedTestParser.getUnpositionalArgument('d').value == "ddd");
delete[] tooManyArgumentsTestParameterList;
std::cout << "Passed too many positional arguments test." << std::endl;
return 0;
}

View File

@ -87,7 +87,7 @@ int main(){
std::vector<uint8_t> data = JavaCompat::exportJavaString(normalString).value;
std::string exportedString = std::string();
for(int i=0; i<data.size(); i++){
for(int i=0; i<(int) data.size(); i++){
exportedString.push_back(data[i]);
}