Unit tests build and run (todo: projects, includes, extras)

This commit is contained in:
Martin Hořeňovský
2019-11-30 20:45:34 +01:00
parent e341b11467
commit fef4f217b1
9 changed files with 35 additions and 249 deletions

View File

@@ -222,6 +222,6 @@ add_library(Catch2 STATIC
target_include_directories(Catch2
PUBLIC
$<BUILD_INTERFACE:${SOURCES_DIR}>
$<BUILD_INTERFACE:${SOURCES_DIR}/..>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

View File

@@ -13,24 +13,24 @@
namespace Catch {
template <typename T>
class ReporterFactory : public IReporterFactory {
IStreamingReporterPtr create( ReporterConfig const& config ) const override {
return std::unique_ptr<T>( new T( config ) );
}
std::string getDescription() const override {
return T::getDescription();
}
};
template<typename T>
class ReporterRegistrar {
class ReporterFactory : public IReporterFactory {
IStreamingReporterPtr create( ReporterConfig const& config ) const override {
return std::unique_ptr<T>( new T( config ) );
}
std::string getDescription() const override {
return T::getDescription();
}
};
public:
explicit ReporterRegistrar( std::string const& name ) {
getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() );
getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory<T>>() );
}
};

View File

@@ -6,9 +6,21 @@
*/
#include "catch_reporter_registry.h"
#include <catch2/catch_reporter_registrars.hpp>
#include <catch2/reporters/catch_reporter_compact.h>
#include <catch2/reporters/catch_reporter_console.h>
#include <catch2/reporters/catch_reporter_junit.h>
#include <catch2/reporters/catch_reporter_xml.h>
namespace Catch {
ReporterRegistry::~ReporterRegistry() = default;
ReporterRegistry::ReporterRegistry():
m_factories({
{"compact", std::make_shared<ReporterFactory<CompactReporter>>() },
{"console", std::make_shared<ReporterFactory<ConsoleReporter>>() },
{"junit", std::make_shared<ReporterFactory<JunitReporter>>() },
{"xml", std::make_shared<ReporterFactory<XmlReporter>>() },
}) {}
IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const {
auto it = m_factories.find( name );

View File

@@ -15,10 +15,10 @@
namespace Catch {
class ReporterRegistry : public IReporterRegistry {
public:
~ReporterRegistry() override;
ReporterRegistry();
~ReporterRegistry() override = default;
IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override;

View File

@@ -7,7 +7,6 @@
#include "catch_reporter_compact.h"
#include "../catch_reporter_registrars.hpp"
#include "../catch_console_colour.h"
namespace {
@@ -288,6 +287,4 @@ private:
CompactReporter::~CompactReporter() {}
CATCH_REGISTER_REPORTER( "compact", CompactReporter )
} // end namespace Catch

View File

@@ -688,8 +688,6 @@ void ConsoleReporter::printTestFilters() {
stream << Colour(Colour::BrightYellow) << "Filters: " << serializeFilters( m_config->getTestsOrTags() ) << '\n';
}
CATCH_REGISTER_REPORTER("console", ConsoleReporter)
} // end namespace Catch
#if defined(_MSC_VER)

View File

@@ -280,6 +280,4 @@ namespace Catch {
}
}
CATCH_REGISTER_REPORTER( "junit", JunitReporter )
} // end namespace Catch

View File

@@ -318,9 +318,6 @@ namespace Catch {
}
}
CATCH_REGISTER_REPORTER( "xml", XmlReporter )
} // end namespace Catch
#if defined(_MSC_VER)