diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index 16c23e4f..285c9409 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -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") diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 184649ef..32a54c3c 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -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; diff --git a/include/internal/catch_interfaces_config.h b/include/internal/catch_interfaces_config.h index 87ee35b4..f9cda931 100644 --- a/include/internal/catch_interfaces_config.h +++ b/include/internal/catch_interfaces_config.h @@ -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; }; } diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp index fb88620a..30ec6cc8 100644 --- a/include/reporters/catch_reporter_console.hpp +++ b/include/reporters/catch_reporter_console.hpp @@ -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 ); } diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp index 4b79de09..031927cc 100644 --- a/include/reporters/catch_reporter_junit.hpp +++ b/include/reporters/catch_reporter_junit.hpp @@ -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::const_iterator it = stats.testGroups.begin();