forked from Alepha/Alepha
Better error messages in certain exception test situations.
This commit is contained in:
@ -28,6 +28,8 @@ static_assert( __cplusplus > 2020'99 );
|
|||||||
|
|
||||||
#include <Alepha/Console.h>
|
#include <Alepha/Console.h>
|
||||||
|
|
||||||
|
#include <Alepha/Exception.h>
|
||||||
|
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
#include "printDebugging.h"
|
#include "printDebugging.h"
|
||||||
|
|
||||||
@ -58,6 +60,15 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
|
|||||||
template< typename T >
|
template< typename T >
|
||||||
using compute_base_t= typename decltype( compute_base_f< std::decay_t< T > >() )::type;
|
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 >
|
template< typename return_type, OutputMode outputMode >
|
||||||
struct BasicUniversalHandler
|
struct BasicUniversalHandler
|
||||||
: compute_base_t< return_type >
|
: 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
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -223,7 +235,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
|
|||||||
}
|
}
|
||||||
catch( const T &ex )
|
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;
|
const TestResult rv= witness == expected ? TestResult::Passed : TestResult::Failed;
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
if( rv == TestResult::Failed )
|
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 "
|
return { TestResult::Failed, IOStreams::String() << "Incorrect exception type " << Utility::fancyTypeName( typeid( ex ) ) << " was thrown, but "
|
||||||
<< Utility::fancyTypeName< T >() << " was expected." };
|
<< 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( ... )
|
catch( ... )
|
||||||
{
|
{
|
||||||
return { TestResult::Failed, IOStreams::String() << "Incorrect exception type (<Unknown>) was thrown, but "
|
return { TestResult::Failed, IOStreams::String() << "Incorrect exception type (<Unknown>) was thrown, but "
|
||||||
|
|||||||
Reference in New Issue
Block a user