added new timing related command line options

2 new timing related command line options have been added:
- performance-timings [-p]: print out performance timings per test case
and group
- performance-timings-threshold [-q <secs>]: print out only the timings
exceeding this given threshold value
This commit is contained in:
Konstantin Baumann 2013-07-23 17:11:43 +02:00
parent 4e7b104f36
commit cdbcd6aa5e
5 changed files with 36 additions and 3 deletions

View File

@ -93,6 +93,17 @@ namespace Catch {
.longOpt( "name" )
.argName( "name" );
cli.bind( &ConfigData::showTimings )
.describe( "print out performance timings per test case and group" )
.shortOpt( "p")
.longOpt( "performance-timings" );
cli.bind( &ConfigData::timingsThreshold )
.describe( "print out only the timings exceeding this given threshold value [in seconds]" )
.shortOpt( "q")
.longOpt( "performance-timings-theshold" )
.argName( "threshold" );
cli.bind( &abortAfterFirst )
.describe( "abort at first failure" )
.shortOpt( "a")

View File

@ -45,6 +45,8 @@ namespace Catch {
shouldDebugBreak( false ),
noThrow( false ),
showHelp( false ),
showTimings( false ),
timingsThreshold( 0.0 ),
abortAfter( -1 ),
verbosity( Verbosity::Normal ),
warnings( WarnAbout::Nothing )
@ -59,6 +61,9 @@ namespace Catch {
bool noThrow;
bool showHelp;
bool showTimings;
double timingsThreshold;
int abortAfter;
Verbosity::Level verbosity;
@ -167,7 +172,8 @@ namespace Catch {
virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & ConfigData::WarnAbout::NoAssertions; }
virtual bool showTimings() const { return m_data.showTimings; }
virtual double timingsThreshold() const { return m_data.timingsThreshold; }
private:
ConfigData m_data;

View File

@ -25,6 +25,8 @@ namespace Catch {
virtual bool includeSuccessfulResults() const = 0;
virtual bool shouldDebugBreak() const = 0;
virtual bool warnAboutMissingAssertions() const = 0;
virtual bool showTimings() const = 0;
virtual double timingsThreshold() const = 0;
virtual int abortAfter() const = 0;
};
}

View File

@ -74,6 +74,12 @@ namespace Catch {
Colour colour( Colour::ResultError );
stream << "\nNo assertions in test case, '" << _testCaseStats.testInfo.name << "'\n" << std::endl;
}
if( m_config->showTimings() && (_testCaseStats.timeSecs >= m_config->timingsThreshold()) ) {
Colour colour( Colour::SecondaryText );
stream << "Time spent in test case '" << _testCaseStats.testInfo.name << "': [timing: " << _testCaseStats.timeSecs << " secs]." << std::endl;
}
StreamingReporterBase::testCaseEnded( _testCaseStats );
m_headerPrinted = false;
}
@ -84,13 +90,21 @@ namespace Catch {
printTotals( _testGroupStats.totals );
stream << "\n" << std::endl;
}
if( m_config->showTimings() && (_testGroupStats.timeSecs >= m_config->timingsThreshold()) ) {
Colour colour( Colour::SecondaryText );
stream << "Time spent in test group '" << _testGroupStats.groupInfo.name << "': [timing: " << _testGroupStats.timeSecs << " secs]." << std::endl;
}
StreamingReporterBase::testGroupEnded( _testGroupStats );
}
virtual void testRunEnded( TestRunStats const& _testRunStats ) {
if( m_atLeastOneTestCasePrinted )
printTotalsDivider();
printTotals( _testRunStats.totals );
stream << " [timing: " << _testRunStats.timeSecs << " secs.]";
if( m_config->showTimings() ) {
stream << " [timing: " << _testRunStats.timeSecs << " secs.]";
}
stream << "\n" << std::endl;
StreamingReporterBase::testRunEnded( _testRunStats );
}

View File

@ -44,7 +44,7 @@ namespace Catch {
private:
static void OutputTestSuites( XmlWriter& xml, AccumTestRunStats const& stats ) {
xml.startElement( "testsuites" );
xml.writeAttribute( "name", stats.testRun.runInfo.name );
xml.writeAttribute( "time", stats.testRun.timeSecs );
std::vector<AccumTestGroupStats>::const_iterator it = stats.testGroups.begin();