Added help option

This commit is contained in:
Phil Nash 2010-12-30 18:51:02 +00:00
parent c60156ad11
commit 27fdf01b76
3 changed files with 45 additions and 5 deletions

View File

@ -36,6 +36,27 @@ namespace Catch
return std::numeric_limits<int>::max();
}
// Handle help
if( config.showHelp() )
{
std::string exeName( argv[0] );
std::string::size_type pos = exeName.find_last_of( "/\\" );
if( pos != std::string::npos )
{
exeName = exeName.substr( pos+1 );
}
std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n"
<< "\t-l, --list <tests | reporters> [xml]\n"
<< "\t-t, --test <testspec> [<testspec>...]\n"
<< "\t-r, --reporter <reporter name>\n"
<< "\t-o, --out <file name>\n"
<< "\t-s, --success\n"
<< "\t-b, --break\n\n"
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
return 0;
}
// Handle list request
if( config.listWhat() != RunnerConfig::listNone )
return List( config );

View File

@ -19,10 +19,10 @@
namespace Catch
{
// -l, --list tests [xml] lists available tests (optionally in xml)
// -l, --list reports [xml] lists available reports (optionally in xml)
// -l, --list reporters [xml] lists available reports (optionally in xml)
// -l, --list all [xml] lists available tests and reports (optionally in xml)
// -t, --test "testspec" ["testspec", ...]
// -r, --report <type>
// -r, --reporter <type>
// -o, --out filename to write to
// -s, --success report successful cases too
// -b, --break breaks into debugger on test failure
@ -37,6 +37,7 @@ namespace Catch
modeOutput,
modeSuccess,
modeBreak,
modeHelp,
modeError
};
@ -55,7 +56,7 @@ namespace Catch
changeMode( cmd, modeList );
else if( cmd == "-t" || cmd == "--test" )
changeMode( cmd, modeTest );
else if( cmd == "-r" || cmd == "--report" )
else if( cmd == "-r" || cmd == "--reporter" )
changeMode( cmd, modeReport );
else if( cmd == "-o" || cmd == "--out" )
changeMode( cmd, modeOutput );
@ -63,6 +64,8 @@ namespace Catch
changeMode( cmd, modeSuccess );
else if( cmd == "-b" || cmd == "--break" )
changeMode( cmd, modeBreak );
else if( cmd == "-h" || cmd == "-?" || cmd == "--help" )
changeMode( cmd, modeHelp );
}
else
{
@ -157,7 +160,12 @@ namespace Catch
return setErrorMode( m_command + " does not accept arguments" );
m_config.setShouldDebugBreak( true );
break;
default:
case modeHelp:
if( m_args.size() != 0 )
return setErrorMode( m_command + " does not accept arguments" );
m_config.setShowHelp( true );
break;
default:
break;
}
m_args.clear();

View File

@ -45,7 +45,8 @@ namespace Catch
RunnerConfig()
: m_reporter( NULL ),
m_listSpec( listNone ),
m_shouldDebugBreak( false )
m_shouldDebugBreak( false ),
m_showHelp( false )
{}
void setReporterInfo( const std::string& reporterName )
@ -122,6 +123,15 @@ namespace Catch
{
return m_shouldDebugBreak;
}
void setShowHelp( bool showHelp )
{
m_showHelp = showHelp;
}
bool showHelp() const
{
return m_showHelp;
}
std::auto_ptr<ITestReporter> m_reporter;
std::string m_filename;
@ -130,6 +140,7 @@ namespace Catch
ListInfo m_listSpec;
std::vector<std::string> m_testSpecs;
bool m_shouldDebugBreak;
bool m_showHelp;
};
} // end namespace Catch