mirror of https://github.com/catchorg/Catch2.git
add support for `durations threshold`
This commit is contained in:
parent
1c2fbe146b
commit
487cf9529e
|
@ -40,6 +40,10 @@ namespace Catch {
|
||||||
? ShowDurations::Always
|
? ShowDurations::Always
|
||||||
: ShowDurations::Never;
|
: ShowDurations::Never;
|
||||||
}
|
}
|
||||||
|
inline void setShowDurationsThreshold( ConfigData& config, double _showDurationsThreshold ) {
|
||||||
|
config.showDurations = ShowDurations::Threshold;
|
||||||
|
config.showDurationsThreshold = _showDurationsThreshold;
|
||||||
|
}
|
||||||
inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
|
inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
|
||||||
std::ifstream f( _filename.c_str() );
|
std::ifstream f( _filename.c_str() );
|
||||||
if( !f.is_open() )
|
if( !f.is_open() )
|
||||||
|
@ -142,6 +146,12 @@ namespace Catch {
|
||||||
.longOpt( "durations" )
|
.longOpt( "durations" )
|
||||||
.hint( "yes/no" );
|
.hint( "yes/no" );
|
||||||
|
|
||||||
|
cli.bind( &setShowDurationsThreshold )
|
||||||
|
.describe( "show test durations only if exceeding this threshold" )
|
||||||
|
.shortOpt( "q")
|
||||||
|
.longOpt( "durations-threshold" )
|
||||||
|
.hint( "seconds" );
|
||||||
|
|
||||||
cli.bind( &loadTestNamesFromFile )
|
cli.bind( &loadTestNamesFromFile )
|
||||||
.describe( "load test names to run from a file" )
|
.describe( "load test names to run from a file" )
|
||||||
.shortOpt( "f")
|
.shortOpt( "f")
|
||||||
|
|
|
@ -38,7 +38,8 @@ namespace Catch {
|
||||||
abortAfter( -1 ),
|
abortAfter( -1 ),
|
||||||
verbosity( Verbosity::Normal ),
|
verbosity( Verbosity::Normal ),
|
||||||
warnings( WarnAbout::Nothing ),
|
warnings( WarnAbout::Nothing ),
|
||||||
showDurations( ShowDurations::DefaultForReporter )
|
showDurations( ShowDurations::DefaultForReporter ),
|
||||||
|
showDurationsThreshold( 0.0 )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool listTests;
|
bool listTests;
|
||||||
|
@ -56,6 +57,7 @@ namespace Catch {
|
||||||
Verbosity::Level verbosity;
|
Verbosity::Level verbosity;
|
||||||
WarnAbout::What warnings;
|
WarnAbout::What warnings;
|
||||||
ShowDurations::OrNot showDurations;
|
ShowDurations::OrNot showDurations;
|
||||||
|
double showDurationsThreshold;
|
||||||
|
|
||||||
std::string reporterName;
|
std::string reporterName;
|
||||||
std::string outputFilename;
|
std::string outputFilename;
|
||||||
|
@ -162,7 +164,7 @@ namespace Catch {
|
||||||
virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
|
virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
|
||||||
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
|
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
|
||||||
virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
|
virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
|
||||||
|
virtual double showDurationsThreshold() const { return m_data.showDurationsThreshold; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConfigData m_data;
|
ConfigData m_data;
|
||||||
|
|
|
@ -47,6 +47,8 @@ namespace Catch {
|
||||||
ReconstructedExpression = Yellow,
|
ReconstructedExpression = Yellow,
|
||||||
|
|
||||||
SecondaryText = LightGrey,
|
SecondaryText = LightGrey,
|
||||||
|
DurationText = Yellow,
|
||||||
|
|
||||||
Headers = White
|
Headers = White
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ namespace Catch {
|
||||||
struct ShowDurations { enum OrNot {
|
struct ShowDurations { enum OrNot {
|
||||||
DefaultForReporter,
|
DefaultForReporter,
|
||||||
Always,
|
Always,
|
||||||
Never
|
Never,
|
||||||
|
Threshold
|
||||||
}; };
|
}; };
|
||||||
|
|
||||||
struct IConfig : IShared {
|
struct IConfig : IShared {
|
||||||
|
@ -44,6 +45,7 @@ namespace Catch {
|
||||||
virtual bool warnAboutMissingAssertions() const = 0;
|
virtual bool warnAboutMissingAssertions() const = 0;
|
||||||
virtual int abortAfter() const = 0;
|
virtual int abortAfter() const = 0;
|
||||||
virtual ShowDurations::OrNot showDurations() const = 0;
|
virtual ShowDurations::OrNot showDurations() const = 0;
|
||||||
|
virtual double showDurationsThreshold() const = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,20 +167,18 @@ namespace Catch
|
||||||
struct TestRunStats {
|
struct TestRunStats {
|
||||||
TestRunStats( TestRunInfo const& _runInfo,
|
TestRunStats( TestRunInfo const& _runInfo,
|
||||||
Totals const& _totals,
|
Totals const& _totals,
|
||||||
|
double _durationInSeconds,
|
||||||
bool _aborting )
|
bool _aborting )
|
||||||
: runInfo( _runInfo ),
|
: runInfo( _runInfo ),
|
||||||
totals( _totals ),
|
totals( _totals ),
|
||||||
|
durationInSeconds( _durationInSeconds ),
|
||||||
aborting( _aborting )
|
aborting( _aborting )
|
||||||
{}
|
{}
|
||||||
TestRunStats( TestRunStats const& _other )
|
|
||||||
: runInfo( _other.runInfo ),
|
|
||||||
totals( _other.totals ),
|
|
||||||
aborting( _other.aborting )
|
|
||||||
{}
|
|
||||||
virtual ~TestRunStats();
|
virtual ~TestRunStats();
|
||||||
|
|
||||||
TestRunInfo runInfo;
|
TestRunInfo runInfo;
|
||||||
Totals totals;
|
Totals totals;
|
||||||
|
double durationInSeconds;
|
||||||
bool aborting;
|
bool aborting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -71,10 +71,11 @@ namespace Catch {
|
||||||
m_context.setConfig( m_config );
|
m_context.setConfig( m_config );
|
||||||
m_context.setResultCapture( this );
|
m_context.setResultCapture( this );
|
||||||
m_reporter->testRunStarting( m_runInfo );
|
m_reporter->testRunStarting( m_runInfo );
|
||||||
|
m_timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~RunContext() {
|
virtual ~RunContext() {
|
||||||
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
|
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, m_timer.getElapsedSeconds(), aborting() ) );
|
||||||
m_context.setRunner( m_prevRunner );
|
m_context.setRunner( m_prevRunner );
|
||||||
m_context.setConfig( NULL );
|
m_context.setConfig( NULL );
|
||||||
m_context.setResultCapture( m_prevResultCapture );
|
m_context.setResultCapture( m_prevResultCapture );
|
||||||
|
@ -329,6 +330,8 @@ namespace Catch {
|
||||||
Ptr<IConfig const> m_prevConfig;
|
Ptr<IConfig const> m_prevConfig;
|
||||||
AssertionInfo m_lastAssertionInfo;
|
AssertionInfo m_lastAssertionInfo;
|
||||||
std::vector<UnfinishedSections> m_unfinishedSections;
|
std::vector<UnfinishedSections> m_unfinishedSections;
|
||||||
|
|
||||||
|
Timer m_timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
|
@ -15,6 +15,19 @@
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
static bool shouldPrintDuration(
|
||||||
|
Ptr<IConfig> const& config,
|
||||||
|
double durationInSeconds
|
||||||
|
) {
|
||||||
|
switch( config->showDurations() ) {
|
||||||
|
case ShowDurations::Always: return true;
|
||||||
|
case ShowDurations::Threshold: return (durationInSeconds >= config->showDurationsThreshold());
|
||||||
|
case ShowDurations::DefaultForReporter:
|
||||||
|
case ShowDurations::Never:
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct ConsoleReporter : StreamingReporterBase {
|
struct ConsoleReporter : StreamingReporterBase {
|
||||||
ConsoleReporter( ReporterConfig const& _config )
|
ConsoleReporter( ReporterConfig const& _config )
|
||||||
: StreamingReporterBase( _config ),
|
: StreamingReporterBase( _config ),
|
||||||
|
@ -73,14 +86,19 @@ namespace Catch {
|
||||||
stream << "\nNo assertions in test case";
|
stream << "\nNo assertions in test case";
|
||||||
stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
|
stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( m_headerPrinted ) {
|
if( m_headerPrinted ) {
|
||||||
if( m_config->showDurations() == ShowDurations::Always )
|
if( shouldPrintDuration(m_config, _sectionStats.durationInSeconds) ) {
|
||||||
|
Colour colour( Colour::DurationText );
|
||||||
stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
|
stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
|
||||||
|
}
|
||||||
m_headerPrinted = false;
|
m_headerPrinted = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if( m_config->showDurations() == ShowDurations::Always )
|
if( shouldPrintDuration(m_config, _sectionStats.durationInSeconds) ) {
|
||||||
stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
|
Colour colour( Colour::DurationText );
|
||||||
|
stream << " '" << _sectionStats.sectionInfo.name << "' completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StreamingReporterBase::sectionEnded( _sectionStats );
|
StreamingReporterBase::sectionEnded( _sectionStats );
|
||||||
}
|
}
|
||||||
|
@ -102,7 +120,15 @@ namespace Catch {
|
||||||
if( m_atLeastOneTestCasePrinted )
|
if( m_atLeastOneTestCasePrinted )
|
||||||
printTotalsDivider();
|
printTotalsDivider();
|
||||||
printTotals( _testRunStats.totals );
|
printTotals( _testRunStats.totals );
|
||||||
stream << "\n" << std::endl;
|
stream << "\n";
|
||||||
|
|
||||||
|
if( shouldPrintDuration(m_config, _testRunStats.durationInSeconds) ) {
|
||||||
|
Colour colour( Colour::DurationText );
|
||||||
|
stream << "All test runs completed in " << _testRunStats.durationInSeconds << "s\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
stream << std::endl;
|
||||||
|
|
||||||
StreamingReporterBase::testRunEnded( _testRunStats );
|
StreamingReporterBase::testRunEnded( _testRunStats );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue