Replace all uses of std::unique_ptr with Catch::Detail::unique_ptr

Doing some benchmarking with ClangBuildAnalyzer suggests that
compiling Catch2's `SelfTest` spends 10% of the time instantiating
`std::unique_ptr` for some interface types required for registering
and running tests.

The lesser compilation overhead of `Catch::Detail::unique_ptr` should
significantly reduce that time.

The compiled implementation was also changed to use the custom impl,
to avoid having to convert between using `std::unique_ptr` and
`Catch::Detail::unique_ptr`. This will likely also improve the compile
times of the implementation, but that is less important than improving
compilation times of the user's TUs with tests.
This commit is contained in:
Martin Hořeňovský 2020-05-25 09:45:24 +02:00
parent 41bbaa6d57
commit 1d1ccf8f3c
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
38 changed files with 141 additions and 125 deletions

View File

@ -43,7 +43,9 @@ int const& RandomIntGenerator::get() const {
// is a value-wrapper around std::unique_ptr<IGenerator<int>>.
Catch::Generators::GeneratorWrapper<int> random(int low, int high) {
return Catch::Generators::GeneratorWrapper<int>(
std::make_unique<RandomIntGenerator>(low, high)
new RandomIntGenerator(low, high)
// Another possibility:
// Catch::Detail::make_unique<RandomIntGenerator>(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<int>(std::unique_ptr<IGenerator<int>>(new RandomIntGenerator(-100, 100)))));
auto i = GENERATE(take(100, GeneratorWrapper<int>(Catch::Detail::make_unique<RandomIntGenerator>(-100, 100))));
REQUIRE(i >= -100);
REQUIRE(i <= 100);
}

View File

@ -40,7 +40,7 @@ std::string const& LineGenerator::get() const {
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
Catch::Generators::GeneratorWrapper<std::string> lines(std::string /* ignored for example */) {
return Catch::Generators::GeneratorWrapper<std::string>(
std::make_unique<LineGenerator>()
new LineGenerator()
);
}

View File

@ -14,11 +14,11 @@
#include <catch2/benchmark/catch_chronometer.hpp>
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
#include <catch2/internal/catch_meta.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <cassert>
#include <type_traits>
#include <utility>
#include <memory>
namespace Catch {
namespace Benchmark {
@ -100,7 +100,7 @@ namespace Catch {
void operator()(Chronometer meter) const { f->call(meter); }
private:
std::unique_ptr<callable> f;
Catch::Detail::unique_ptr<callable> f;
};
} // namespace Detail
} // namespace Benchmark

View File

@ -10,8 +10,8 @@
#include <catch2/catch_test_spec.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <memory>
#include <vector>
#include <string>
@ -116,7 +116,7 @@ namespace Catch {
IStream const* openStream();
ConfigData m_data;
std::unique_ptr<IStream const> m_stream;
Detail::unique_ptr<IStream const> m_stream;
TestSpec m_testSpec;
bool m_hasTestFilters = false;
};

View File

@ -49,7 +49,7 @@ namespace Catch {
void registerListener( IReporterFactoryPtr factory ) override {
m_reporterRegistry.registerListener( std::move(factory) );
}
void registerTest( std::unique_ptr<TestCaseInfo>&& testInfo, std::unique_ptr<ITestInvoker>&& invoker ) override {
void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override {
m_testCaseRegistry.registerTest( std::move(testInfo), std::move(invoker) );
}
void registerTranslator( const IExceptionTranslator* translator ) override {

View File

@ -10,6 +10,7 @@
#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
namespace Catch {
@ -17,7 +18,7 @@ namespace Catch {
class ReporterFactory : public IReporterFactory {
IStreamingReporterPtr create( ReporterConfig const& config ) const override {
return std::make_unique<T>( config );
return Detail::make_unique<T>( 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<ReporterFactory<T>>() );
getMutableRegistryHub().registerReporter( name, Detail::make_unique<ReporterFactory<T>>() );
}
};
@ -40,7 +41,7 @@ namespace Catch {
class ListenerFactory : public IReporterFactory {
IStreamingReporterPtr create( ReporterConfig const& config ) const override {
return std::make_unique<T>(config);
return Detail::make_unique<T>(config);
}
std::string getDescription() const override {
return std::string();
@ -50,7 +51,7 @@ namespace Catch {
public:
ListenerRegistrar() {
getMutableRegistryHub().registerListener( std::make_unique<ListenerFactory>() );
getMutableRegistryHub().registerListener( Detail::make_unique<ListenerFactory>() );
}
};
}

View File

@ -44,12 +44,12 @@ namespace Catch {
return createReporter(config->getReporterName(), config);
}
// On older platforms, returning std::unique_ptr<ListeningReporter>
// when the return type is std::unique_ptr<IStreamingReporter>
// On older platforms, returning unique_ptr<ListeningReporter>
// when the return type is unique_ptr<IStreamingReporter>
// 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<IStreamingReporter>(new ListeningReporter);
auto ret = Detail::unique_ptr<IStreamingReporter>(new ListeningReporter);
auto& multi = static_cast<ListeningReporter&>(*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<Config>( m_configData );
m_config = Detail::make_unique<Config>( m_configData );
return *m_config;
}

View File

@ -11,8 +11,7 @@
#include <catch2/internal/catch_commandline.hpp>
#include <catch2/catch_config.hpp>
#include <catch2/internal/catch_text.hpp>
#include <memory>
#include <catch2/internal/catch_unique_ptr.hpp>
namespace Catch {
@ -53,7 +52,7 @@ namespace Catch {
clara::Parser m_cli;
ConfigData m_configData;
std::unique_ptr<Config> m_config;
Detail::unique_ptr<Config> m_config;
bool m_startupExceptions = false;
};

View File

@ -105,11 +105,11 @@ namespace Catch {
}
}
std::unique_ptr<TestCaseInfo>
Detail::unique_ptr<TestCaseInfo>
makeTestCaseInfo(std::string const& _className,
NameAndTags const& nameAndTags,
SourceLineInfo const& _lineInfo ) {
return std::make_unique<TestCaseInfo>(_className, nameAndTags, _lineInfo);
return Detail::unique_ptr<TestCaseInfo>(new TestCaseInfo(_className, nameAndTags, _lineInfo));
}
TestCaseInfo::TestCaseInfo(std::string const& _className,

View File

@ -11,10 +11,11 @@
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_test_registry.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <string>
#include <vector>
#include <memory>
#ifdef __clang__
#pragma clang diagnostic push
@ -90,7 +91,7 @@ namespace Catch {
bool operator < ( TestCaseHandle const& rhs ) const;
};
std::unique_ptr<TestCaseInfo> makeTestCaseInfo( std::string const& className,
Detail::unique_ptr<TestCaseInfo> makeTestCaseInfo( std::string const& className,
NameAndTags const& nameAndTags,
SourceLineInfo const& lineInfo );
}

View File

@ -13,7 +13,6 @@
#include <algorithm>
#include <string>
#include <vector>
#include <memory>
namespace Catch {

View File

@ -13,11 +13,11 @@
#pragma clang diagnostic ignored "-Wpadded"
#endif
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_wildcard_pattern.hpp>
#include <string>
#include <vector>
#include <memory>
namespace Catch {
@ -54,8 +54,8 @@ namespace Catch {
};
struct Filter {
std::vector<std::unique_ptr<Pattern>> m_required;
std::vector<std::unique_ptr<Pattern>> m_forbidden;
std::vector<Detail::unique_ptr<Pattern>> m_required;
std::vector<Detail::unique_ptr<Pattern>> m_forbidden;
bool matches( TestCaseInfo const& testCase ) const;
std::string name() const;

View File

@ -10,7 +10,6 @@
#include <catch2/interfaces/catch_interfaces_generatortracker.hpp>
#include <catch2/internal/catch_common.hpp>
#include <memory>
#include <vector>
#include <tuple>
#include <utility>
@ -43,11 +42,35 @@ namespace Detail {
using type = T;
};
template <typename T>
using GeneratorPtr = Catch::Detail::unique_ptr<IGenerator<T>>;
template <typename T>
class GeneratorWrapper final {
GeneratorPtr<T> m_generator;
public:
//! Takes ownership of the passed pointer.
GeneratorWrapper(IGenerator<T>* generator):
m_generator(generator) {}
GeneratorWrapper(GeneratorPtr<T> generator):
m_generator(std::move(generator)) {}
T const& get() const {
return m_generator->get();
}
bool next() {
return m_generator->next();
}
};
template<typename T>
class SingleValueGenerator final : public IGenerator<T> {
T m_value;
public:
SingleValueGenerator(T&& value) : m_value(std::move(value)) {}
SingleValueGenerator(T&& value):
m_value(std::forward<T>(value))
{}
T const& get() const override {
return m_value;
@ -76,28 +99,13 @@ namespace Detail {
}
};
template <typename T>
class GeneratorWrapper final {
std::unique_ptr<IGenerator<T>> m_generator;
public:
GeneratorWrapper(std::unique_ptr<IGenerator<T>> generator):
m_generator(std::move(generator))
{}
T const& get() const {
return m_generator->get();
}
bool next() {
return m_generator->next();
}
};
template <typename T>
GeneratorWrapper<T> value(T&& value) {
return GeneratorWrapper<T>(std::make_unique<SingleValueGenerator<T>>(std::forward<T>(value)));
return GeneratorWrapper<T>(Catch::Detail::make_unique<SingleValueGenerator<T>>(std::forward<T>(value)));
}
template <typename T>
GeneratorWrapper<T> values(std::initializer_list<T> values) {
return GeneratorWrapper<T>(std::make_unique<FixedValuesGenerator<T>>(values));
return GeneratorWrapper<T>(Catch::Detail::make_unique<FixedValuesGenerator<T>>(values));
}
template<typename T>
@ -182,7 +190,7 @@ namespace Detail {
IGeneratorTracker& tracker = acquireGeneratorTracker( lineInfo );
if (!tracker.hasGenerator()) {
tracker.setGenerator(std::make_unique<Generators<UnderlyingType>>(generatorExpression()));
tracker.setGenerator(Catch::Detail::make_unique<Generators<UnderlyingType>>(generatorExpression()));
}
auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker.getGenerator() );

View File

@ -46,7 +46,7 @@ namespace Generators {
template <typename T>
GeneratorWrapper<T> take(size_t target, GeneratorWrapper<T>&& generator) {
return GeneratorWrapper<T>(std::make_unique<TakeGenerator<T>>(target, std::move(generator)));
return GeneratorWrapper<T>(Catch::Detail::make_unique<TakeGenerator<T>>(target, std::move(generator)));
}
@ -87,7 +87,7 @@ namespace Generators {
template <typename T, typename Predicate>
GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {
return GeneratorWrapper<T>(std::unique_ptr<IGenerator<T>>(std::make_unique<FilterGenerator<T, Predicate>>(std::forward<Predicate>(pred), std::move(generator))));
return GeneratorWrapper<T>(Catch::Detail::make_unique<FilterGenerator<T, Predicate>>(std::forward<Predicate>(pred), std::move(generator)));
}
template <typename T>
@ -143,7 +143,7 @@ namespace Generators {
template <typename T>
GeneratorWrapper<T> repeat(size_t repeats, GeneratorWrapper<T>&& generator) {
return GeneratorWrapper<T>(std::make_unique<RepeatGenerator<T>>(repeats, std::move(generator)));
return GeneratorWrapper<T>(Catch::Detail::make_unique<RepeatGenerator<T>>(repeats, std::move(generator)));
}
template <typename T, typename U, typename Func>
@ -176,14 +176,14 @@ namespace Generators {
template <typename Func, typename U, typename T = FunctionReturnType<Func, U>>
GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
return GeneratorWrapper<T>(
std::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
Catch::Detail::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
);
}
template <typename T, typename U, typename Func>
GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
return GeneratorWrapper<T>(
std::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
Catch::Detail::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
);
}
@ -226,7 +226,7 @@ namespace Generators {
template <typename T>
GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) {
return GeneratorWrapper<std::vector<T>>(
std::make_unique<ChunkGenerator<T>>(size, std::move(generator))
Catch::Detail::make_unique<ChunkGenerator<T>>(size, std::move(generator))
);
}

View File

@ -67,7 +67,7 @@ std::enable_if_t<std::is_integral<T>::value && !std::is_same<T, bool>::value,
GeneratorWrapper<T>>
random(T a, T b) {
return GeneratorWrapper<T>(
std::make_unique<RandomIntegerGenerator<T>>(a, b)
Catch::Detail::make_unique<RandomIntegerGenerator<T>>(a, b)
);
}
@ -76,7 +76,7 @@ std::enable_if_t<std::is_floating_point<T>::value,
GeneratorWrapper<T>>
random(T a, T b) {
return GeneratorWrapper<T>(
std::make_unique<RandomFloatingGenerator<T>>(a, b)
Catch::Detail::make_unique<RandomFloatingGenerator<T>>(a, b)
);
}

View File

@ -52,13 +52,13 @@ public:
template <typename T>
GeneratorWrapper<T> range(T const& start, T const& end, T const& step) {
static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric");
return GeneratorWrapper<T>(std::make_unique<RangeGenerator<T>>(start, end, step));
return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end, step));
}
template <typename T>
GeneratorWrapper<T> range(T const& start, T const& end) {
static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer");
return GeneratorWrapper<T>(std::make_unique<RangeGenerator<T>>(start, end));
return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end));
}
@ -92,13 +92,13 @@ template <typename InputIterator,
typename InputSentinel,
typename ResultType = typename std::iterator_traits<InputIterator>::value_type>
GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) {
return GeneratorWrapper<ResultType>(std::make_unique<IteratorGenerator<ResultType>>(from, to));
return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(from, to));
}
template <typename Container,
typename ResultType = typename Container::value_type>
GeneratorWrapper<ResultType> from_range(Container const& cnt) {
return GeneratorWrapper<ResultType>(std::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end()));
return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end()));
}

View File

@ -10,6 +10,7 @@
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <string>
#include <vector>
@ -18,7 +19,7 @@ namespace Catch {
using exceptionTranslateFunction = std::string(*)();
struct IExceptionTranslator;
using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
using ExceptionTranslators = std::vector<Detail::unique_ptr<IExceptionTranslator const>>;
struct IExceptionTranslator {
virtual ~IExceptionTranslator();

View File

@ -8,7 +8,7 @@
#ifndef TWOBLUECUBES_CATCH_INTERFACES_GENERATORTRACKER_INCLUDED
#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORTRACKER_INCLUDED
#include <memory>
#include <catch2/internal/catch_unique_ptr.hpp>
namespace Catch {
@ -29,7 +29,7 @@ namespace Catch {
// can be retrieved).
virtual bool next() = 0;
};
using GeneratorBasePtr = std::unique_ptr<GeneratorUntypedBase>;
using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>;
} // namespace Generators

View File

@ -9,9 +9,9 @@
#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <string>
#include <memory>
namespace Catch {
@ -28,7 +28,7 @@ namespace Catch {
class StartupExceptionRegistry;
using IReporterFactoryPtr = std::unique_ptr<IReporterFactory>;
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
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<TestCaseInfo>&& testInfo, std::unique_ptr<ITestInvoker>&& invoker) = 0;
virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& 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;

View File

@ -17,6 +17,7 @@
#include <catch2/internal/catch_message_info.hpp>
#include <catch2/internal/catch_option.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/benchmark/catch_estimate.hpp>
#include <catch2/benchmark/catch_outlier_classification.hpp>
@ -25,7 +26,6 @@
#include <string>
#include <iosfwd>
#include <map>
#include <memory>
#include <algorithm>
namespace Catch {
@ -222,14 +222,14 @@ namespace Catch {
virtual void listTags(std::vector<TagInfo> const& tags, Config const& config);
};
using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
using IStreamingReporterPtr = Detail::unique_ptr<IStreamingReporter>;
struct IReporterFactory {
virtual ~IReporterFactory();
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
virtual std::string getDescription() const = 0;
};
using IReporterFactoryPtr = std::unique_ptr<IReporterFactory>;
using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
struct IReporterRegistry {
using FactoryMap = std::map<std::string, IReporterFactoryPtr>;

View File

@ -9,7 +9,6 @@
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
#include <vector>
#include <memory>
namespace Catch {
@ -26,7 +25,8 @@ namespace Catch {
struct ITestCaseRegistry {
virtual ~ITestCaseRegistry();
virtual std::vector<std::unique_ptr<TestCaseInfo>> 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<TestCaseInfo* > const& getAllInfos() const = 0;
virtual std::vector<TestCaseHandle> const& getAllTests() const = 0;
virtual std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const = 0;
};

View File

@ -51,8 +51,8 @@ namespace Catch {
return "{** unexpected enum value **}"_sr;
}
std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
auto enumInfo = std::make_unique<EnumInfo>();
Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
auto enumInfo = Catch::Detail::make_unique<EnumInfo>();
enumInfo->m_name = enumName;
enumInfo->m_values.reserve( values.size() );

View File

@ -9,19 +9,19 @@
#define TWOBLUECUBES_CATCH_ENUMVALUESREGISTRY_H_INCLUDED
#include <catch2/interfaces/catch_interfaces_enum_values_registry.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <vector>
#include <memory>
namespace Catch {
namespace Detail {
std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
class EnumValuesRegistry : public IMutableEnumValuesRegistry {
std::vector<std::unique_ptr<EnumInfo>> m_enumInfos;
std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos;
EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
};

View File

@ -17,7 +17,7 @@ namespace Catch {
}
void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) {
m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) );
m_translators.push_back( Detail::unique_ptr<const IExceptionTranslator>( translator ) );
}
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)

View File

@ -11,7 +11,6 @@
#include <catch2/interfaces/catch_interfaces_exception.hpp>
#include <vector>
#include <string>
#include <memory>
namespace Catch {
@ -23,7 +22,7 @@ namespace Catch {
std::string tryTranslators() const;
private:
std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators;
ExceptionTranslators m_translators;
};
}

View File

@ -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<ReporterFactory<AutomakeReporter>>();
m_factories["compact"] = std::make_unique<ReporterFactory<CompactReporter>>();
m_factories["console"] = std::make_unique<ReporterFactory<ConsoleReporter>>();
m_factories["junit"] = std::make_unique<ReporterFactory<JunitReporter>>();
m_factories["sonarqube"] = std::make_unique<ReporterFactory<SonarQubeReporter>>();
m_factories["tap"] = std::make_unique<ReporterFactory<TAPReporter>>();
m_factories["teamcity"] = std::make_unique<ReporterFactory<TeamCityReporter>>();
m_factories["xml"] = std::make_unique<ReporterFactory<XmlReporter>>();
m_factories["automake"] = Detail::make_unique<ReporterFactory<AutomakeReporter>>();
m_factories["compact"] = Detail::make_unique<ReporterFactory<CompactReporter>>();
m_factories["console"] = Detail::make_unique<ReporterFactory<ConsoleReporter>>();
m_factories["junit"] = Detail::make_unique<ReporterFactory<JunitReporter>>();
m_factories["sonarqube"] = Detail::make_unique<ReporterFactory<SonarQubeReporter>>();
m_factories["tap"] = Detail::make_unique<ReporterFactory<TAPReporter>>();
m_factories["teamcity"] = Detail::make_unique<ReporterFactory<TeamCityReporter>>();
m_factories["xml"] = Detail::make_unique<ReporterFactory<XmlReporter>>();
}
ReporterRegistry::~ReporterRegistry() = default;

View File

@ -13,19 +13,20 @@
#include <catch2/internal/catch_debug_console.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_singletons.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <memory>
namespace Catch {
Catch::IStream::~IStream() = default;
namespace Detail { namespace {
namespace Detail {
namespace {
template<typename WriterF, std::size_t bufferSize=256>
class StreamBufImpl : public std::streambuf {
char data[bufferSize];
@ -104,11 +105,11 @@ namespace Catch {
///////////////////////////////////////////////////////////////////////////
class DebugOutStream : public IStream {
std::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
Detail::unique_ptr<StreamBufImpl<OutputDebugWriter>> m_streamBuf;
mutable std::ostream m_os;
public:
DebugOutStream()
: m_streamBuf( std::make_unique<StreamBufImpl<OutputDebugWriter>>() ),
: m_streamBuf( Detail::make_unique<StreamBufImpl<OutputDebugWriter>>() ),
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<std::unique_ptr<std::ostringstream>> m_streams;
std::vector<Detail::unique_ptr<std::ostringstream>> m_streams;
std::vector<std::size_t> 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<std::ostringstream>( new std::ostringstream ) );
m_streams.push_back( Detail::unique_ptr<std::ostringstream>( new std::ostringstream ) );
return m_streams.size()-1;
}
else {

View File

@ -10,8 +10,6 @@
#include <catch2/internal/catch_preprocessor.hpp>
#include <catch2/internal/catch_meta.hpp>
#include <memory>
// 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 :-(

View File

@ -116,14 +116,15 @@ namespace {
return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
}
void TestRegistry::registerTest(std::unique_ptr<TestCaseInfo> testInfo, std::unique_ptr<ITestInvoker> testInvoker) {
void TestRegistry::registerTest(Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> 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<std::unique_ptr<TestCaseInfo>> const& TestRegistry::getAllInfos() const {
return m_infos;
std::vector<TestCaseInfo*> const& TestRegistry::getAllInfos() const {
return m_viewed_test_infos;
}
std::vector<TestCaseHandle> const& TestRegistry::getAllTests() const {

View File

@ -35,15 +35,19 @@ namespace Catch {
public:
~TestRegistry() override = default;
virtual void registerTest( std::unique_ptr<TestCaseInfo> testInfo, std::unique_ptr<ITestInvoker> testInvoker );
virtual void registerTest( Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> testInvoker );
std::vector<std::unique_ptr<TestCaseInfo>> const& getAllInfos() const override;
std::vector<TestCaseInfo*> const& getAllInfos() const override;
std::vector<TestCaseHandle> const& getAllTests() const override;
std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const override;
private:
std::vector<std::unique_ptr<TestCaseInfo>> m_infos;
std::vector<std::unique_ptr<ITestInvoker>> m_invokers;
std::vector<Detail::unique_ptr<TestCaseInfo>> m_owned_test_infos;
// Keeps a materialized vector for `getAllInfos`.
// We should get rid of that eventually (see interface note)
std::vector<TestCaseInfo*> m_viewed_test_infos;
std::vector<Detail::unique_ptr<ITestInvoker>> m_invokers;
std::vector<TestCaseHandle> m_handles;
mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder;
mutable std::vector<TestCaseHandle> m_sortedFunctions;

View File

@ -13,11 +13,11 @@
namespace Catch {
std::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() ) {
return std::make_unique<TestInvokerAsFunction>( testAsFunction );
Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() ) {
return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsFunction( testAsFunction ));
}
AutoReg::AutoReg( std::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept {
AutoReg::AutoReg( Detail::unique_ptr<ITestInvoker> 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();

View File

@ -12,8 +12,7 @@
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <memory>
#include <catch2/internal/catch_unique_ptr.hpp>
// 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<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
template<typename C>
std::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
return std::make_unique<TestInvokerAsMethod<C>>( testAsMethod );
Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
return Detail::unique_ptr<ITestInvoker>( new TestInvokerAsMethod<C>(testAsMethod) );
}
struct NameAndTags {
@ -54,7 +53,7 @@ struct NameAndTags {
};
struct AutoReg : NonCopyable {
AutoReg( std::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
};
} // end namespace Catch

View File

@ -199,9 +199,9 @@ namespace Catch {
if (!token.empty()) {
if (m_exclusion) {
m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::NamePattern>(token, m_substring));
m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::NamePattern>(token, m_substring));
} else {
m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::NamePattern>(token, m_substring));
m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::NamePattern>(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<TestSpec::TagPattern>(".", m_substring));
m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::TagPattern>(".", m_substring));
m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
} else {
m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(".", m_substring));
m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::TagPattern>(".", m_substring));
m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
}
}
if (m_exclusion) {
m_currentFilter.m_forbidden.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
m_currentFilter.m_forbidden.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
} else {
m_currentFilter.m_required.emplace_back(std::make_unique<TestSpec::TagPattern>(token, m_substring));
m_currentFilter.m_required.emplace_back(Detail::make_unique<TestSpec::TagPattern>(token, m_substring));
}
}
m_substring.clear();

View File

@ -17,7 +17,6 @@
#include <cstdio>
#include <ostream>
#include <cassert>
#include <memory>
namespace Catch {
void prepareExpandedExpression(AssertionResult& result) {

View File

@ -9,6 +9,7 @@
#define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_H_INCLUDED
#include <catch2/reporters/catch_reporter_bases.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#if defined(_MSC_VER)
#pragma warning(push)
@ -24,7 +25,7 @@ namespace Catch {
class TablePrinter;
struct ConsoleReporter : StreamingReporterBase {
std::unique_ptr<TablePrinter> m_tablePrinter;
Detail::unique_ptr<TablePrinter> m_tablePrinter;
ConsoleReporter(ReporterConfig const& config);
~ConsoleReporter() override;

View File

@ -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<int>(std::unique_ptr<Catch::Generators::IGenerator<int>>(new TestGen(nc))));
auto value2 = GENERATE_REF(Catch::Generators::GeneratorWrapper<int>(Catch::Detail::make_unique<TestGen>(nc)));
REQUIRE(value == value2);
}

View File

@ -34,7 +34,7 @@ TEST_CASE( "parseEnums", "[Strings][enums]" ) {
TEST_CASE( "Directly creating an EnumInfo" ) {
using namespace Catch::Detail;
std::unique_ptr<EnumInfo> 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" );

View File

@ -16,6 +16,7 @@
#include <cerrno>
#include <limits>
#include <array>
#include <tuple>
namespace { namespace MiscTests {