From fef4f217b12ec6cbcb6b680555ddd69c7c1e4a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 30 Nov 2019 20:45:34 +0100 Subject: [PATCH] Unit tests build and run (todo: projects, includes, extras) --- projects/CMakeLists.txt | 226 +----------------- src/CMakeLists.txt | 2 +- src/catch2/catch_reporter_registrars.hpp | 28 +-- src/catch2/catch_reporter_registry.cpp | 14 +- src/catch2/catch_reporter_registry.h | 4 +- .../reporters/catch_reporter_compact.cpp | 3 - .../reporters/catch_reporter_console.cpp | 2 - src/catch2/reporters/catch_reporter_junit.cpp | 2 - src/catch2/reporters/catch_reporter_xml.cpp | 3 - 9 files changed, 35 insertions(+), 249 deletions(-) diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index d01f4375..a662c124 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -69,224 +69,6 @@ set(SURROGATE_SOURCES CheckFileList(SURROGATE_SOURCES ${SELF_TEST_DIR}/SurrogateCpps) -# Please keep these ordered alphabetically -set(EXTERNAL_HEADERS - ${HEADER_DIR}/external/clara.hpp - ) -CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external) - - -# Please keep these ordered alphabetically -set(BENCHMARK_HEADERS - ${HEADER_DIR}/internal/benchmark/catch_benchmark.hpp - ${HEADER_DIR}/internal/benchmark/catch_chronometer.hpp - ${HEADER_DIR}/internal/benchmark/catch_clock.hpp - ${HEADER_DIR}/internal/benchmark/catch_constructor.hpp - ${HEADER_DIR}/internal/benchmark/catch_environment.hpp - ${HEADER_DIR}/internal/benchmark/catch_estimate.hpp - ${HEADER_DIR}/internal/benchmark/catch_execution_plan.hpp - ${HEADER_DIR}/internal/benchmark/catch_optimizer.hpp - ${HEADER_DIR}/internal/benchmark/catch_outlier_classification.hpp - ${HEADER_DIR}/internal/benchmark/catch_sample_analysis.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_analyse.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_benchmark_function.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_complete_invoke.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_estimate_clock.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_measure.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_repeat.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_run_for_at_least.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_stats.hpp - ${HEADER_DIR}/internal/benchmark/detail/catch_timing.hpp -) -set(BENCHMARK_SOURCES - ${HEADER_DIR}/internal/benchmark/detail/catch_stats.cpp -) - -SOURCE_GROUP("benchmark" FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES}) - -set(INTERNAL_HEADERS - ${HEADER_DIR}/internal/catch_approx.h - ${HEADER_DIR}/internal/catch_assertionhandler.h - ${HEADER_DIR}/internal/catch_assertioninfo.h - ${HEADER_DIR}/internal/catch_assertionresult.h - ${HEADER_DIR}/internal/catch_capture.hpp - ${HEADER_DIR}/internal/catch_capture_matchers.h - ${HEADER_DIR}/internal/catch_clara.h - ${HEADER_DIR}/internal/catch_commandline.h - ${HEADER_DIR}/internal/catch_common.h - ${HEADER_DIR}/internal/catch_compiler_capabilities.h - ${HEADER_DIR}/internal/catch_config.hpp - ${HEADER_DIR}/internal/catch_console_colour.h - ${HEADER_DIR}/internal/catch_context.h - ${HEADER_DIR}/internal/catch_debug_console.h - ${HEADER_DIR}/internal/catch_debugger.h - ${HEADER_DIR}/internal/catch_decomposer.h - ${HEADER_DIR}/internal/catch_default_main.hpp - ${HEADER_DIR}/internal/catch_enforce.h - ${HEADER_DIR}/internal/catch_enum_values_registry.h - ${HEADER_DIR}/internal/catch_errno_guard.h - ${HEADER_DIR}/internal/catch_exception_translator_registry.h - ${HEADER_DIR}/internal/catch_external_interfaces.h - ${HEADER_DIR}/internal/catch_fatal_condition.h - ${HEADER_DIR}/internal/catch_generators.hpp - ${HEADER_DIR}/internal/catch_generators_generic.hpp - ${HEADER_DIR}/internal/catch_generators_specific.hpp - ${HEADER_DIR}/internal/catch_impl.hpp - ${HEADER_DIR}/internal/catch_interfaces_capture.h - ${HEADER_DIR}/internal/catch_interfaces_config.h - ${HEADER_DIR}/internal/catch_interfaces_enum_values_registry.h - ${HEADER_DIR}/internal/catch_interfaces_exception.h - ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h - ${HEADER_DIR}/internal/catch_interfaces_reporter.h - ${HEADER_DIR}/internal/catch_interfaces_runner.h - ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h - ${HEADER_DIR}/internal/catch_interfaces_testcase.h - ${HEADER_DIR}/internal/catch_leak_detector.h - ${HEADER_DIR}/internal/catch_list.h - ${HEADER_DIR}/internal/catch_matchers.h - ${HEADER_DIR}/internal/catch_matchers_exception.hpp - ${HEADER_DIR}/internal/catch_matchers_floating.h - ${HEADER_DIR}/internal/catch_matchers_generic.hpp - ${HEADER_DIR}/internal/catch_matchers_string.h - ${HEADER_DIR}/internal/catch_matchers_vector.h - ${HEADER_DIR}/internal/catch_message.h - ${HEADER_DIR}/internal/catch_meta.hpp - ${HEADER_DIR}/internal/catch_objc.hpp - ${HEADER_DIR}/internal/catch_objc_arc.hpp - ${HEADER_DIR}/internal/catch_option.hpp - ${HEADER_DIR}/internal/catch_output_redirect.h - ${HEADER_DIR}/internal/catch_platform.h - ${HEADER_DIR}/internal/catch_polyfills.hpp - ${HEADER_DIR}/internal/catch_preprocessor.hpp - ${HEADER_DIR}/internal/catch_random_number_generator.h - ${HEADER_DIR}/internal/catch_reenable_warnings.h - ${HEADER_DIR}/internal/catch_reporter_registrars.hpp - ${HEADER_DIR}/internal/catch_reporter_registry.h - ${HEADER_DIR}/internal/catch_result_type.h - ${HEADER_DIR}/internal/catch_run_context.h - ${HEADER_DIR}/internal/catch_section.h - ${HEADER_DIR}/internal/catch_section_info.h - ${HEADER_DIR}/internal/catch_session.h - ${HEADER_DIR}/internal/catch_singletons.hpp - ${HEADER_DIR}/internal/catch_startup_exception_registry.h - ${HEADER_DIR}/internal/catch_stream.h - ${HEADER_DIR}/internal/catch_stringref.h - ${HEADER_DIR}/internal/catch_string_manip.h - ${HEADER_DIR}/internal/catch_suppress_warnings.h - ${HEADER_DIR}/internal/catch_tag_alias.h - ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.h - ${HEADER_DIR}/internal/catch_tag_alias_registry.h - ${HEADER_DIR}/internal/catch_test_case_info.h - ${HEADER_DIR}/internal/catch_test_case_registry_impl.h - ${HEADER_DIR}/internal/catch_test_case_tracker.h - ${HEADER_DIR}/internal/catch_test_registry.h - ${HEADER_DIR}/internal/catch_test_spec.h - ${HEADER_DIR}/internal/catch_test_spec_parser.h - ${HEADER_DIR}/internal/catch_text.h - ${HEADER_DIR}/internal/catch_timer.h - ${HEADER_DIR}/internal/catch_to_string.hpp - ${HEADER_DIR}/internal/catch_tostring.h - ${HEADER_DIR}/internal/catch_totals.h - ${HEADER_DIR}/internal/catch_uncaught_exceptions.h - ${HEADER_DIR}/internal/catch_user_interfaces.h - ${HEADER_DIR}/internal/catch_version.h - ${HEADER_DIR}/internal/catch_wildcard_pattern.h - ${HEADER_DIR}/internal/catch_windows_h_proxy.h - ${HEADER_DIR}/internal/catch_xmlwriter.h - ) -set(IMPL_SOURCES - ${HEADER_DIR}/internal/catch_approx.cpp - ${HEADER_DIR}/internal/catch_assertionhandler.cpp - ${HEADER_DIR}/internal/catch_assertionresult.cpp - ${HEADER_DIR}/internal/catch_capture_matchers.cpp - ${HEADER_DIR}/internal/catch_commandline.cpp - ${HEADER_DIR}/internal/catch_common.cpp - ${HEADER_DIR}/internal/catch_config.cpp - ${HEADER_DIR}/internal/catch_console_colour.cpp - ${HEADER_DIR}/internal/catch_context.cpp - ${HEADER_DIR}/internal/catch_debug_console.cpp - ${HEADER_DIR}/internal/catch_debugger.cpp - ${HEADER_DIR}/internal/catch_decomposer.cpp - ${HEADER_DIR}/internal/catch_enforce.cpp - ${HEADER_DIR}/internal/catch_enum_values_registry.cpp - ${HEADER_DIR}/internal/catch_errno_guard.cpp - ${HEADER_DIR}/internal/catch_exception_translator_registry.cpp - ${HEADER_DIR}/internal/catch_fatal_condition.cpp - ${HEADER_DIR}/internal/catch_generators.cpp - ${HEADER_DIR}/internal/catch_interfaces_capture.cpp - ${HEADER_DIR}/internal/catch_interfaces_config.cpp - ${HEADER_DIR}/internal/catch_interfaces_exception.cpp - ${HEADER_DIR}/internal/catch_interfaces_generatortracker.h - ${HEADER_DIR}/internal/catch_interfaces_registry_hub.cpp - ${HEADER_DIR}/internal/catch_interfaces_runner.cpp - ${HEADER_DIR}/internal/catch_interfaces_testcase.cpp - ${HEADER_DIR}/internal/catch_list.cpp - ${HEADER_DIR}/internal/catch_leak_detector.cpp - ${HEADER_DIR}/internal/catch_matchers.cpp - ${HEADER_DIR}/internal/catch_matchers_exception.cpp - ${HEADER_DIR}/internal/catch_matchers_floating.cpp - ${HEADER_DIR}/internal/catch_matchers_generic.cpp - ${HEADER_DIR}/internal/catch_matchers_string.cpp - ${HEADER_DIR}/internal/catch_message.cpp - ${HEADER_DIR}/internal/catch_output_redirect.cpp - ${HEADER_DIR}/internal/catch_registry_hub.cpp - ${HEADER_DIR}/internal/catch_interfaces_reporter.cpp - ${HEADER_DIR}/internal/catch_polyfills.cpp - ${HEADER_DIR}/internal/catch_random_number_generator.cpp - ${HEADER_DIR}/internal/catch_reporter_registry.cpp - ${HEADER_DIR}/internal/catch_result_type.cpp - ${HEADER_DIR}/internal/catch_run_context.cpp - ${HEADER_DIR}/internal/catch_section.cpp - ${HEADER_DIR}/internal/catch_session.cpp - ${HEADER_DIR}/internal/catch_singletons.cpp - ${HEADER_DIR}/internal/catch_startup_exception_registry.cpp - ${HEADER_DIR}/internal/catch_stream.cpp - ${HEADER_DIR}/internal/catch_stringref.cpp - ${HEADER_DIR}/internal/catch_string_manip.cpp - ${HEADER_DIR}/internal/catch_tag_alias.cpp - ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.cpp - ${HEADER_DIR}/internal/catch_tag_alias_registry.cpp - ${HEADER_DIR}/internal/catch_test_case_info.cpp - ${HEADER_DIR}/internal/catch_test_case_registry_impl.cpp - ${HEADER_DIR}/internal/catch_test_case_tracker.cpp - ${HEADER_DIR}/internal/catch_test_registry.cpp - ${HEADER_DIR}/internal/catch_test_spec.cpp - ${HEADER_DIR}/internal/catch_test_spec_parser.cpp - ${HEADER_DIR}/internal/catch_timer.cpp - ${HEADER_DIR}/internal/catch_tostring.cpp - ${HEADER_DIR}/internal/catch_totals.cpp - ${HEADER_DIR}/internal/catch_uncaught_exceptions.cpp - ${HEADER_DIR}/internal/catch_version.cpp - ${HEADER_DIR}/internal/catch_wildcard_pattern.cpp - ${HEADER_DIR}/internal/catch_xmlwriter.cpp - ) -set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS}) -CheckFileList(INTERNAL_FILES ${HEADER_DIR}/internal) - -# Please keep these ordered alphabetically -set(REPORTER_HEADERS - ${HEADER_DIR}/reporters/catch_reporter_automake.hpp - ${HEADER_DIR}/reporters/catch_reporter_bases.hpp - ${HEADER_DIR}/reporters/catch_reporter_compact.h - ${HEADER_DIR}/reporters/catch_reporter_console.h - ${HEADER_DIR}/reporters/catch_reporter_junit.h - ${HEADER_DIR}/reporters/catch_reporter_listening.h - ${HEADER_DIR}/reporters/catch_reporter_tap.hpp - ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp - ${HEADER_DIR}/reporters/catch_reporter_xml.h - ${HEADER_DIR}/reporters/catch_reporter_sonarqube.hpp - ) -set(REPORTER_SOURCES - ${HEADER_DIR}/reporters/catch_reporter_bases.cpp - ${HEADER_DIR}/reporters/catch_reporter_compact.cpp - ${HEADER_DIR}/reporters/catch_reporter_console.cpp - ${HEADER_DIR}/reporters/catch_reporter_junit.cpp - ${HEADER_DIR}/reporters/catch_reporter_listening.cpp - ${HEADER_DIR}/reporters/catch_reporter_xml.cpp - ) -set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES}) -CheckFileList(REPORTER_FILES ${HEADER_DIR}/reporters) - # Specify the headers, too, so CLion recognises them as project files set(HEADERS ${TOP_LEVEL_HEADERS} @@ -298,14 +80,16 @@ set(HEADERS ) # Provide some groupings for IDEs -SOURCE_GROUP("Tests" FILES ${TEST_SOURCES}) -SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES}) +#SOURCE_GROUP("benchmark" FILES ${BENCHMARK_HEADERS} ${BENCHMARK_SOURCES}) +#SOURCE_GROUP("Tests" FILES ${TEST_SOURCES}) +#SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES}) include(CTest) add_executable(SelfTest ${TEST_SOURCES}) target_link_libraries(SelfTest PRIVATE Catch2) -target_include_directories(SelfTest PRIVATE ${HEADER_DIR}) +# Fixme! +target_include_directories(SelfTest PRIVATE ${SOURCES_DIR}) # It took CMake until 3.8 to abandon the doomed approach of enumerating # required features so we just list bunch of C++11 and C++14 features. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8c66ff87..e33466a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -222,6 +222,6 @@ add_library(Catch2 STATIC target_include_directories(Catch2 PUBLIC - $ + $ $ ) diff --git a/src/catch2/catch_reporter_registrars.hpp b/src/catch2/catch_reporter_registrars.hpp index a1950536..842c82e8 100644 --- a/src/catch2/catch_reporter_registrars.hpp +++ b/src/catch2/catch_reporter_registrars.hpp @@ -13,24 +13,24 @@ namespace Catch { + template + class ReporterFactory : public IReporterFactory { + + IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr( new T( config ) ); + } + + std::string getDescription() const override { + return T::getDescription(); + } + }; + + template class ReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - - IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::unique_ptr( new T( config ) ); - } - - std::string getDescription() const override { - return T::getDescription(); - } - }; - public: - explicit ReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, std::make_shared() ); + getMutableRegistryHub().registerReporter( name, std::make_shared>() ); } }; diff --git a/src/catch2/catch_reporter_registry.cpp b/src/catch2/catch_reporter_registry.cpp index f017e059..235fab1a 100644 --- a/src/catch2/catch_reporter_registry.cpp +++ b/src/catch2/catch_reporter_registry.cpp @@ -6,9 +6,21 @@ */ #include "catch_reporter_registry.h" +#include +#include +#include +#include +#include + namespace Catch { - ReporterRegistry::~ReporterRegistry() = default; + ReporterRegistry::ReporterRegistry(): + m_factories({ + {"compact", std::make_shared>() }, + {"console", std::make_shared>() }, + {"junit", std::make_shared>() }, + {"xml", std::make_shared>() }, + }) {} IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const { auto it = m_factories.find( name ); diff --git a/src/catch2/catch_reporter_registry.h b/src/catch2/catch_reporter_registry.h index 916e9247..31fd01f8 100644 --- a/src/catch2/catch_reporter_registry.h +++ b/src/catch2/catch_reporter_registry.h @@ -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; diff --git a/src/catch2/reporters/catch_reporter_compact.cpp b/src/catch2/reporters/catch_reporter_compact.cpp index 705144b1..2b9b35cf 100644 --- a/src/catch2/reporters/catch_reporter_compact.cpp +++ b/src/catch2/reporters/catch_reporter_compact.cpp @@ -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 diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp index 2d1dbdfa..35698ef7 100644 --- a/src/catch2/reporters/catch_reporter_console.cpp +++ b/src/catch2/reporters/catch_reporter_console.cpp @@ -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) diff --git a/src/catch2/reporters/catch_reporter_junit.cpp b/src/catch2/reporters/catch_reporter_junit.cpp index 22ae4b37..3531d3e4 100644 --- a/src/catch2/reporters/catch_reporter_junit.cpp +++ b/src/catch2/reporters/catch_reporter_junit.cpp @@ -280,6 +280,4 @@ namespace Catch { } } - CATCH_REGISTER_REPORTER( "junit", JunitReporter ) - } // end namespace Catch diff --git a/src/catch2/reporters/catch_reporter_xml.cpp b/src/catch2/reporters/catch_reporter_xml.cpp index 212b02f6..d02488e5 100644 --- a/src/catch2/reporters/catch_reporter_xml.cpp +++ b/src/catch2/reporters/catch_reporter_xml.cpp @@ -318,9 +318,6 @@ namespace Catch { } } - - CATCH_REGISTER_REPORTER( "xml", XmlReporter ) - } // end namespace Catch #if defined(_MSC_VER)