diff --git a/Testing/TableTest.h b/Testing/TableTest.h index 4f08a8e..05d506e 100644 --- a/Testing/TableTest.h +++ b/Testing/TableTest.h @@ -28,6 +28,8 @@ static_assert( __cplusplus > 2020'99 ); #include +#include + #include "colors.h" #include "printDebugging.h" @@ -58,6 +60,15 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m template< typename T > using compute_base_t= typename decltype( compute_base_f< std::decay_t< T > >() )::type; + template< typename T > + requires( DerivedFrom< T, std::exception > or DerivedFrom< T, Alepha::Exception > ) + std::string + getMessageFromException( const T &ex ) + { + if constexpr( DerivedFrom< T, std::exception > ) return ex.what(); + else return ex.message(); + } + template< typename return_type, OutputMode outputMode > struct BasicUniversalHandler : compute_base_t< return_type > @@ -208,10 +219,11 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m } {} - template< DerivedFrom< std::exception > T > + template< typename T > + requires( DerivedFrom< T, std::exception > or DerivedFrom< T, Alepha::Exception > ) BasicUniversalHandler( const T exemplar ) : impl { - [expected= std::string{ exemplar.what() }]( Invoker invoker, const std::string &comment ) -> std::tuple< TestResult, std::optional< std::string > > + [expected= getMessageFromException( exemplar )]( Invoker invoker, const std::string &comment ) -> std::tuple< TestResult, std::optional< std::string > > { try { @@ -223,7 +235,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m } catch( const T &ex ) { - const std::string witness= ex.what(); + const std::string witness= getMessageFromException( ex ); const TestResult rv= witness == expected ? TestResult::Passed : TestResult::Failed; std::ostringstream oss; if( rv == TestResult::Failed ) @@ -239,6 +251,11 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m return { TestResult::Failed, IOStreams::String() << "Incorrect exception type " << Utility::fancyTypeName( typeid( ex ) ) << " was thrown, but " << Utility::fancyTypeName< T >() << " was expected." }; } + catch( const Exception &ex ) + { + return { TestResult::Failed, IOStreams::String() << "Incorrect exception type " << Utility::fancyTypeName( typeid( ex ) ) << " was thrown, but " + << Utility::fancyTypeName< T >() << " was expected." }; + } catch( ... ) { return { TestResult::Failed, IOStreams::String() << "Incorrect exception type () was thrown, but "