diff options
author | tamasmeszaros <meszaros.q@gmail.com> | 2019-10-29 15:33:29 +0300 |
---|---|---|
committer | tamasmeszaros <meszaros.q@gmail.com> | 2019-10-30 12:48:47 +0300 |
commit | b928cca54c666036f9d66074930761d416063cd4 (patch) | |
tree | 66d5f78a5b9ac5a55618f6d618799362ce25b1a9 /tests/catch_main.hpp | |
parent | f60fbecd3d580c7ace44d86719785e41829757ed (diff) |
Useful verbose test output on console with Catch2
Diffstat (limited to 'tests/catch_main.hpp')
-rw-r--r-- | tests/catch_main.hpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/catch_main.hpp b/tests/catch_main.hpp new file mode 100644 index 000000000..e49ff40b4 --- /dev/null +++ b/tests/catch_main.hpp @@ -0,0 +1,51 @@ +#ifndef CATCH_MAIN +#define CATCH_MAIN + +#define CATCH_CONFIG_EXTERNAL_INTERFACES +#define CATCH_CONFIG_MAIN +#include <catch2/catch.hpp> + +namespace Catch { +struct VerboseConsoleReporter : public ConsoleReporter { + double duration = 0.; + using ConsoleReporter::ConsoleReporter; + + void testCaseStarting(TestCaseInfo const& _testInfo) override + { + Colour::use(Colour::Cyan); + stream << "Testing "; + Colour::use(Colour::None); + stream << _testInfo.name << std::endl; + ConsoleReporter::testCaseStarting(_testInfo); + } + + void sectionStarting(const SectionInfo &_sectionInfo) override + { + if (_sectionInfo.name != currentTestCaseInfo->name) + stream << _sectionInfo.name << std::endl; + + ConsoleReporter::sectionStarting(_sectionInfo); + } + + void sectionEnded(const SectionStats &_sectionStats) override { + duration += _sectionStats.durationInSeconds; + ConsoleReporter::sectionEnded(_sectionStats); + } + + void testCaseEnded(TestCaseStats const& stats) override + { + if (stats.totals.assertions.allOk()) { + Colour::use(Colour::BrightGreen); + stream << "Passed"; + Colour::use(Colour::None); + stream << " in " << duration << " [seconds]\n" << std::endl; + } + + duration = 0.; + ConsoleReporter::testCaseEnded(stats); + } +}; +CATCH_REGISTER_REPORTER( "verboseconsole", VerboseConsoleReporter ) +} + +#endif // CATCH_MAIN |