Skip to content

Commit

Permalink
Add test for help printing of global argument under command.
Browse files Browse the repository at this point in the history
  • Loading branch information
igormironchik committed Jun 28, 2021
1 parent 65b4713 commit cedaa5e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/auto/help/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,3 +1321,41 @@ TEST_CASE( "TestHelpWithWrongCommand2" )

REQUIRE( false );
}

TEST_CASE( "TestHelpWithGlobalArgUnderCommand" )
{
const int argc = 4;
const CHAR * argv[ argc ] = { SL( "program.exe" ),
SL( "-h" ), SL( "add" ), SL( "-f" ) };

CmdLine cmd( argc, argv );

cmd.addCommand( SL( "add" ), ValueOptions::NoValue, true , SL( "Add item to..." ) )
.end()
.addArgWithFlagOnly( 'f', false, false, "File object." )
.addHelp( true, SL( "program.exe" ), SL( "Help with commands." ) );

try {
cmd.parse();
}
catch( const HelpHasBeenPrintedException & )
{
#ifdef ARGS_QSTRING_BUILD
REQUIRE( g_string ==
"USAGE: [ -f ] \n\n"
" File object. \n\n" );

g_string.clear();
#else
REQUIRE( g_argsOutStream.str() == SL(
"USAGE: [ -f ] \n\n"
" File object. \n\n" ) );

g_argsOutStream.str( SL( "" ) );
#endif

return;
}

REQUIRE( false );
}

0 comments on commit cedaa5e

Please sign in to comment.