blob: 6763592c32516b78f0cea82580c124aff41b9c79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
#pragma once
#include <Progmasoft/Catch3/Interfaces/EventListenerFactory.hpp>
#include <Progmasoft/Catch3/Internal/CompilerCapabilities.hpp>
#include <Progmasoft/Catch3/Internal/UniqueName.hpp>
#include <Progmasoft/Catch3/Internal/UniquePtr.hpp>
#include <Progmasoft/Catch3/Internal/MoveAndForward.hpp>
#include <Progmasoft/Catch3/Internal/VoidType.hpp>
#include <type_traits>
namespace Catch {
namespace Detail {
template <typename T, typename = void>
struct has_description : std::false_type {};
template <typename T>
struct has_description<
T,
void_t<decltype( T::getDescription() )>>
: std::true_type {};
//! Actually registers the factory, independent on listener's concrete type
void registerListenerImpl( Detail::unique_ptr<EventListenerFactory> listenerFactory );
} // namespace Detail
class IEventListener;
using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
template<typename T>
class ListenerRegistrar {
class TypedListenerFactory : public EventListenerFactory {
StringRef m_listenerName;
std::string getDescriptionImpl( std::true_type ) const {
return T::getDescription();
}
std::string getDescriptionImpl( std::false_type ) const {
return "(No description provided)";
}
public:
TypedListenerFactory( StringRef listenerName ):
m_listenerName( listenerName ) {}
IEventListenerPtr create( IConfig const* config ) const override {
return Detail::make_unique<T>( config );
}
StringRef getName() const override {
return m_listenerName;
}
std::string getDescription() const override {
return getDescriptionImpl( Detail::has_description<T>{} );
}
};
public:
ListenerRegistrar(StringRef listenerName) {
registerListenerImpl( Detail::make_unique<TypedListenerFactory>(listenerName) );
}
};
}
#if !defined(CATCH_CONFIG_DISABLE)
# define CATCH_REGISTER_LISTENER( listenerType ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace { \
const Catch::ListenerRegistrar<listenerType> \
INTERNAL_CATCH_UNIQUE_NAME( catch_internal_RegistrarFor )( \
#listenerType##_catch_sr ); \
} \
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#else // CATCH_CONFIG_DISABLE
#define CATCH_REGISTER_LISTENER(listenerType)
#endif // CATCH_CONFIG_DISABLE
|