diff --git a/examples/300-Gen-OwnGenerator.cpp b/examples/300-Gen-OwnGenerator.cpp index bff62907..09643d6f 100644 --- a/examples/300-Gen-OwnGenerator.cpp +++ b/examples/300-Gen-OwnGenerator.cpp @@ -43,7 +43,9 @@ int const& RandomIntGenerator::get() const { // is a value-wrapper around std::unique_ptr>. Catch::Generators::GeneratorWrapper random(int low, int high) { return Catch::Generators::GeneratorWrapper( - std::make_unique(low, high) + new RandomIntGenerator(low, high) + // Another possibility: + // Catch::Detail::make_unique(low, high) ); } @@ -58,7 +60,7 @@ TEST_CASE("Generating random ints", "[example][generator]") { REQUIRE(i <= 100); } SECTION("Creating the random generator directly") { - auto i = GENERATE(take(100, GeneratorWrapper(std::unique_ptr>(new RandomIntGenerator(-100, 100))))); + auto i = GENERATE(take(100, GeneratorWrapper(Catch::Detail::make_unique(-100, 100)))); REQUIRE(i >= -100); REQUIRE(i <= 100); } diff --git a/examples/301-Gen-MapTypeConversion.cpp b/examples/301-Gen-MapTypeConversion.cpp index 15b90fdd..6d81ce6d 100644 --- a/examples/301-Gen-MapTypeConversion.cpp +++ b/examples/301-Gen-MapTypeConversion.cpp @@ -40,7 +40,7 @@ std::string const& LineGenerator::get() const { // is a value-wrapper around std::unique_ptr>. Catch::Generators::GeneratorWrapper lines(std::string /* ignored for example */) { return Catch::Generators::GeneratorWrapper( - std::make_unique() + new LineGenerator() ); } diff --git a/src/catch2/benchmark/detail/catch_benchmark_function.hpp b/src/catch2/benchmark/detail/catch_benchmark_function.hpp index 03ef22a7..ebeb7fa0 100644 --- a/src/catch2/benchmark/detail/catch_benchmark_function.hpp +++ b/src/catch2/benchmark/detail/catch_benchmark_function.hpp @@ -14,11 +14,11 @@ #include #include #include +#include #include #include #include -#include namespace Catch { namespace Benchmark { @@ -100,7 +100,7 @@ namespace Catch { void operator()(Chronometer meter) const { f->call(meter); } private: - std::unique_ptr f; + Catch::Detail::unique_ptr f; }; } // namespace Detail } // namespace Benchmark diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp index 55cff0ee..dd8767dc 100644 --- a/src/catch2/catch_config.hpp +++ b/src/catch2/catch_config.hpp @@ -10,8 +10,8 @@ #include #include +#include -#include #include #include @@ -116,7 +116,7 @@ namespace Catch { IStream const* openStream(); ConfigData m_data; - std::unique_ptr m_stream; + Detail::unique_ptr m_stream; TestSpec m_testSpec; bool m_hasTestFilters = false; }; diff --git a/src/catch2/catch_registry_hub.cpp b/src/catch2/catch_registry_hub.cpp index c6a19f09..ed2d068a 100644 --- a/src/catch2/catch_registry_hub.cpp +++ b/src/catch2/catch_registry_hub.cpp @@ -49,7 +49,7 @@ namespace Catch { void registerListener( IReporterFactoryPtr factory ) override { m_reporterRegistry.registerListener( std::move(factory) ); } - void registerTest( std::unique_ptr&& testInfo, std::unique_ptr&& invoker ) override { + void registerTest( Detail::unique_ptr&& testInfo, Detail::unique_ptr&& invoker ) override { m_testCaseRegistry.registerTest( std::move(testInfo), std::move(invoker) ); } void registerTranslator( const IExceptionTranslator* translator ) override { diff --git a/src/catch2/catch_reporter_registrars.hpp b/src/catch2/catch_reporter_registrars.hpp index 0b4c19f2..8ad600ea 100644 --- a/src/catch2/catch_reporter_registrars.hpp +++ b/src/catch2/catch_reporter_registrars.hpp @@ -10,6 +10,7 @@ #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED #include +#include namespace Catch { @@ -17,7 +18,7 @@ namespace Catch { class ReporterFactory : public IReporterFactory { IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::make_unique( config ); + return Detail::make_unique( config ); } std::string getDescription() const override { @@ -30,7 +31,7 @@ namespace Catch { class ReporterRegistrar { public: explicit ReporterRegistrar( std::string const& name ) { - getMutableRegistryHub().registerReporter( name, std::make_unique>() ); + getMutableRegistryHub().registerReporter( name, Detail::make_unique>() ); } }; @@ -40,7 +41,7 @@ namespace Catch { class ListenerFactory : public IReporterFactory { IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::make_unique(config); + return Detail::make_unique(config); } std::string getDescription() const override { return std::string(); @@ -50,7 +51,7 @@ namespace Catch { public: ListenerRegistrar() { - getMutableRegistryHub().registerListener( std::make_unique() ); + getMutableRegistryHub().registerListener( Detail::make_unique() ); } }; } diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp index 351deb8d..3abd8410 100644 --- a/src/catch2/catch_session.cpp +++ b/src/catch2/catch_session.cpp @@ -44,12 +44,12 @@ namespace Catch { return createReporter(config->getReporterName(), config); } - // On older platforms, returning std::unique_ptr - // when the return type is std::unique_ptr + // On older platforms, returning unique_ptr + // when the return type is unique_ptr // doesn't compile without a std::move call. However, this causes // a warning on newer platforms. Thus, we have to work around // it a bit and downcast the pointer manually. - auto ret = std::unique_ptr(new ListeningReporter); + auto ret = Detail::unique_ptr(new ListeningReporter); auto& multi = static_cast(*ret); auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); for (auto const& listener : listeners) { @@ -252,7 +252,7 @@ namespace Catch { } Config& Session::config() { if( !m_config ) - m_config = std::make_unique( m_configData ); + m_config = Detail::make_unique( m_configData ); return *m_config; } diff --git a/src/catch2/catch_session.hpp b/src/catch2/catch_session.hpp index 54fe37dd..52bf9f34 100644 --- a/src/catch2/catch_session.hpp +++ b/src/catch2/catch_session.hpp @@ -11,8 +11,7 @@ #include #include #include - -#include +#include namespace Catch { @@ -53,7 +52,7 @@ namespace Catch { clara::Parser m_cli; ConfigData m_configData; - std::unique_ptr m_config; + Detail::unique_ptr m_config; bool m_startupExceptions = false; }; diff --git a/src/catch2/catch_test_case_info.cpp b/src/catch2/catch_test_case_info.cpp index 7be5b861..a4bcb11c 100644 --- a/src/catch2/catch_test_case_info.cpp +++ b/src/catch2/catch_test_case_info.cpp @@ -105,11 +105,11 @@ namespace Catch { } } - std::unique_ptr + Detail::unique_ptr makeTestCaseInfo(std::string const& _className, NameAndTags const& nameAndTags, SourceLineInfo const& _lineInfo ) { - return std::make_unique(_className, nameAndTags, _lineInfo); + return Detail::unique_ptr(new TestCaseInfo(_className, nameAndTags, _lineInfo)); } TestCaseInfo::TestCaseInfo(std::string const& _className, diff --git a/src/catch2/catch_test_case_info.hpp b/src/catch2/catch_test_case_info.hpp index f586ce92..991cca61 100644 --- a/src/catch2/catch_test_case_info.hpp +++ b/src/catch2/catch_test_case_info.hpp @@ -11,10 +11,11 @@ #include #include #include +#include + #include #include -#include #ifdef __clang__ #pragma clang diagnostic push @@ -90,7 +91,7 @@ namespace Catch { bool operator < ( TestCaseHandle const& rhs ) const; }; - std::unique_ptr makeTestCaseInfo( std::string const& className, + Detail::unique_ptr makeTestCaseInfo( std::string const& className, NameAndTags const& nameAndTags, SourceLineInfo const& lineInfo ); } diff --git a/src/catch2/catch_test_spec.cpp b/src/catch2/catch_test_spec.cpp index 87cf8cae..88966ec1 100644 --- a/src/catch2/catch_test_spec.cpp +++ b/src/catch2/catch_test_spec.cpp @@ -13,7 +13,6 @@ #include #include #include -#include namespace Catch { diff --git a/src/catch2/catch_test_spec.hpp b/src/catch2/catch_test_spec.hpp index 3a767c74..7bb86512 100644 --- a/src/catch2/catch_test_spec.hpp +++ b/src/catch2/catch_test_spec.hpp @@ -13,11 +13,11 @@ #pragma clang diagnostic ignored "-Wpadded" #endif +#include #include #include #include -#include namespace Catch { @@ -54,8 +54,8 @@ namespace Catch { }; struct Filter { - std::vector> m_required; - std::vector> m_forbidden; + std::vector> m_required; + std::vector> m_forbidden; bool matches( TestCaseInfo const& testCase ) const; std::string name() const; diff --git a/src/catch2/generators/catch_generators.hpp b/src/catch2/generators/catch_generators.hpp index e8c2a8fd..2e8fad14 100644 --- a/src/catch2/generators/catch_generators.hpp +++ b/src/catch2/generators/catch_generators.hpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -43,11 +42,35 @@ namespace Detail { using type = T; }; + template + using GeneratorPtr = Catch::Detail::unique_ptr>; + + template + class GeneratorWrapper final { + GeneratorPtr m_generator; + public: + //! Takes ownership of the passed pointer. + GeneratorWrapper(IGenerator* generator): + m_generator(generator) {} + GeneratorWrapper(GeneratorPtr generator): + m_generator(std::move(generator)) {} + + T const& get() const { + return m_generator->get(); + } + bool next() { + return m_generator->next(); + } + }; + + template class SingleValueGenerator final : public IGenerator { T m_value; public: - SingleValueGenerator(T&& value) : m_value(std::move(value)) {} + SingleValueGenerator(T&& value): + m_value(std::forward(value)) + {} T const& get() const override { return m_value; @@ -76,28 +99,13 @@ namespace Detail { } }; - template - class GeneratorWrapper final { - std::unique_ptr> m_generator; - public: - GeneratorWrapper(std::unique_ptr> generator): - m_generator(std::move(generator)) - {} - T const& get() const { - return m_generator->get(); - } - bool next() { - return m_generator->next(); - } - }; - template GeneratorWrapper value(T&& value) { - return GeneratorWrapper(std::make_unique>(std::forward(value))); + return GeneratorWrapper(Catch::Detail::make_unique>(std::forward(value))); } template GeneratorWrapper values(std::initializer_list values) { - return GeneratorWrapper(std::make_unique>(values)); + return GeneratorWrapper(Catch::Detail::make_unique>(values)); } template @@ -182,7 +190,7 @@ namespace Detail { IGeneratorTracker& tracker = acquireGeneratorTracker( lineInfo ); if (!tracker.hasGenerator()) { - tracker.setGenerator(std::make_unique>(generatorExpression())); + tracker.setGenerator(Catch::Detail::make_unique>(generatorExpression())); } auto const& generator = static_cast const&>( *tracker.getGenerator() ); diff --git a/src/catch2/generators/catch_generators_adapters.hpp b/src/catch2/generators/catch_generators_adapters.hpp index 774df819..d4ea46e3 100644 --- a/src/catch2/generators/catch_generators_adapters.hpp +++ b/src/catch2/generators/catch_generators_adapters.hpp @@ -46,7 +46,7 @@ namespace Generators { template GeneratorWrapper take(size_t target, GeneratorWrapper&& generator) { - return GeneratorWrapper(std::make_unique>(target, std::move(generator))); + return GeneratorWrapper(Catch::Detail::make_unique>(target, std::move(generator))); } @@ -87,7 +87,7 @@ namespace Generators { template GeneratorWrapper filter(Predicate&& pred, GeneratorWrapper&& generator) { - return GeneratorWrapper(std::unique_ptr>(std::make_unique>(std::forward(pred), std::move(generator)))); + return GeneratorWrapper(Catch::Detail::make_unique>(std::forward(pred), std::move(generator))); } template @@ -143,7 +143,7 @@ namespace Generators { template GeneratorWrapper repeat(size_t repeats, GeneratorWrapper&& generator) { - return GeneratorWrapper(std::make_unique>(repeats, std::move(generator))); + return GeneratorWrapper(Catch::Detail::make_unique>(repeats, std::move(generator))); } template @@ -176,14 +176,14 @@ namespace Generators { template > GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { return GeneratorWrapper( - std::make_unique>(std::forward(function), std::move(generator)) + Catch::Detail::make_unique>(std::forward(function), std::move(generator)) ); } template GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { return GeneratorWrapper( - std::make_unique>(std::forward(function), std::move(generator)) + Catch::Detail::make_unique>(std::forward(function), std::move(generator)) ); } @@ -226,7 +226,7 @@ namespace Generators { template GeneratorWrapper> chunk(size_t size, GeneratorWrapper&& generator) { return GeneratorWrapper>( - std::make_unique>(size, std::move(generator)) + Catch::Detail::make_unique>(size, std::move(generator)) ); } diff --git a/src/catch2/generators/catch_generators_random.hpp b/src/catch2/generators/catch_generators_random.hpp index 03cb57c1..eb6de023 100644 --- a/src/catch2/generators/catch_generators_random.hpp +++ b/src/catch2/generators/catch_generators_random.hpp @@ -67,7 +67,7 @@ std::enable_if_t::value && !std::is_same::value, GeneratorWrapper> random(T a, T b) { return GeneratorWrapper( - std::make_unique>(a, b) + Catch::Detail::make_unique>(a, b) ); } @@ -76,7 +76,7 @@ std::enable_if_t::value, GeneratorWrapper> random(T a, T b) { return GeneratorWrapper( - std::make_unique>(a, b) + Catch::Detail::make_unique>(a, b) ); } diff --git a/src/catch2/generators/catch_generators_range.hpp b/src/catch2/generators/catch_generators_range.hpp index e2c5c522..ffb80377 100644 --- a/src/catch2/generators/catch_generators_range.hpp +++ b/src/catch2/generators/catch_generators_range.hpp @@ -52,13 +52,13 @@ public: template GeneratorWrapper range(T const& start, T const& end, T const& step) { static_assert(std::is_arithmetic::value && !std::is_same::value, "Type must be numeric"); - return GeneratorWrapper(std::make_unique>(start, end, step)); + return GeneratorWrapper(Catch::Detail::make_unique>(start, end, step)); } template GeneratorWrapper range(T const& start, T const& end) { static_assert(std::is_integral::value && !std::is_same::value, "Type must be an integer"); - return GeneratorWrapper(std::make_unique>(start, end)); + return GeneratorWrapper(Catch::Detail::make_unique>(start, end)); } @@ -92,13 +92,13 @@ template ::value_type> GeneratorWrapper from_range(InputIterator from, InputSentinel to) { - return GeneratorWrapper(std::make_unique>(from, to)); + return GeneratorWrapper(Catch::Detail::make_unique>(from, to)); } template GeneratorWrapper from_range(Container const& cnt) { - return GeneratorWrapper(std::make_unique>(cnt.begin(), cnt.end())); + return GeneratorWrapper(Catch::Detail::make_unique>(cnt.begin(), cnt.end())); } diff --git a/src/catch2/interfaces/catch_interfaces_exception.hpp b/src/catch2/interfaces/catch_interfaces_exception.hpp index e9fb9ef7..31b6dc20 100644 --- a/src/catch2/interfaces/catch_interfaces_exception.hpp +++ b/src/catch2/interfaces/catch_interfaces_exception.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -18,7 +19,7 @@ namespace Catch { using exceptionTranslateFunction = std::string(*)(); struct IExceptionTranslator; - using ExceptionTranslators = std::vector>; + using ExceptionTranslators = std::vector>; struct IExceptionTranslator { virtual ~IExceptionTranslator(); diff --git a/src/catch2/interfaces/catch_interfaces_generatortracker.hpp b/src/catch2/interfaces/catch_interfaces_generatortracker.hpp index fa08be0c..88615ef5 100644 --- a/src/catch2/interfaces/catch_interfaces_generatortracker.hpp +++ b/src/catch2/interfaces/catch_interfaces_generatortracker.hpp @@ -8,7 +8,7 @@ #ifndef TWOBLUECUBES_CATCH_INTERFACES_GENERATORTRACKER_INCLUDED #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORTRACKER_INCLUDED -#include +#include namespace Catch { @@ -29,7 +29,7 @@ namespace Catch { // can be retrieved). virtual bool next() = 0; }; - using GeneratorBasePtr = std::unique_ptr; + using GeneratorBasePtr = Catch::Detail::unique_ptr; } // namespace Generators diff --git a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp index e292763d..3e99d215 100644 --- a/src/catch2/interfaces/catch_interfaces_registry_hub.hpp +++ b/src/catch2/interfaces/catch_interfaces_registry_hub.hpp @@ -9,9 +9,9 @@ #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED #include +#include #include -#include namespace Catch { @@ -28,7 +28,7 @@ namespace Catch { class StartupExceptionRegistry; - using IReporterFactoryPtr = std::unique_ptr; + using IReporterFactoryPtr = Detail::unique_ptr; struct IRegistryHub { virtual ~IRegistryHub(); @@ -46,7 +46,7 @@ namespace Catch { virtual ~IMutableRegistryHub(); virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0; virtual void registerListener( IReporterFactoryPtr factory ) = 0; - virtual void registerTest(std::unique_ptr&& testInfo, std::unique_ptr&& invoker) = 0; + virtual void registerTest(Detail::unique_ptr&& testInfo, Detail::unique_ptr&& invoker) = 0; virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0; virtual void registerStartupException() noexcept = 0; diff --git a/src/catch2/interfaces/catch_interfaces_reporter.hpp b/src/catch2/interfaces/catch_interfaces_reporter.hpp index 408db425..5f0bcfc6 100644 --- a/src/catch2/interfaces/catch_interfaces_reporter.hpp +++ b/src/catch2/interfaces/catch_interfaces_reporter.hpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include namespace Catch { @@ -222,14 +222,14 @@ namespace Catch { virtual void listTags(std::vector const& tags, Config const& config); }; - using IStreamingReporterPtr = std::unique_ptr; + using IStreamingReporterPtr = Detail::unique_ptr; struct IReporterFactory { virtual ~IReporterFactory(); virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; virtual std::string getDescription() const = 0; }; - using IReporterFactoryPtr = std::unique_ptr; + using IReporterFactoryPtr = Detail::unique_ptr; struct IReporterRegistry { using FactoryMap = std::map; diff --git a/src/catch2/interfaces/catch_interfaces_testcase.hpp b/src/catch2/interfaces/catch_interfaces_testcase.hpp index d176b490..aecc0871 100644 --- a/src/catch2/interfaces/catch_interfaces_testcase.hpp +++ b/src/catch2/interfaces/catch_interfaces_testcase.hpp @@ -9,7 +9,6 @@ #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED #include -#include namespace Catch { @@ -26,7 +25,8 @@ namespace Catch { struct ITestCaseRegistry { virtual ~ITestCaseRegistry(); - virtual std::vector> const& getAllInfos() const = 0; + // TODO: this exists only for adding filenames to test cases -- let's expose this in a saner way later + virtual std::vector const& getAllInfos() const = 0; virtual std::vector const& getAllTests() const = 0; virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; }; diff --git a/src/catch2/internal/catch_enum_values_registry.cpp b/src/catch2/internal/catch_enum_values_registry.cpp index 0ab07b57..7e7deb87 100644 --- a/src/catch2/internal/catch_enum_values_registry.cpp +++ b/src/catch2/internal/catch_enum_values_registry.cpp @@ -51,8 +51,8 @@ namespace Catch { return "{** unexpected enum value **}"_sr; } - std::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ) { - auto enumInfo = std::make_unique(); + Catch::Detail::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ) { + auto enumInfo = Catch::Detail::make_unique(); enumInfo->m_name = enumName; enumInfo->m_values.reserve( values.size() ); diff --git a/src/catch2/internal/catch_enum_values_registry.hpp b/src/catch2/internal/catch_enum_values_registry.hpp index 87494b07..080af01e 100644 --- a/src/catch2/internal/catch_enum_values_registry.hpp +++ b/src/catch2/internal/catch_enum_values_registry.hpp @@ -9,19 +9,19 @@ #define TWOBLUECUBES_CATCH_ENUMVALUESREGISTRY_H_INCLUDED #include +#include #include -#include namespace Catch { namespace Detail { - std::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ); + Catch::Detail::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ); class EnumValuesRegistry : public IMutableEnumValuesRegistry { - std::vector> m_enumInfos; + std::vector> m_enumInfos; EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector const& values) override; }; diff --git a/src/catch2/internal/catch_exception_translator_registry.cpp b/src/catch2/internal/catch_exception_translator_registry.cpp index d99ec839..36640309 100644 --- a/src/catch2/internal/catch_exception_translator_registry.cpp +++ b/src/catch2/internal/catch_exception_translator_registry.cpp @@ -17,7 +17,7 @@ namespace Catch { } void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) { - m_translators.push_back( std::unique_ptr( translator ) ); + m_translators.push_back( Detail::unique_ptr( translator ) ); } #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) diff --git a/src/catch2/internal/catch_exception_translator_registry.hpp b/src/catch2/internal/catch_exception_translator_registry.hpp index 48c385ab..7c170c08 100644 --- a/src/catch2/internal/catch_exception_translator_registry.hpp +++ b/src/catch2/internal/catch_exception_translator_registry.hpp @@ -11,7 +11,6 @@ #include #include #include -#include namespace Catch { @@ -23,7 +22,7 @@ namespace Catch { std::string tryTranslators() const; private: - std::vector> m_translators; + ExceptionTranslators m_translators; }; } diff --git a/src/catch2/internal/catch_reporter_registry.cpp b/src/catch2/internal/catch_reporter_registry.cpp index 9c37b7b2..4919e5df 100644 --- a/src/catch2/internal/catch_reporter_registry.cpp +++ b/src/catch2/internal/catch_reporter_registry.cpp @@ -21,14 +21,14 @@ namespace Catch { ReporterRegistry::ReporterRegistry() { // Because it is impossible to move out of initializer list, // we have to add the elements manually - m_factories["automake"] = std::make_unique>(); - m_factories["compact"] = std::make_unique>(); - m_factories["console"] = std::make_unique>(); - m_factories["junit"] = std::make_unique>(); - m_factories["sonarqube"] = std::make_unique>(); - m_factories["tap"] = std::make_unique>(); - m_factories["teamcity"] = std::make_unique>(); - m_factories["xml"] = std::make_unique>(); + m_factories["automake"] = Detail::make_unique>(); + m_factories["compact"] = Detail::make_unique>(); + m_factories["console"] = Detail::make_unique>(); + m_factories["junit"] = Detail::make_unique>(); + m_factories["sonarqube"] = Detail::make_unique>(); + m_factories["tap"] = Detail::make_unique>(); + m_factories["teamcity"] = Detail::make_unique>(); + m_factories["xml"] = Detail::make_unique>(); } ReporterRegistry::~ReporterRegistry() = default; diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp index 809acc0b..ec1179d3 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_stream.cpp @@ -13,19 +13,20 @@ #include #include #include +#include #include #include #include #include #include -#include namespace Catch { Catch::IStream::~IStream() = default; - namespace Detail { namespace { +namespace Detail { + namespace { template class StreamBufImpl : public std::streambuf { char data[bufferSize]; @@ -104,11 +105,11 @@ namespace Catch { /////////////////////////////////////////////////////////////////////////// class DebugOutStream : public IStream { - std::unique_ptr> m_streamBuf; + Detail::unique_ptr> m_streamBuf; mutable std::ostream m_os; public: DebugOutStream() - : m_streamBuf( std::make_unique>() ), + : m_streamBuf( Detail::make_unique>() ), m_os( m_streamBuf.get() ) {} @@ -118,7 +119,8 @@ namespace Catch { std::ostream& stream() const override { return m_os; } }; - }} // namespace anon::detail + } // unnamed namespace +} // namespace Detail /////////////////////////////////////////////////////////////////////////// @@ -138,13 +140,13 @@ namespace Catch { // This class encapsulates the idea of a pool of ostringstreams that can be reused. struct StringStreams { - std::vector> m_streams; + std::vector> m_streams; std::vector m_unused; std::ostringstream m_referenceStream; // Used for copy state/ flags from auto add() -> std::size_t { if( m_unused.empty() ) { - m_streams.push_back( std::unique_ptr( new std::ostringstream ) ); + m_streams.push_back( Detail::unique_ptr( new std::ostringstream ) ); return m_streams.size()-1; } else { diff --git a/src/catch2/internal/catch_template_test_registry.hpp b/src/catch2/internal/catch_template_test_registry.hpp index 0873e884..b716c5f7 100644 --- a/src/catch2/internal/catch_template_test_registry.hpp +++ b/src/catch2/internal/catch_template_test_registry.hpp @@ -10,8 +10,6 @@ #include #include -#include - // GCC 5 and older do not properly handle disabling unused-variable warning // with a _Pragma. This means that we have to leak the suppression to the // user code as well :-( diff --git a/src/catch2/internal/catch_test_case_registry_impl.cpp b/src/catch2/internal/catch_test_case_registry_impl.cpp index 7d16fb50..b7ebe977 100644 --- a/src/catch2/internal/catch_test_case_registry_impl.cpp +++ b/src/catch2/internal/catch_test_case_registry_impl.cpp @@ -116,14 +116,15 @@ namespace { return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); } - void TestRegistry::registerTest(std::unique_ptr testInfo, std::unique_ptr testInvoker) { + void TestRegistry::registerTest(Detail::unique_ptr testInfo, Detail::unique_ptr testInvoker) { m_handles.emplace_back(testInfo.get(), testInvoker.get()); - m_infos.push_back(std::move(testInfo)); + m_viewed_test_infos.push_back(testInfo.get()); + m_owned_test_infos.push_back(std::move(testInfo)); m_invokers.push_back(std::move(testInvoker)); } - std::vector> const& TestRegistry::getAllInfos() const { - return m_infos; + std::vector const& TestRegistry::getAllInfos() const { + return m_viewed_test_infos; } std::vector const& TestRegistry::getAllTests() const { diff --git a/src/catch2/internal/catch_test_case_registry_impl.hpp b/src/catch2/internal/catch_test_case_registry_impl.hpp index 3d00896f..b7f49523 100644 --- a/src/catch2/internal/catch_test_case_registry_impl.hpp +++ b/src/catch2/internal/catch_test_case_registry_impl.hpp @@ -35,15 +35,19 @@ namespace Catch { public: ~TestRegistry() override = default; - virtual void registerTest( std::unique_ptr testInfo, std::unique_ptr testInvoker ); + virtual void registerTest( Detail::unique_ptr testInfo, Detail::unique_ptr testInvoker ); - std::vector> const& getAllInfos() const override; + std::vector const& getAllInfos() const override; std::vector const& getAllTests() const override; std::vector const& getAllTestsSorted( IConfig const& config ) const override; private: - std::vector> m_infos; - std::vector> m_invokers; + std::vector> m_owned_test_infos; + // Keeps a materialized vector for `getAllInfos`. + // We should get rid of that eventually (see interface note) + std::vector m_viewed_test_infos; + + std::vector> m_invokers; std::vector m_handles; mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder; mutable std::vector m_sortedFunctions; diff --git a/src/catch2/internal/catch_test_registry.cpp b/src/catch2/internal/catch_test_registry.cpp index 070fde0d..583754e2 100644 --- a/src/catch2/internal/catch_test_registry.cpp +++ b/src/catch2/internal/catch_test_registry.cpp @@ -13,11 +13,11 @@ namespace Catch { - std::unique_ptr makeTestInvoker( void(*testAsFunction)() ) { - return std::make_unique( testAsFunction ); + Detail::unique_ptr makeTestInvoker( void(*testAsFunction)() ) { + return Detail::unique_ptr( new TestInvokerAsFunction( testAsFunction )); } - AutoReg::AutoReg( std::unique_ptr invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept { + AutoReg::AutoReg( Detail::unique_ptr invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept { CATCH_TRY { getMutableRegistryHub() .registerTest( @@ -25,7 +25,8 @@ namespace Catch { extractClassName( classOrMethod ), nameAndTags, lineInfo), - std::move(invoker)); + std::move(invoker) + ); } CATCH_CATCH_ALL { // Do not throw when constructing global objects, instead register the exception to be processed later getMutableRegistryHub().registerStartupException(); diff --git a/src/catch2/internal/catch_test_registry.hpp b/src/catch2/internal/catch_test_registry.hpp index 8a027bd9..fd6d7d21 100644 --- a/src/catch2/internal/catch_test_registry.hpp +++ b/src/catch2/internal/catch_test_registry.hpp @@ -12,8 +12,7 @@ #include #include #include - -#include +#include // GCC 5 and older do not properly handle disabling unused-variable warning // with a _Pragma. This means that we have to leak the suppression to the @@ -38,11 +37,11 @@ public: } }; -std::unique_ptr makeTestInvoker( void(*testAsFunction)() ); +Detail::unique_ptr makeTestInvoker( void(*testAsFunction)() ); template -std::unique_ptr makeTestInvoker( void (C::*testAsMethod)() ) { - return std::make_unique>( testAsMethod ); +Detail::unique_ptr makeTestInvoker( void (C::*testAsMethod)() ) { + return Detail::unique_ptr( new TestInvokerAsMethod(testAsMethod) ); } struct NameAndTags { @@ -54,7 +53,7 @@ struct NameAndTags { }; struct AutoReg : NonCopyable { - AutoReg( std::unique_ptr invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept; + AutoReg( Detail::unique_ptr invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept; }; } // end namespace Catch diff --git a/src/catch2/internal/catch_test_spec_parser.cpp b/src/catch2/internal/catch_test_spec_parser.cpp index db8812b9..d82cb5e0 100644 --- a/src/catch2/internal/catch_test_spec_parser.cpp +++ b/src/catch2/internal/catch_test_spec_parser.cpp @@ -199,9 +199,9 @@ namespace Catch { if (!token.empty()) { if (m_exclusion) { - m_currentFilter.m_forbidden.emplace_back(std::make_unique(token, m_substring)); + m_currentFilter.m_forbidden.emplace_back(Detail::make_unique(token, m_substring)); } else { - m_currentFilter.m_required.emplace_back(std::make_unique(token, m_substring)); + m_currentFilter.m_required.emplace_back(Detail::make_unique(token, m_substring)); } } m_substring.clear(); @@ -218,17 +218,17 @@ namespace Catch { if (token.size() > 1 && token[0] == '.') { token.erase(token.begin()); if (m_exclusion) { - m_currentFilter.m_forbidden.emplace_back(std::make_unique(".", m_substring)); - m_currentFilter.m_forbidden.emplace_back(std::make_unique(token, m_substring)); + m_currentFilter.m_forbidden.emplace_back(Detail::make_unique(".", m_substring)); + m_currentFilter.m_forbidden.emplace_back(Detail::make_unique(token, m_substring)); } else { - m_currentFilter.m_required.emplace_back(std::make_unique(".", m_substring)); - m_currentFilter.m_required.emplace_back(std::make_unique(token, m_substring)); + m_currentFilter.m_required.emplace_back(Detail::make_unique(".", m_substring)); + m_currentFilter.m_required.emplace_back(Detail::make_unique(token, m_substring)); } } if (m_exclusion) { - m_currentFilter.m_forbidden.emplace_back(std::make_unique(token, m_substring)); + m_currentFilter.m_forbidden.emplace_back(Detail::make_unique(token, m_substring)); } else { - m_currentFilter.m_required.emplace_back(std::make_unique(token, m_substring)); + m_currentFilter.m_required.emplace_back(Detail::make_unique(token, m_substring)); } } m_substring.clear(); diff --git a/src/catch2/reporters/catch_reporter_bases.cpp b/src/catch2/reporters/catch_reporter_bases.cpp index abb47e68..3534ce4d 100644 --- a/src/catch2/reporters/catch_reporter_bases.cpp +++ b/src/catch2/reporters/catch_reporter_bases.cpp @@ -17,7 +17,6 @@ #include #include #include -#include namespace Catch { void prepareExpandedExpression(AssertionResult& result) { diff --git a/src/catch2/reporters/catch_reporter_console.hpp b/src/catch2/reporters/catch_reporter_console.hpp index 5ee9663c..56c7231a 100644 --- a/src/catch2/reporters/catch_reporter_console.hpp +++ b/src/catch2/reporters/catch_reporter_console.hpp @@ -9,6 +9,7 @@ #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_H_INCLUDED #include +#include #if defined(_MSC_VER) #pragma warning(push) @@ -24,7 +25,7 @@ namespace Catch { class TablePrinter; struct ConsoleReporter : StreamingReporterBase { - std::unique_ptr m_tablePrinter; + Detail::unique_ptr m_tablePrinter; ConsoleReporter(ReporterConfig const& config); ~ConsoleReporter() override; diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index 81f5a811..169cac82 100644 --- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -313,7 +313,7 @@ TEST_CASE("GENERATE capture macros", "[generators][internals][approvals]") { non_copyable nc; nc.value = value; // neither `GENERATE_COPY` nor plain `GENERATE` would compile here - auto value2 = GENERATE_REF(Catch::Generators::GeneratorWrapper(std::unique_ptr>(new TestGen(nc)))); + auto value2 = GENERATE_REF(Catch::Generators::GeneratorWrapper(Catch::Detail::make_unique(nc))); REQUIRE(value == value2); } diff --git a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp index 966bebed..b50a4012 100644 --- a/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/ToString.tests.cpp @@ -34,7 +34,7 @@ TEST_CASE( "parseEnums", "[Strings][enums]" ) { TEST_CASE( "Directly creating an EnumInfo" ) { using namespace Catch::Detail; - std::unique_ptr enumInfo = makeEnumInfo( "EnumName", "EnumName::Value1, EnumName::Value2", {0, 1} ); + auto enumInfo = makeEnumInfo( "EnumName", "EnumName::Value1, EnumName::Value2", {0, 1} ); CHECK( enumInfo->lookup(0) == "Value1" ); CHECK( enumInfo->lookup(1) == "Value2" ); diff --git a/tests/SelfTest/UsageTests/Misc.tests.cpp b/tests/SelfTest/UsageTests/Misc.tests.cpp index 8203f730..c3e39161 100644 --- a/tests/SelfTest/UsageTests/Misc.tests.cpp +++ b/tests/SelfTest/UsageTests/Misc.tests.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace { namespace MiscTests {