Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2022-05-10 13:52:16 +0200
committerMartin Hořeňovský2022-05-10 20:57:53 +0200
commitae475a3c19e9b770e66ea3a2ce3eaa2debecd4c6 (patch)
treeb748885b23761ddf0a481df47ddb6a0b739be331
parentd60fbe49be5737d2a01f67ff54f8dca37253a20c (diff)
downloadcatch3-ae475a3c19e9b770e66ea3a2ce3eaa2debecd4c6.tar.gz
Optional support for listener descriptions
-rw-r--r--src/catch2/reporters/catch_reporter_registrars.hpp41
1 files changed, 34 insertions, 7 deletions
diff --git a/src/catch2/reporters/catch_reporter_registrars.hpp b/src/catch2/reporters/catch_reporter_registrars.hpp
index 31ecb080..19d97b3b 100644
--- a/src/catch2/reporters/catch_reporter_registrars.hpp
+++ b/src/catch2/reporters/catch_reporter_registrars.hpp
@@ -14,9 +14,23 @@
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
+#include <catch2/internal/catch_void_type.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 {};
+ }
+
class IEventListener;
using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
@@ -45,20 +59,33 @@ namespace Catch {
class ListenerRegistrar {
class TypedListenerFactory : public EventListenerFactory {
+ StringRef m_defaultDescription;
+
+ std::string getDescriptionImpl( std::true_type ) const {
+ return T::getDescription();
+ }
- IEventListenerPtr
- create( IConfig const* config ) const override {
- return Detail::make_unique<T>(config);
+ std::string getDescriptionImpl( std::false_type ) const {
+ return static_cast<std::string>(m_defaultDescription);
}
+
+ public:
+ TypedListenerFactory( StringRef defaultDescription ):
+ m_defaultDescription( defaultDescription ) {}
+
+ IEventListenerPtr create( IConfig const* config ) const override {
+ return Detail::make_unique<T>( config );
+ }
+
std::string getDescription() const override {
- return std::string();
+ return getDescriptionImpl( Detail::has_description<T>{} );
}
};
public:
- ListenerRegistrar() {
- getMutableRegistryHub().registerListener( Detail::make_unique<TypedListenerFactory>() );
+ ListenerRegistrar(StringRef defaultDescription) {
+ getMutableRegistryHub().registerListener( Detail::make_unique<TypedListenerFactory>(defaultDescription) );
}
};
}
@@ -74,7 +101,7 @@ namespace Catch {
#define CATCH_REGISTER_LISTENER( listenerType ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
- namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
+ namespace { Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType(#listenerType); } \
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#else // CATCH_CONFIG_DISABLE