Allow name to be provided for overall test run

This commit is contained in:
Phil Nash 2011-04-12 08:07:39 +01:00
parent 0bc42c5659
commit b3db552cfa
5 changed files with 32 additions and 2 deletions

View File

@ -266,7 +266,10 @@ namespace Catch
{ {
if( !m_testingSpan.emitted ) if( !m_testingSpan.emitted )
{ {
m_config.stream() << "[Started testing]" << std::endl; if( m_config.getName().empty() )
m_config.stream() << "[Started testing]" << std::endl;
else
m_config.stream() << "[Started testing: " << m_config.getName() << "]" << std::endl;
m_testingSpan.emitted = true; m_testingSpan.emitted = true;
} }

View File

@ -46,6 +46,8 @@ namespace Catch
{ {
m_xml = XmlWriter( m_config.stream() ); m_xml = XmlWriter( m_config.stream() );
m_xml.startElement( "Catch" ); m_xml.startElement( "Catch" );
if( !m_config.getName().empty() )
m_xml.writeAttribute( "name", m_config.getName() );
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@ -30,6 +30,7 @@ namespace Catch
// -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
// -n, --name specifies an optional name for the test run
class ArgParser : NonCopyable class ArgParser : NonCopyable
{ {
enum Mode enum Mode
@ -41,6 +42,7 @@ namespace Catch
modeOutput, modeOutput,
modeSuccess, modeSuccess,
modeBreak, modeBreak,
modeName,
modeHelp, modeHelp,
modeError modeError
@ -74,6 +76,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 == "-n" || cmd == "--name" )
changeMode( cmd, modeName );
else if( cmd == "-h" || cmd == "-?" || cmd == "--help" ) else if( cmd == "-h" || cmd == "-?" || cmd == "--help" )
changeMode( cmd, modeHelp ); changeMode( cmd, modeHelp );
} }
@ -179,6 +183,10 @@ namespace Catch
if( m_args.size() != 0 ) if( m_args.size() != 0 )
return setErrorMode( m_command + " does not accept arguments" ); return setErrorMode( m_command + " does not accept arguments" );
m_config.setShouldDebugBreak( true ); m_config.setShouldDebugBreak( true );
case modeName:
if( m_args.size() != 1 )
return setErrorMode( m_command + " requires exactly one argument (a name)" );
m_config.setName( m_args[0] );
break; break;
case modeHelp: case modeHelp:
if( m_args.size() != 0 ) if( m_args.size() != 0 )

View File

@ -171,6 +171,18 @@ namespace Catch
m_shouldDebugBreak = shouldDebugBreakFlag; m_shouldDebugBreak = shouldDebugBreakFlag;
} }
///////////////////////////////////////////////////////////////////////////
void setName( const std::string& name )
{
m_name = name;
}
///////////////////////////////////////////////////////////////////////////
std::string getName() const
{
return m_name;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
bool shouldDebugBreak() const bool shouldDebugBreak() const
{ {
@ -228,7 +240,9 @@ namespace Catch
bool m_showHelp; bool m_showHelp;
std::streambuf* m_streambuf; std::streambuf* m_streambuf;
mutable std::ostream m_os; mutable std::ostream m_os;
Include::What m_includeWhat; Include::What m_includeWhat;
std::string m_name;
}; };
} // end namespace Catch } // end namespace Catch

View File

@ -33,6 +33,9 @@ namespace Catch
virtual bool includeSuccessfulResults virtual bool includeSuccessfulResults
() const = 0; () const = 0;
virtual std::string getName
() const = 0;
}; };
class TestCaseInfo; class TestCaseInfo;