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> 24 #ifdef PLATFORM_WINDOWS 35 using namespace CPPUNIT_NS;
42 CPPUNIT_TEST(testArgument);
43 CPPUNIT_TEST(testParsing);
44 CPPUNIT_TEST(testCallbacks);
45 CPPUNIT_TEST(testSetMainArguments);
46 CPPUNIT_TEST(testValueConversion);
47 #ifndef PLATFORM_WINDOWS 48 CPPUNIT_TEST(testBashCompletion);
49 CPPUNIT_TEST(testHelp);
50 CPPUNIT_TEST(testNoColorArgument);
52 CPPUNIT_TEST_SUITE_END();
61 void testSetMainArguments();
62 void testValueConversion();
63 #ifndef PLATFORM_WINDOWS 64 void testBashCompletion();
66 void testNoColorArgument();
77 #ifndef PLATFORM_WINDOWS 78 setenv(
"ENABLE_ESCAPE_CODES",
"0", 1);
92 Argument argument(
"test",
't',
"some description");
93 CPPUNIT_ASSERT_EQUAL(
false, argument.
isRequired());
95 CPPUNIT_ASSERT_EQUAL(
true, argument.
isRequired());
96 Argument subArg(
"sub",
's',
"sub arg");
98 CPPUNIT_ASSERT_EQUAL(&argument, subArg.
parents().at(0));
99 CPPUNIT_ASSERT(!subArg.conflictsWithArgument());
102 #ifndef PLATFORM_WINDOWS // disabled under Windows for same reason as testNoColorArgument() 103 setenv(
"FOO_ENV_VAR",
"foo", 1);
104 CPPUNIT_ASSERT_EQUAL(
"foo"s,
string(argument.
firstValue()));
107 occurrence.
values.emplace_back(
"bar");
108 argument.m_occurrences.emplace_back(move(occurrence));
109 CPPUNIT_ASSERT_EQUAL(
"bar"s,
string(argument.
firstValue()));
122 Argument verboseArg(
"verbose",
'v',
"be verbose");
124 Argument fileArg(
"file",
'f',
"specifies the path of the file to be opened");
128 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
131 Argument outputFileArg(
"output-file",
'o',
"specifies the path of the output file");
136 Argument printFieldNamesArg(
"print-field-names",
'\0',
"prints available field names");
137 Argument displayFileInfoArg(
"display-file-info",
'i',
"displays general file information");
138 Argument notAlbumArg(
"album",
'a',
"should not be confused with album value");
140 displayFileInfoArg.
setSubArguments({ &fileArg, &verboseArg, ¬AlbumArg });
141 Argument fieldsArg(
"fields",
'\0',
"specifies the fields");
143 fieldsArg.
setValueNames({
"title",
"album",
"artist",
"trackpos" });
145 Argument displayTagInfoArg(
"get",
'p',
"displays the values of all specified tag fields (displays all fields if none specified)");
147 displayTagInfoArg.
setSubArguments({ &fieldsArg, &filesArg, &verboseArg, ¬AlbumArg });
149 parser.
setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &printFieldNamesArg, &displayTagInfoArg, &displayFileInfoArg, &helpArg, &noColorArg });
158 const char *argv[] = {
"tageditor",
"get",
"album",
"title",
"diskpos",
"-f",
"somefile" };
162 CPPUNIT_FAIL(
"Exception expected.");
164 CPPUNIT_ASSERT_EQUAL(
"The argument \"files\" can not be combined with \"fields\"."s,
string(e.
what()));
168 CPPUNIT_ASSERT_EQUAL(
169 "Error: Unable to parse arguments: The argument \"files\" can not be combined with \"fields\".\nSee --help for available commands.\n"s,
179 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
180 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
181 CPPUNIT_ASSERT(!strcmp(parser.
executable(),
"tageditor"));
183 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
185 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album"));
186 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
187 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
188 CPPUNIT_ASSERT_THROW(displayTagInfoArg.
values().at(3), out_of_range);
192 const char *argv2[] = {
"tageditor",
"",
"-p",
"album",
"title",
"diskpos",
"",
"--files",
"somefile" };
197 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
198 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
200 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
202 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album"));
203 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
204 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
205 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(3),
""));
206 CPPUNIT_ASSERT_THROW(fieldsArg.
values().at(4), out_of_range);
208 CPPUNIT_ASSERT(!strcmp(filesArg.
values().at(0),
"somefile"));
211 const char *argv3[] = {
"tageditor",
"album",
"title",
"diskpos",
"--files",
"somefile" };
215 CPPUNIT_FAIL(
"Exception expected.");
217 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"album\" is unknown.\nDid you mean get or --help?"s,
string(e.
what()));
221 const char *argv18[] = {
"tageditor",
"get",
"album",
"title",
"diskpos",
"--verbose",
"--fi" };
225 CPPUNIT_FAIL(
"Exception expected.");
227 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"--fi\" is unknown.\nDid you mean --files or --no-color?"s,
string(e.
what()));
233 #ifndef PLATFORM_WINDOWS 234 const OutputCheck outputCheck(
"Warning: The specified argument \"album\" is unknown and will be ignored.\n"s
235 "Warning: The specified argument \"title\" is unknown and will be ignored.\n"s
236 "Warning: The specified argument \"diskpos\" is unknown and will be ignored.\n"s
237 "Warning: The specified argument \"--files\" is unknown and will be ignored.\n"s
238 "Warning: The specified argument \"somefile\" is unknown and will be ignored.\n"s,
246 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
247 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
248 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
254 const char *argv4[] = {
"tageditor",
"-i",
"-vf",
"test" };
258 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
259 CPPUNIT_ASSERT(displayFileInfoArg.
isPresent());
261 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
264 CPPUNIT_ASSERT(!strcmp(fileArg.
values().at(0),
"test"));
265 CPPUNIT_ASSERT_THROW(fileArg.
values().at(1), out_of_range);
271 CPPUNIT_FAIL(
"Exception expected.");
273 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
274 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" mustn't be specified more than 1 time."));
281 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
287 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
290 const char *argv5[] = {
"tageditor",
"-i",
"-f",
"test" };
294 CPPUNIT_FAIL(
"Exception expected.");
296 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
297 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" must be specified at least 1 time."));
302 const char *argv10[] = {
"tageditor",
"-pf",
"test" };
305 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
306 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
309 CPPUNIT_ASSERT_EQUAL(1_st, filesArg.
values(0).size());
310 CPPUNIT_ASSERT(!strcmp(filesArg.
values(0).front(),
"test"));
311 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
314 const char *argv6[] = {
"tageditor",
"-g" };
317 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
320 const char *argv7[] = {
"tageditor",
"-f",
"test" };
324 CPPUNIT_FAIL(
"Exception expected.");
326 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
327 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"-f\" is unknown.\nDid you mean get or --help?"s,
string(e.
what()));
331 const char *argv11[] = {
"tageditor",
"-if=test-v" };
337 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
338 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
339 const char *argv15[] = {
"tageditor",
"-i",
"--file=test",
"-v" };
345 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
346 CPPUNIT_ASSERT_EQUAL(
"test"s,
string(fileArg.
values(0).front()));
349 const char *argv12[] = {
"tageditor",
"-iftest" };
354 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
355 CPPUNIT_ASSERT(!strcmp(fileArg.
values(0).front(),
"test"));
358 const char *argv17[] = {
"tageditor",
"-if=test-v",
"--no-color" };
365 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
366 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
369 const char *argv8[] = {
"tageditor" };
372 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
373 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
375 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
378 if (getenv(
"PATH")) {
380 CPPUNIT_ASSERT(!strcmp(fileArg.
firstValue(), getenv(
"PATH")));
386 const char *argv13[] = {
"tageditor",
"get",
"--fields",
"album=test",
"title",
"diskpos",
"--files",
"somefile" };
391 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
392 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
394 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
396 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
397 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
398 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
399 CPPUNIT_ASSERT_THROW(fieldsArg.
values().at(3), out_of_range);
401 CPPUNIT_ASSERT(!strcmp(filesArg.
values().at(0),
"somefile"));
402 CPPUNIT_ASSERT(!notAlbumArg.
isPresent());
405 const char *argv9[] = {
"tageditor",
"-p",
"album",
"title",
"diskpos" };
410 CPPUNIT_FAIL(
"Exception expected.");
412 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
413 CPPUNIT_ASSERT_EQUAL(
414 "Not all parameter for argument \"fields\" provided. You have to provide the following parameter: title album artist trackpos"s,
419 const char *argv16[] = {
"tageditor",
"--hel",
"-p",
"album",
"title",
"diskpos" };
424 CPPUNIT_FAIL(
"Exception expected.");
426 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
427 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"--hel\" is unknown.\nDid you mean --help or get?"s,
string(e.
what()));
431 const char *argv14[] = {
"tageditor",
"get",
"fields",
"album=test",
"-f",
"somefile" };
435 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
437 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
443 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
445 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"fields"));
446 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"album=test"));
455 Argument callbackArg(
"with-callback",
't',
"callback test");
458 CPPUNIT_ASSERT_EQUAL(0_st, occurrence.
index);
459 CPPUNIT_ASSERT(occurrence.
path.empty());
460 CPPUNIT_ASSERT_EQUAL(2_st, occurrence.
values.size());
461 CPPUNIT_ASSERT(!strcmp(occurrence.
values[0],
"val1"));
462 CPPUNIT_ASSERT(!strcmp(occurrence.
values[1],
"val2"));
465 Argument noCallbackArg(
"no-callback",
'l',
"callback test");
470 const char *argv[] = {
"test",
"-t",
"val1",
"val2" };
474 CPPUNIT_ASSERT_EQUAL(
i, 42);
479 const char *argv2[] = {
"test",
"-l",
"val1",
"val2" };
483 #ifndef PLATFORM_WINDOWS 487 static bool exitCalled =
false;
499 Argument verboseArg(
"verbose",
'v',
"be verbose");
501 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
504 Argument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg");
505 Argument subArg(
"sub",
'\0',
"sub arg");
507 Argument displayFileInfoArg(
"display-file-info",
'i',
"displays general file information");
509 displayFileInfoArg.
setSubArguments({ &filesArg, &verboseArg, &subArg });
510 Argument fieldsArg(
"fields",
'\0',
"specifies the fields");
514 Argument valuesArg(
"values",
'\0',
"specifies the fields");
518 valuesArg.
setValueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::AppendEquationSign);
519 Argument selectorsArg(
"selectors",
'\0',
"has some more pre-defined values");
526 Argument getArg(
"get",
'g',
"gets tag values");
528 Argument setArg(
"set",
's',
"sets tag values");
531 parser.
setMainArguments({ &helpArg, &displayFileInfoArg, &getArg, &setArg });
534 const char *
const argv1[] = {
"se" };
538 CPPUNIT_ASSERT(reader.
read());
539 parser.printBashCompletion(1, argv1, 0, reader);
548 parser.printBashCompletion(1, argv1, 0, reader);
552 const char *
const argv2[] = {
"set" };
557 parser.printBashCompletion(1, argv2, 0, reader);
563 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
565 parser.printBashCompletion(1, argv2, 1, reader);
572 const OutputCheck c(
"COMPREPLY=('files' '--selectors' '--values' )\n");
574 parser.printBashCompletion(1, argv2, 1, reader);
581 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
583 parser.printBashCompletion(0,
nullptr, 0, reader);
587 const char *
const argv3[] = {
"get",
"--fields" };
590 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--files' )\n");
592 parser.printBashCompletion(2, argv3, 2, reader);
596 const char *
const argv4[] = {
"set",
"--values",
"a" };
599 const OutputCheck c(
"COMPREPLY=('album=' 'artist=' ); compopt -o nospace\n");
601 parser.printBashCompletion(3, argv4, 2, reader);
605 const char *
const argv12[] = {
"set",
"--selectors",
"tag=id3" };
608 const OutputCheck c(
"COMPREPLY=('tag=id3v1' 'tag=id3v2' )\n");
610 parser.printBashCompletion(3, argv12, 2, reader);
614 const char *
const argv13[] = {
"set",
"--selectors",
"tag",
"=",
"id3" };
617 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' )\n");
619 parser.printBashCompletion(5, argv13, 4, reader);
623 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' 'matroska' )\n");
625 parser.printBashCompletion(5, argv13, 3, reader);
632 const OutputCheck c(
"COMPREPLY=('matroska' 'mp4' 'vorbis' )\n");
634 parser.printBashCompletion(5, argv13, 3, reader);
640 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--fields' '--files' )\n");
642 parser.printBashCompletion(1, argv3, 2, reader);
647 iniFilePath.resize(iniFilePath.size() - 4);
649 mkvFilePath.resize(mkvFilePath.size() - 17);
651 const char *
const argv5[] = {
"get",
"--files", iniFilePath.c_str() };
654 const OutputCheck c(
"COMPREPLY=('" % mkvFilePath %
" '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath +
".ini' ); compopt -o filenames\n",
655 "COMPREPLY=('" % iniFilePath %
".ini' '" % mkvFilePath +
" '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n");
657 parser.printBashCompletion(3, argv5, 2, reader);
661 const char *
const argv6[] = {
"set",
"--" };
664 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
666 parser.printBashCompletion(2, argv6, 1, reader);
670 const char *
const argv7[] = {
"-i",
"--sub",
"--" };
673 const OutputCheck c(
"COMPREPLY=('--files' '--nested-sub' '--verbose' )\n");
675 parser.printBashCompletion(3, argv7, 2, reader);
679 const char *
const argv8[] = {
"set",
"--values",
"t" };
682 const OutputCheck c(
"COMPREPLY=('title=' 'trackpos=' ); compopt -o nospace\n");
684 parser.printBashCompletion(3, argv8, 2, reader);
688 const char *
const argv9[] = {
"-gf" };
693 parser.printBashCompletion(1, argv9, 0, reader);
697 const OutputCheck c([](
const string &actualOutput) { CPPUNIT_ASSERT_EQUAL(0_st, actualOutput.find(
"COMPREPLY=('--fields' ")); });
699 parser.printBashCompletion(1, argv9, 1, reader);
706 const char *
const argv10[] = {
"/some/path/tageditor",
"--bash-completion-for",
"0" };
709 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
712 CPPUNIT_ASSERT(!strcmp(
"/some/path/tageditor", parser.
executable()));
713 CPPUNIT_ASSERT(exitCalled);
716 const char *
const argv11[] = {
"/some/path/tageditor",
"--bash-completion-for",
"ge" };
725 #ifndef PLATFORM_WINDOWS 735 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(4 + 3), indent.
level);
741 OperationArgument verboseArg(
"verbose",
'v',
"be verbose",
"actually not an operation");
743 ConfigValueArgument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg", {
"value1",
"value2" });
745 Argument subArg(
"foo",
'f',
"dummy");
752 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
756 Argument envArg(
"env",
'\0',
"env");
767 const char *
const argv[] = {
"app",
"-h" };
769 const OutputCheck c(
"\e[1m" APP_NAME
", version " APP_VERSION
"\n" 770 "\e[0mLinked against: somelib, some other lib\n" 772 "Available operations:\n" 773 "\e[1mverbose, -v\e[0m\n" 775 " example: actually not an operation\n" 777 "Available top-level options:\n" 778 "\e[1m--files, -f\e[0m\n" 779 " specifies the path of the file(s) to be opened\n" 782 " particularities: mandatory if parent argument is present\n" 783 " \e[1m--nested-sub\e[0m [value1] [value2] ...\n" 785 " example: sub arg example\n" 787 "\e[1m--env\e[0m [file] [value 2]\n" 789 " default environment variable: FILES\n" 791 "Project website: " APP_URL
"\n");
798 const OutputCheck c(APP_NAME
", version " APP_VERSION
"\n" 799 "Linked against: somelib, some other lib\n" 801 "Available arguments:\n" 804 " example: actually not an operation\n" 807 " specifies the path of the file(s) to be opened\n" 810 " particularities: mandatory if parent argument is present\n" 811 " --nested-sub [value1] [value2] ...\n" 813 " example: sub arg example\n" 815 "--env [file] [value 2]\n" 817 " default environment variable: FILES\n" 819 "Project website: " APP_URL
"\n");
834 Argument subArg(
"sub-arg",
's',
"mandatory sub arg");
839 CPPUNIT_ASSERT_MESSAGE(
"clear main args", parser.
mainArguments().empty());
841 CPPUNIT_ASSERT_MESSAGE(
"no default due to required sub arg", !parser.
defaultArgument());
844 CPPUNIT_ASSERT_MESSAGE(
"default if no required sub arg", &helpArg == parser.
defaultArgument());
847 #ifndef PLATFORM_WINDOWS 861 NoColorArgument::s_instance =
nullptr;
864 unsetenv(
"ENABLE_ESCAPE_CODES");
868 noColorArg.m_occurrences.emplace_back(0);
872 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"s_instance not altered by 2nd instance", &noColorArg, NoColorArgument::s_instance);
875 setenv(
"ENABLE_ESCAPE_CODES",
" 0 ", 1);
880 setenv(
"ENABLE_ESCAPE_CODES",
" 1 ", 1);
889 CPPUNIT_ASSERT_EQUAL_MESSAGE(message,
"foo"s, get<0>(values));
890 CPPUNIT_ASSERT_EQUAL_MESSAGE(message, 42u, get<1>(values));
891 CPPUNIT_ASSERT_EQUAL_MESSAGE(message, 7.5, get<2>(values));
892 CPPUNIT_ASSERT_EQUAL_MESSAGE(message, -42, get<3>(values));
902 occurrence.
values = {
"foo",
"42",
"7.5",
"-42" };
904 static_assert(std::is_same<std::tuple<>, decltype(occurrence.
convertValues<>())>::value,
"specifying no types yields empty tuple");
908 arg.m_occurrences = { occurrence, occurrence };
911 const auto allValues = arg.
allValuesAs<string,
unsigned int, double,
int>();
912 CPPUNIT_ASSERT_EQUAL(2_st, allValues.size());
913 for (
const auto &values : allValues) {
916 static_assert(std::is_same<std::tuple<>, decltype(arg.
valuesAs<>())>::value,
"specifying no types yields empty tuple");
920 occurrence.
convertValues<string,
unsigned int, double, int,
int>();
921 CPPUNIT_FAIL(
"Expected exception");
922 }
catch (
const Failure &failure) {
923 CPPUNIT_ASSERT_EQUAL(
"Expected 5 top-level values to be present but only 4 have been specified."s,
string(failure.
what()));
927 CPPUNIT_FAIL(
"Expected exception");
928 }
catch (
const Failure &failure) {
929 CPPUNIT_ASSERT_EQUAL(
930 "Conversion of top-level value \"foo\" to type \"i\" failed: The character \"f\" is no valid digit."s,
string(failure.
what()));
932 occurrence.
path = { &arg };
934 occurrence.
convertValues<string,
unsigned int, double, int,
int>();
935 CPPUNIT_FAIL(
"Expected exception");
936 }
catch (
const Failure &failure) {
937 CPPUNIT_ASSERT_EQUAL(
"Expected 5 values for argument --test to be present but only 4 have been specified."s,
string(failure.
what()));
941 CPPUNIT_FAIL(
"Expected exception");
942 }
catch (
const Failure &failure) {
943 CPPUNIT_ASSERT_EQUAL(
"Conversion of value \"foo\" (for argument --test) to type \"i\" failed: The character \"f\" is no valid digit."s,
944 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.
const ArgumentVector parents() const
Returns the parents of this argument.
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.
Contains utility classes helping to read and write streams.
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.
void setValueNames(std::initializer_list< const char * > valueNames)
Sets the names of the requried values.
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.
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.
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &relativeTestFilePath)
Convenience function to invoke TestApplication::testFilePath().
std::vector< const char * > values
The parameter values which have been specified after the occurrence of the argument.