mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Added duration reporting to compact reporter
Also made the duration formatting code available to all reporters. Closes #780
This commit is contained in:
parent
95b0eb2b6c
commit
40f6a5b8a4
@ -11,10 +11,32 @@
|
|||||||
#include "../internal/catch_interfaces_reporter.h"
|
#include "../internal/catch_interfaces_reporter.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <cfloat>
|
||||||
|
#include <cstdio>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Because formatting using c++ streams is stateful, drop down to C is required
|
||||||
|
// Alternatively we could use stringstream, but its performance is... not good.
|
||||||
|
std::string getFormattedDuration( double duration ) {
|
||||||
|
// Max exponent + 1 is required to represent the whole part
|
||||||
|
// + 1 for decimal point
|
||||||
|
// + 3 for the 3 decimal places
|
||||||
|
// + 1 for null terminator
|
||||||
|
const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
|
||||||
|
char buffer[maxDoubleSize];
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
sprintf_s(buffer, "%.3f", duration);
|
||||||
|
#else
|
||||||
|
sprintf(buffer, "%.3f", duration);
|
||||||
|
#endif
|
||||||
|
return std::string(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
|
struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
|
||||||
|
|
||||||
StreamingReporterBase( ReporterConfig const& _config )
|
StreamingReporterBase( ReporterConfig const& _config )
|
||||||
|
@ -37,8 +37,7 @@ namespace Catch {
|
|||||||
stream << "No test cases matched '" << spec << '\'' << std::endl;
|
stream << "No test cases matched '" << spec << '\'' << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void assertionStarting( AssertionInfo const& ) {
|
virtual void assertionStarting( AssertionInfo const& ) {}
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
|
virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
|
||||||
AssertionResult const& result = _assertionStats.assertionResult;
|
AssertionResult const& result = _assertionStats.assertionResult;
|
||||||
@ -59,6 +58,12 @@ namespace Catch {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void sectionEnded(SectionStats const& _sectionStats) CATCH_OVERRIDE {
|
||||||
|
if (m_config->showDurations() == ShowDurations::Always) {
|
||||||
|
stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void testRunEnded( TestRunStats const& _testRunStats ) {
|
virtual void testRunEnded( TestRunStats const& _testRunStats ) {
|
||||||
printTotals( _testRunStats.totals );
|
printTotals( _testRunStats.totals );
|
||||||
stream << '\n' << std::endl;
|
stream << '\n' << std::endl;
|
||||||
|
@ -18,25 +18,6 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
namespace {
|
|
||||||
// Because formatting using c++ streams is stateful, drop down to C is required
|
|
||||||
// Alternatively we could use stringstream, but its performance is... not good.
|
|
||||||
std::string getFormattedDuration( double duration ) {
|
|
||||||
// Max exponent + 1 is required to represent the whole part
|
|
||||||
// + 1 for decimal point
|
|
||||||
// + 3 for the 3 decimal places
|
|
||||||
// + 1 for null terminator
|
|
||||||
const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
|
|
||||||
char buffer[maxDoubleSize];
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
sprintf_s(buffer, "%.3f", duration);
|
|
||||||
#else
|
|
||||||
sprintf(buffer, "%.3f", duration);
|
|
||||||
#endif
|
|
||||||
return std::string(buffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct ConsoleReporter : StreamingReporterBase {
|
struct ConsoleReporter : StreamingReporterBase {
|
||||||
ConsoleReporter( ReporterConfig const& _config )
|
ConsoleReporter( ReporterConfig const& _config )
|
||||||
|
Loading…
Reference in New Issue
Block a user