4 #include "../conversion/stringbuilder.h" 5 #include "../conversion/stringconversion.h" 7 #include "../application/argumentparser.h" 8 #include "../application/argumentparserprivate.h" 9 #include "../application/commandlineutils.h" 10 #include "../application/failure.h" 11 #include "../application/fakeqtconfigarguments.h" 13 #include "../io/ansiescapecodes.h" 14 #include "../io/path.h" 16 #include "resources/config.h" 18 #include <cppunit/TestFixture.h> 19 #include <cppunit/extensions/HelperMacros.h> 37 CPPUNIT_TEST(testArgument);
38 CPPUNIT_TEST(testParsing);
39 CPPUNIT_TEST(testCallbacks);
40 CPPUNIT_TEST(testBashCompletion);
41 CPPUNIT_TEST(testHelp);
42 CPPUNIT_TEST(testSetMainArguments);
43 CPPUNIT_TEST(testNoColorArgument);
44 CPPUNIT_TEST(testValueConversion);
45 CPPUNIT_TEST_SUITE_END();
54 void testBashCompletion();
56 void testSetMainArguments();
57 void testNoColorArgument();
58 void testValueConversion();
79 Argument argument(
"test",
't',
"some description");
80 CPPUNIT_ASSERT_EQUAL(argument.
isRequired(),
false);
82 CPPUNIT_ASSERT_EQUAL(argument.
isRequired(),
true);
83 Argument subArg(
"sub",
's',
"sub arg");
85 CPPUNIT_ASSERT_EQUAL(subArg.parents().at(0), &argument);
86 CPPUNIT_ASSERT(!subArg.conflictsWithArgument());
89 setenv(
"FOO_ENV_VAR",
"foo",
true);
90 CPPUNIT_ASSERT(!strcmp(argument.
firstValue(),
"foo"));
92 occurrence.
values.emplace_back(
"bar");
93 argument.m_occurrences.emplace_back(move(occurrence));
94 CPPUNIT_ASSERT(!strcmp(argument.
firstValue(),
"bar"));
107 Argument verboseArg(
"verbose",
'v',
"be verbose");
109 Argument fileArg(
"file",
'f',
"specifies the path of the file to be opened");
113 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
116 Argument outputFileArg(
"output-file",
'o',
"specifies the path of the output file");
121 Argument printFieldNamesArg(
"print-field-names",
'\0',
"prints available field names");
122 Argument displayFileInfoArg(
"display-file-info",
'i',
"displays general file information");
123 Argument notAlbumArg(
"album",
'a',
"should not be confused with album value");
125 displayFileInfoArg.
setSubArguments({ &fileArg, &verboseArg, ¬AlbumArg });
126 Argument fieldsArg(
"fields",
'\0',
"specifies the fields");
128 fieldsArg.
setValueNames({
"title",
"album",
"artist",
"trackpos" });
130 Argument displayTagInfoArg(
"get",
'p',
"displays the values of all specified tag fields (displays all fields if none specified)");
132 displayTagInfoArg.
setSubArguments({ &fieldsArg, &filesArg, &verboseArg, ¬AlbumArg });
134 parser.
setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &printFieldNamesArg, &displayTagInfoArg, &displayFileInfoArg, &helpArg, &noColorArg });
143 const char *argv[] = {
"tageditor",
"get",
"album",
"title",
"diskpos",
"-f",
"somefile" };
147 CPPUNIT_FAIL(
"Exception expected.");
149 CPPUNIT_ASSERT_EQUAL(
"The argument \"files\" can not be combined with \"fields\"."s,
string(e.
what()));
153 CPPUNIT_ASSERT_EQUAL(
154 "Error: Unable to parse arguments: The argument \"files\" can not be combined with \"fields\".\nSee --help for available commands.\n"s,
164 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
165 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
166 CPPUNIT_ASSERT(!strcmp(parser.
executable(),
"tageditor"));
168 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
170 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album"));
171 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
172 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
173 CPPUNIT_ASSERT_THROW(displayTagInfoArg.
values().at(3), out_of_range);
177 const char *argv2[] = {
"tageditor",
"",
"-p",
"album",
"title",
"diskpos",
"",
"--files",
"somefile" };
182 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
183 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
185 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
187 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album"));
188 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
189 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
190 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(3),
""));
191 CPPUNIT_ASSERT_THROW(fieldsArg.
values().at(4), out_of_range);
193 CPPUNIT_ASSERT(!strcmp(filesArg.
values().at(0),
"somefile"));
196 const char *argv3[] = {
"tageditor",
"album",
"title",
"diskpos",
"--files",
"somefile" };
200 CPPUNIT_FAIL(
"Exception expected.");
202 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"album\" is unknown.\nDid you mean get or --help?"s,
string(e.
what()));
206 const char *argv18[] = {
"tageditor",
"get",
"album",
"title",
"diskpos",
"--verbose",
"--fi" };
210 CPPUNIT_FAIL(
"Exception expected.");
212 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"--fi\" is unknown.\nDid you mean --files or --no-color?"s,
string(e.
what()));
219 streambuf *regularCerrBuffer = cerr.rdbuf(buffer.rdbuf());
225 cerr.rdbuf(regularCerrBuffer);
228 cerr.rdbuf(regularCerrBuffer);
229 CPPUNIT_ASSERT_EQUAL(
"Warning: The specified argument \"album\" is unknown and will be ignored.\n"s
230 "Warning: The specified argument \"title\" is unknown and will be ignored.\n"s
231 "Warning: The specified argument \"diskpos\" is unknown and will be ignored.\n"s
232 "Warning: The specified argument \"--files\" is unknown and will be ignored.\n"s
233 "Warning: The specified argument \"somefile\" is unknown and will be ignored.\n"s,
236 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
237 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
238 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
243 const char *argv4[] = {
"tageditor",
"-i",
"-vf",
"test" };
247 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
248 CPPUNIT_ASSERT(displayFileInfoArg.
isPresent());
250 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
253 CPPUNIT_ASSERT(!strcmp(fileArg.
values().at(0),
"test"));
254 CPPUNIT_ASSERT_THROW(fileArg.
values().at(1), out_of_range);
260 CPPUNIT_FAIL(
"Exception expected.");
262 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
263 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" mustn't be specified more than 1 time."));
270 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
276 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
279 const char *argv5[] = {
"tageditor",
"-i",
"-f",
"test" };
283 CPPUNIT_FAIL(
"Exception expected.");
285 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
286 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" must be specified at least 1 time."));
291 const char *argv10[] = {
"tageditor",
"-pf",
"test" };
294 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
295 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
298 CPPUNIT_ASSERT_EQUAL(1_st, filesArg.
values(0).size());
299 CPPUNIT_ASSERT(!strcmp(filesArg.
values(0).front(),
"test"));
300 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
303 const char *argv6[] = {
"tageditor",
"-g" };
306 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
309 const char *argv7[] = {
"tageditor",
"-f",
"test" };
313 CPPUNIT_FAIL(
"Exception expected.");
315 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
316 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"-f\" is unknown.\nDid you mean get or --help?"s,
string(e.
what()));
320 const char *argv11[] = {
"tageditor",
"-if=test-v" };
326 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
327 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
328 const char *argv15[] = {
"tageditor",
"-i",
"--file=test",
"-v" };
334 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
335 CPPUNIT_ASSERT_EQUAL(
"test"s,
string(fileArg.
values(0).front()));
338 const char *argv12[] = {
"tageditor",
"-iftest" };
343 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
344 CPPUNIT_ASSERT(!strcmp(fileArg.
values(0).front(),
"test"));
347 const char *argv17[] = {
"tageditor",
"-if=test-v",
"--no-color" };
354 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
355 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
358 const char *argv8[] = {
"tageditor" };
361 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
362 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
364 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
367 if (getenv(
"PATH")) {
369 CPPUNIT_ASSERT(!strcmp(fileArg.
firstValue(), getenv(
"PATH")));
375 const char *argv13[] = {
"tageditor",
"get",
"--fields",
"album=test",
"title",
"diskpos",
"--files",
"somefile" };
380 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
381 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
383 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
385 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
386 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
387 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
388 CPPUNIT_ASSERT_THROW(fieldsArg.
values().at(3), out_of_range);
390 CPPUNIT_ASSERT(!strcmp(filesArg.
values().at(0),
"somefile"));
391 CPPUNIT_ASSERT(!notAlbumArg.
isPresent());
394 const char *argv9[] = {
"tageditor",
"-p",
"album",
"title",
"diskpos" };
399 CPPUNIT_FAIL(
"Exception expected.");
401 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
402 CPPUNIT_ASSERT_EQUAL(
403 "Not all parameter for argument \"fields\" provided. You have to provide the following parameter: title album artist trackpos"s,
408 const char *argv16[] = {
"tageditor",
"--hel",
"-p",
"album",
"title",
"diskpos" };
413 CPPUNIT_FAIL(
"Exception expected.");
415 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
416 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"--hel\" is unknown.\nDid you mean --help or get?"s,
string(e.
what()));
420 const char *argv14[] = {
"tageditor",
"get",
"fields",
"album=test",
"-f",
"somefile" };
424 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
426 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
432 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
434 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"fields"));
435 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"album=test"));
444 Argument callbackArg(
"with-callback",
't',
"callback test");
447 CPPUNIT_ASSERT_EQUAL(0_st, occurrence.
index);
448 CPPUNIT_ASSERT(occurrence.
path.empty());
449 CPPUNIT_ASSERT_EQUAL(2_st, occurrence.
values.size());
450 CPPUNIT_ASSERT(!strcmp(occurrence.
values[0],
"val1"));
451 CPPUNIT_ASSERT(!strcmp(occurrence.
values[1],
"val2"));
454 Argument noCallbackArg(
"no-callback",
'l',
"callback test");
459 const char *argv[] = {
"test",
"-t",
"val1",
"val2" };
463 CPPUNIT_ASSERT_EQUAL(
i, 42);
468 const char *argv2[] = {
"test",
"-l",
"val1",
"val2" };
475 static bool exitCalled =
false;
485 Argument verboseArg(
"verbose",
'v',
"be verbose");
487 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
490 Argument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg");
491 Argument subArg(
"sub",
'\0',
"sub arg");
493 Argument displayFileInfoArg(
"display-file-info",
'i',
"displays general file information");
495 displayFileInfoArg.
setSubArguments({ &filesArg, &verboseArg, &subArg });
496 Argument fieldsArg(
"fields",
'\0',
"specifies the fields");
500 Argument valuesArg(
"values",
'\0',
"specifies the fields");
504 valuesArg.
setValueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::AppendEquationSign);
505 Argument selectorsArg(
"selectors",
'\0',
"has some more pre-defined values");
512 Argument getArg(
"get",
'g',
"gets tag values");
514 Argument setArg(
"set",
's',
"sets tag values");
517 parser.
setMainArguments({ &helpArg, &displayFileInfoArg, &getArg, &setArg });
520 const char *
const argv1[] = {
"se" };
524 CPPUNIT_ASSERT(reader.
read());
525 parser.printBashCompletion(1, argv1, 0, reader);
534 parser.printBashCompletion(1, argv1, 0, reader);
538 const char *
const argv2[] = {
"set" };
543 parser.printBashCompletion(1, argv2, 0, reader);
549 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
551 parser.printBashCompletion(1, argv2, 1, reader);
558 const OutputCheck c(
"COMPREPLY=('files' '--selectors' '--values' )\n");
560 parser.printBashCompletion(1, argv2, 1, reader);
567 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
569 parser.printBashCompletion(0,
nullptr, 0, reader);
573 const char *
const argv3[] = {
"get",
"--fields" };
576 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--files' )\n");
578 parser.printBashCompletion(2, argv3, 2, reader);
582 const char *
const argv4[] = {
"set",
"--values",
"a" };
585 const OutputCheck c(
"COMPREPLY=('album=' 'artist=' ); compopt -o nospace\n");
587 parser.printBashCompletion(3, argv4, 2, reader);
591 const char *
const argv12[] = {
"set",
"--selectors",
"tag=id3" };
594 const OutputCheck c(
"COMPREPLY=('tag=id3v1' 'tag=id3v2' )\n");
596 parser.printBashCompletion(3, argv12, 2, reader);
600 const char *
const argv13[] = {
"set",
"--selectors",
"tag",
"=",
"id3" };
603 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' )\n");
605 parser.printBashCompletion(5, argv13, 4, reader);
609 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' 'matroska' )\n");
611 parser.printBashCompletion(5, argv13, 3, reader);
618 const OutputCheck c(
"COMPREPLY=('matroska' 'mp4' 'vorbis' )\n");
620 parser.printBashCompletion(5, argv13, 3, reader);
626 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--fields' '--files' )\n");
628 parser.printBashCompletion(1, argv3, 2, reader);
633 iniFilePath.resize(iniFilePath.size() - 4);
635 mkvFilePath.resize(mkvFilePath.size() - 17);
637 const char *
const argv5[] = {
"get",
"--files", iniFilePath.c_str() };
640 const OutputCheck c(
"COMPREPLY=('" % mkvFilePath %
" '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath +
".ini' ); compopt -o filenames\n",
641 "COMPREPLY=('" % iniFilePath %
".ini' '" % mkvFilePath +
" '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n");
643 parser.printBashCompletion(3, argv5, 2, reader);
647 const char *
const argv6[] = {
"set",
"--" };
650 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
652 parser.printBashCompletion(2, argv6, 1, reader);
656 const char *
const argv7[] = {
"-i",
"--sub",
"--" };
659 const OutputCheck c(
"COMPREPLY=('--files' '--nested-sub' '--verbose' )\n");
661 parser.printBashCompletion(3, argv7, 2, reader);
665 const char *
const argv8[] = {
"set",
"--values",
"t" };
668 const OutputCheck c(
"COMPREPLY=('title=' 'trackpos=' ); compopt -o nospace\n");
670 parser.printBashCompletion(3, argv8, 2, reader);
674 const char *
const argv9[] = {
"-gf" };
679 parser.printBashCompletion(1, argv9, 0, reader);
683 const OutputCheck c([](
const string &actualOutput) { CPPUNIT_ASSERT_EQUAL(0_st, actualOutput.find(
"COMPREPLY=('--fields' ")); });
685 parser.printBashCompletion(1, argv9, 1, reader);
692 const char *
const argv10[] = {
"/some/path/tageditor",
"--bash-completion-for",
"0" };
695 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
698 CPPUNIT_ASSERT(!strcmp(
"/some/path/tageditor", parser.
executable()));
699 CPPUNIT_ASSERT(exitCalled);
702 const char *
const argv11[] = {
"/some/path/tageditor",
"--bash-completion-for",
"ge" };
718 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(4 + 3), indent.
level);
724 OperationArgument verboseArg(
"verbose",
'v',
"be verbose",
"actually not an operation");
726 ConfigValueArgument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg", {
"value1",
"value2" });
728 Argument subArg(
"foo",
'f',
"dummy");
735 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
739 Argument envArg(
"env",
'\0',
"env");
750 const char *
const argv[] = {
"app",
"-h" };
752 const OutputCheck c(
"\e[1m" APP_NAME
", version " APP_VERSION
"\n" 753 "\e[0mLinked against: somelib, some other lib\n" 755 "Available operations:\n" 756 "\e[1mverbose, -v\e[0m\n" 758 " example: actually not an operation\n" 760 "Available top-level options:\n" 761 "\e[1m--files, -f\e[0m\n" 762 " specifies the path of the file(s) to be opened\n" 765 " particularities: mandatory if parent argument is present\n" 766 " \e[1m--nested-sub\e[0m [value1] [value2] ...\n" 768 " example: sub arg example\n" 770 "\e[1m--env\e[0m [file] [value 2]\n" 772 " default environment variable: FILES\n" 774 "Project website: " APP_URL
"\n");
781 const OutputCheck c(APP_NAME
", version " APP_VERSION
"\n" 782 "Linked against: somelib, some other lib\n" 784 "Available arguments:\n" 787 " example: actually not an operation\n" 790 " specifies the path of the file(s) to be opened\n" 793 " particularities: mandatory if parent argument is present\n" 794 " --nested-sub [value1] [value2] ...\n" 796 " example: sub arg example\n" 798 "--env [file] [value 2]\n" 800 " default environment variable: FILES\n" 802 "Project website: " APP_URL
"\n");
816 Argument subArg(
"sub-arg",
's',
"mandatory sub arg");
821 CPPUNIT_ASSERT_MESSAGE(
"clear main args", parser.
mainArguments().empty());
823 CPPUNIT_ASSERT_MESSAGE(
"no default due to required sub arg", !parser.
defaultArgument());
826 CPPUNIT_ASSERT_MESSAGE(
"default if no required sub arg", &helpArg == parser.
defaultArgument());
838 NoColorArgument::s_instance =
nullptr;
841 unsetenv(
"ENABLE_ESCAPE_CODES");
845 noColorArg.m_occurrences.emplace_back(0);
849 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"s_instance not altered by 2nd instance", &noColorArg, NoColorArgument::s_instance);
852 setenv(
"ENABLE_ESCAPE_CODES",
" 0 ", 1);
857 setenv(
"ENABLE_ESCAPE_CODES",
" 1 ", 1);
865 CPPUNIT_ASSERT_EQUAL_MESSAGE(message,
"foo"s, get<0>(values));
866 CPPUNIT_ASSERT_EQUAL_MESSAGE(message, 42u, get<1>(values));
867 CPPUNIT_ASSERT_EQUAL_MESSAGE(message, 7.5, get<2>(values));
868 CPPUNIT_ASSERT_EQUAL_MESSAGE(message, -42, get<3>(values));
878 occurrence.
values = {
"foo",
"42",
"7.5",
"-42" };
880 static_assert(std::is_same<std::tuple<>, decltype(occurrence.
convertValues<>())>::value,
"specifying no types yields empty tuple");
884 arg.m_occurrences = { occurrence, occurrence };
887 const auto allValues = arg.
allValuesAs<string,
unsigned int, double,
int>();
888 CPPUNIT_ASSERT_EQUAL(2_st, allValues.size());
889 for (
const auto &values : allValues) {
892 static_assert(std::is_same<std::tuple<>, decltype(arg.
valuesAs<>())>::value,
"specifying no types yields empty tuple");
896 occurrence.
convertValues<string,
unsigned int, double, int,
int>();
897 CPPUNIT_FAIL(
"Expected exception");
898 }
catch (
const Failure &failure) {
899 CPPUNIT_ASSERT_EQUAL(
"Expected 5 top-level values to be present but only 4 have been specified."s,
string(failure.
what()));
903 CPPUNIT_FAIL(
"Expected exception");
904 }
catch (
const Failure &failure) {
905 CPPUNIT_ASSERT_EQUAL(
906 "Conversion of top-level value \"foo\" to type \"i\" failed: The character \"f\" is no valid digit."s,
string(failure.
what()));
908 occurrence.
path = { &arg };
910 occurrence.
convertValues<string,
unsigned int, double, int,
int>();
911 CPPUNIT_FAIL(
"Expected exception");
912 }
catch (
const Failure &failure) {
913 CPPUNIT_ASSERT_EQUAL(
"Expected 5 values for argument --test to be present but only 4 have been specified."s,
string(failure.
what()));
917 CPPUNIT_FAIL(
"Expected exception");
918 }
catch (
const Failure &failure) {
919 CPPUNIT_ASSERT_EQUAL(
"Conversion of value \"foo\" (for argument --test) to type \"i\" failed: The character \"f\" is no valid digit."s,
920 string(failure.
what()));
void testNoColorArgument()
Tests whether NocolorArgument toggles escape codes correctly.
void testBashCompletion()
Tests bash completion.
std::tuple< RemainingTargetTypes... > convertValues() const
Converts the present values to the specified target types.
void resetArgs()
Resets all Argument instances assigned as mainArguments() and sub arguments.
#define QT_CONFIG_ARGUMENTS
The ConfigValueArgument class is an Argument where setCombinable() is true by default.
Argument * defaultArgument() const
Returns the default argument.
void setImplicit(bool value)
Sets whether the argument is an implicit argument.
std::size_t index
The index of the occurrence.
void testParsing()
Tests parsing command line arguments.
static void apply()
Sets EscapeCodes::enabled according to the presense of the first instantiation of NoColorArgument...
void checkConvertedValues(const std::string &message, const ValueTuple &values)
void setCombinable(bool value)
Sets whether this argument can be combined.
ValueCompletionBehavior valueCompletionBehaviour() const
Returns the items to be considered when generating completion for the values.
void setUnknownArgumentBehavior(UnknownArgumentBehavior behavior)
Sets how unknown arguments are treated.
void readArgs(int argc, const char *const *argv)
Parses the specified command line arguments.
virtual const char * what() const USE_NOTHROW
Returns a C-style character string describing the cause of the Failure.
Contains currently only ArgumentParser and related classes.
void setMainArguments(const ArgumentInitializerList &mainArguments)
Sets the main arguments for the parser.
void testArgument()
Tests the behaviour of the argument class.
void testSetMainArguments()
Tests some corner cases in setMainArguments() which are not already checked in the other tests...
bool isRequired() const
Returns an indication whether the argument is mandatory.
void testCallbacks()
Tests whether callbacks are called correctly.
void setRequired(bool required)
Sets whether this argument is mandatory or not.
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
void parseArgs(int argc, const char *const *argv)
Parses the specified command line arguments.
const char * firstValue() const
Returns the first parameter value of the first occurrence of the argument.
The Indentation class allows printing indentation conveniently, eg.
The NoColorArgument class allows to specify whether use of escape codes or similar technique to provi...
void addMainArgument(Argument *argument)
Adds the specified argument to the main argument.
The ArgumentParserTests class tests the ArgumentParser and Argument classes.
The OperationArgument class is an Argument where denotesOperation() is true by default.
void setConstraints(std::size_t minOccurrences, std::size_t maxOccurrences)
Sets the allowed number of occurrences.
void testValueConversion()
Tests value conversion provided by Argument and ArgumentOccurrence.
void setAbbreviation(char abbreviation)
Sets the abbreviation of the argument.
Contains classes and functions utilizing creating of test applications.
void setDescription(const char *description)
Sets the description of the argument.
CPP_UTILITIES_EXPORT bool enabled
Controls whether the functions inside the EscapeCodes namespace actually make use of escape codes...
void setValueCompletionBehavior(ValueCompletionBehavior valueCompletionBehaviour)
Sets the items to be considered when generating completion for the values.
#define SET_APPLICATION_INFO
Sets application meta data (including SET_DEPENDENCY_INFO) used by ArgumentParser::printHelp().
void appendValueName(const char *valueName)
Appends a value name.
const std::vector< const char * > & values(std::size_t occurrence=0) const
Returns the parameter values for the specified occurrence of argument.
Contains several functions providing conversions between different data types.
CPP_UTILITIES_EXPORT void(* exitFunction)(int)
Specifies a function quit the application.
const char * executable() const
Returns the name of the current executable.
The Argument class is a wrapper for command line argument information.
void setCallback(CallbackFunction callback)
Sets a callback function which will be called by the parser if the argument could be found and no par...
void setExample(const char *example)
Sets the a usage example for the argument.
void setPreDefinedCompletionValues(const char *preDefinedCompletionValues)
Assignes the values to be used when generating completion for the values.
ApplicationUtilities::ArgumentReader & reset(const char *const *argv, const char *const *end)
Resets the ArgumentReader to continue reading new argv.
std::vector< Argument * > path
The "path" of the occurrence (the parent elements which have been specified before).
The StandardOutputCheck class asserts whether the (standard) output written in the enclosing code blo...
bool read()
Reads the commands line arguments specified when constructing the object.
void addSubArgument(Argument *arg)
Adds arg as a secondary argument for this argument.
void setEnvironmentVariable(const char *environmentVariable)
Sets the environment variable queried when firstValue() is called.
The ArgumentOccurrence struct holds argument values for an occurrence of an argument.
bool isPresent() const
Returns an indication whether the argument could be detected when parsing.
The HelpArgument class prints help information for an argument parser when present (–help...
CPPUNIT_TEST_SUITE_REGISTRATION(ArgumentParserTests)
The Failure class is thrown by an ArgumentParser when a parsing error occurs.
CPP_UTILITIES_EXPORT std::vector< const char * > dependencyVersions2
Specifies the dependency versions the application was linked against (used by ArgumentParser::printHe...
const ArgumentVector & mainArguments() const
Returns the main arguments.
void setDenotesOperation(bool denotesOperation)
Sets whether the argument denotes the operation.
bool isUncombinableMainArgPresent() const
Checks whether at least one uncombinable main argument is present.
void reset()
Resets occurrences (indices, values and paths).
void setRequiredValueCount(std::size_t requiredValueCount)
Sets the number of values which are required to be given for this argument.
The ArgumentReader class internally encapsulates the process of reading command line arguments...
std::tuple< TargetType... > valuesAs(std::size_t occurrence=0) const
Converts the present values for the specified occurrence to the specified target types.
void setSubArguments(const ArgumentInitializerList &subArguments)
Sets the secondary arguments for this arguments.
unsigned int actualArgumentCount() const
Returns the actual number of arguments that could be found when parsing.
void setName(const char *name)
Sets the name of the argument.
std::vector< std::tuple< TargetType... > > allValuesAs() const
Converts the present values for all occurrence to the specified target types.
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &name)
Convenience function which returns the full path of the test file with the specified name...
The ArgumentParser class provides a means for handling command line arguments.
Argument * specifiedOperation() const
Returns the first operation argument specified by the user or nullptr if no operation has been specif...
void testHelp()
Tests –help output.
void setValueNames(std::initializer_list< const char *> valueNames)
Sets the names of the requried values.
std::vector< const char * > values
The parameter values which have been specified after the occurrence of the argument.