1
0
forked from Alepha/Alepha

Better error messages in certain exception test situations.

This commit is contained in:
2023-11-16 07:29:30 -05:00
parent f2de383c03
commit 4dac28a2c3

View File

@ -28,6 +28,8 @@ static_assert( __cplusplus > 2020'99 );
#include <Alepha/Console.h>
#include <Alepha/Exception.h>
#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 (<Unknown>) was thrown, but "