Useful verbose test output on console with Catch2

This commit is contained in:
tamasmeszaros 2019-10-29 13:33:29 +01:00
parent f60fbecd3d
commit b928cca54c
8 changed files with 58 additions and 13 deletions

View File

@ -10,7 +10,7 @@ target_include_directories(Catch2 INTERFACE ${CMAKE_CURRENT_LIST_DIR})
add_library(Catch2::Catch2 ALIAS Catch2)
include(Catch)
set(CATCH_EXTRA_ARGS "--durations yes" CACHE STRING "Extra arguments for catch2 test suites.")
set(CATCH_EXTRA_ARGS "-r usefulconsole" CACHE STRING "Extra arguments for catch2 test suites.")
add_library(test_common INTERFACE)
target_compile_definitions(test_common INTERFACE TEST_DATA_DIR=R"\(${TEST_DATA_DIR}\)" CATCH_CONFIG_FAST_COMPILE)

51
tests/catch_main.hpp Normal file
View File

@ -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

View File

@ -1,5 +1,5 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <catch_main.hpp>
TEST_CASE("Is example succesful", "[example]") {
REQUIRE(true);

View File

@ -1,4 +1,3 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <catch_main.hpp>
#include "libslic3r/libslic3r.h"

View File

@ -1,9 +1,7 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <catch_main.hpp>
#include <fstream>
#include <libnest2d/libnest2d.hpp>
#include "printer_parts.hpp"
//#include <libnest2d/geometry_traits_nfp.hpp>

View File

@ -1,5 +1,4 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <catch_main.hpp>
#include "libslic3r/libslic3r.h"

View File

@ -1,5 +1,4 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <catch_main.hpp>
#include <unordered_set>
#include <unordered_map>

View File

@ -1,5 +1,4 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <catch_main.hpp>
#include "libslic3r/Time.hpp"