mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
Console reporter now uses fixed decimal formatting
3 decimal places, output in seconds.
This commit is contained in:
parent
70ac6dbb9f
commit
061a183036
@ -13,8 +13,31 @@
|
||||
#include "../internal/catch_reporter_registrars.hpp"
|
||||
#include "../internal/catch_console_colour.hpp"
|
||||
|
||||
#include <cfloat>
|
||||
#include <cstdio>
|
||||
|
||||
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 {
|
||||
ConsoleReporter( ReporterConfig const& _config )
|
||||
: StreamingReporterBase( _config ),
|
||||
@ -68,7 +91,7 @@ namespace Catch {
|
||||
stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
|
||||
}
|
||||
if( m_config->showDurations() == ShowDurations::Always ) {
|
||||
stream << _sectionStats.durationInSeconds << " s: " << _sectionStats.sectionInfo.name << std::endl;
|
||||
stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
|
||||
}
|
||||
if( m_headerPrinted ) {
|
||||
m_headerPrinted = false;
|
||||
|
Loading…
Reference in New Issue
Block a user