Added duration reporting to compact reporter

Also made the duration formatting code available to all reporters.

Closes #780
This commit is contained in:
Martin Hořeňovský
2017-03-02 16:16:17 +01:00
parent 95b0eb2b6c
commit 40f6a5b8a4
3 changed files with 29 additions and 21 deletions

View File

@@ -18,25 +18,6 @@
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 )