mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-29 16:53:30 +01:00
Added help option
This commit is contained in:
parent
c60156ad11
commit
27fdf01b76
@ -36,6 +36,27 @@ namespace Catch
|
|||||||
return std::numeric_limits<int>::max();
|
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
|
// Handle list request
|
||||||
if( config.listWhat() != RunnerConfig::listNone )
|
if( config.listWhat() != RunnerConfig::listNone )
|
||||||
return List( config );
|
return List( config );
|
||||||
|
@ -19,10 +19,10 @@
|
|||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
// -l, --list tests [xml] lists available tests (optionally in xml)
|
// -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)
|
// -l, --list all [xml] lists available tests and reports (optionally in xml)
|
||||||
// -t, --test "testspec" ["testspec", ...]
|
// -t, --test "testspec" ["testspec", ...]
|
||||||
// -r, --report <type>
|
// -r, --reporter <type>
|
||||||
// -o, --out filename to write to
|
// -o, --out filename to write to
|
||||||
// -s, --success report successful cases too
|
// -s, --success report successful cases too
|
||||||
// -b, --break breaks into debugger on test failure
|
// -b, --break breaks into debugger on test failure
|
||||||
@ -37,6 +37,7 @@ namespace Catch
|
|||||||
modeOutput,
|
modeOutput,
|
||||||
modeSuccess,
|
modeSuccess,
|
||||||
modeBreak,
|
modeBreak,
|
||||||
|
modeHelp,
|
||||||
|
|
||||||
modeError
|
modeError
|
||||||
};
|
};
|
||||||
@ -55,7 +56,7 @@ namespace Catch
|
|||||||
changeMode( cmd, modeList );
|
changeMode( cmd, modeList );
|
||||||
else if( cmd == "-t" || cmd == "--test" )
|
else if( cmd == "-t" || cmd == "--test" )
|
||||||
changeMode( cmd, modeTest );
|
changeMode( cmd, modeTest );
|
||||||
else if( cmd == "-r" || cmd == "--report" )
|
else if( cmd == "-r" || cmd == "--reporter" )
|
||||||
changeMode( cmd, modeReport );
|
changeMode( cmd, modeReport );
|
||||||
else if( cmd == "-o" || cmd == "--out" )
|
else if( cmd == "-o" || cmd == "--out" )
|
||||||
changeMode( cmd, modeOutput );
|
changeMode( cmd, modeOutput );
|
||||||
@ -63,6 +64,8 @@ namespace Catch
|
|||||||
changeMode( cmd, modeSuccess );
|
changeMode( cmd, modeSuccess );
|
||||||
else if( cmd == "-b" || cmd == "--break" )
|
else if( cmd == "-b" || cmd == "--break" )
|
||||||
changeMode( cmd, modeBreak );
|
changeMode( cmd, modeBreak );
|
||||||
|
else if( cmd == "-h" || cmd == "-?" || cmd == "--help" )
|
||||||
|
changeMode( cmd, modeHelp );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -157,6 +160,11 @@ namespace Catch
|
|||||||
return setErrorMode( m_command + " does not accept arguments" );
|
return setErrorMode( m_command + " does not accept arguments" );
|
||||||
m_config.setShouldDebugBreak( true );
|
m_config.setShouldDebugBreak( true );
|
||||||
break;
|
break;
|
||||||
|
case modeHelp:
|
||||||
|
if( m_args.size() != 0 )
|
||||||
|
return setErrorMode( m_command + " does not accept arguments" );
|
||||||
|
m_config.setShowHelp( true );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,8 @@ namespace Catch
|
|||||||
RunnerConfig()
|
RunnerConfig()
|
||||||
: m_reporter( NULL ),
|
: m_reporter( NULL ),
|
||||||
m_listSpec( listNone ),
|
m_listSpec( listNone ),
|
||||||
m_shouldDebugBreak( false )
|
m_shouldDebugBreak( false ),
|
||||||
|
m_showHelp( false )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void setReporterInfo( const std::string& reporterName )
|
void setReporterInfo( const std::string& reporterName )
|
||||||
@ -122,6 +123,15 @@ namespace Catch
|
|||||||
{
|
{
|
||||||
return m_shouldDebugBreak;
|
return m_shouldDebugBreak;
|
||||||
}
|
}
|
||||||
|
void setShowHelp( bool showHelp )
|
||||||
|
{
|
||||||
|
m_showHelp = showHelp;
|
||||||
|
}
|
||||||
|
bool showHelp() const
|
||||||
|
{
|
||||||
|
return m_showHelp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::auto_ptr<ITestReporter> m_reporter;
|
std::auto_ptr<ITestReporter> m_reporter;
|
||||||
std::string m_filename;
|
std::string m_filename;
|
||||||
@ -130,6 +140,7 @@ namespace Catch
|
|||||||
ListInfo m_listSpec;
|
ListInfo m_listSpec;
|
||||||
std::vector<std::string> m_testSpecs;
|
std::vector<std::string> m_testSpecs;
|
||||||
bool m_shouldDebugBreak;
|
bool m_shouldDebugBreak;
|
||||||
|
bool m_showHelp;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
Loading…
Reference in New Issue
Block a user