@@ -124,6 +124,15 @@ void CppCommandLineTest::boundValue()
124124 QCOMPARE (option.boundValue <std::string>(), &boundValue);
125125 }
126126
127+ {
128+ SCENARIO (" Option bound value with default value" )
129+ std::string boundValue;
130+ cppcommandline::Option option = std::move (cppcommandline::Option ().withDefaultValue (std::string (" filename" )));
131+ option.bindTo (boundValue);
132+ QCOMPARE (option.boundValue <std::string>(), &boundValue);
133+ QCOMPARE (boundValue, std::string (" filename" ));
134+ }
135+
127136 {
128137 SCENARIO (" Option bound value with differently typed default value is not possible" )
129138 std::string boundValue;
@@ -351,7 +360,38 @@ void CppCommandLineTest::parse()
351360
352361void CppCommandLineTest::parseFailed ()
353362{
363+ {
364+ SCENARIO (" Unmatched argument" )
365+ std::vector<const char *> args{" -v" };
366+ QVERIFY_EXCEPTION_THROWN (cppcommandline::Parser ().parse (static_cast <int >(args.size ()), const_cast <char **>(args.data ())), std::logic_error);
367+ }
368+
369+ {
370+ SCENARIO (" Unmatched required option" )
371+ std::vector<const char *> args{" -v" };
372+ cppcommandline::Parser parser;
373+ parser.option (" longName" ).asShortName (" v" );
374+ parser.option ().required ();
375+ QVERIFY_EXCEPTION_THROWN (parser.parse (static_cast <int >(args.size ()), const_cast <char **>(args.data ())), std::logic_error);
376+ }
377+
378+ {
379+ SCENARIO (" Type mismatch" )
380+ std::vector<const char *> args{" -v=hello" };
381+ cppcommandline::Parser parser;
382+ int value = 0 ;
383+ parser.option (" value" ).asShortName (" v" ).bindTo (value);
384+ QVERIFY_EXCEPTION_THROWN (parser.parse (static_cast <int >(args.size ()), const_cast <char **>(args.data ())), std::logic_error);
385+ }
354386
387+ {
388+ SCENARIO (" Missing value" )
389+ std::vector<const char *> args{" -v" };
390+ cppcommandline::Parser parser;
391+ int value = 0 ;
392+ parser.option (" value" ).asShortName (" v" ).bindTo (value);
393+ QVERIFY_EXCEPTION_THROWN (parser.parse (static_cast <int >(args.size ()), const_cast <char **>(args.data ())), std::logic_error);
394+ }
355395}
356396
357397QTEST_APPLESS_MAIN (CppCommandLineTest)
0 commit comments