forked from Alepha/Alepha
Retire the non-universal legacy cases.
This commit is contained in:
@ -648,175 +648,6 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
|
||||
using args_type= Meta::product_type_decay_t< typename function_traits_type::args_type >;
|
||||
using return_type= typename function_traits_type::return_type;
|
||||
|
||||
// The classic table-test engine would only support `Cases` which were run-and-test-value
|
||||
// without the ability to test exceptions. The `ExceptionCases` construct was used to
|
||||
// test throwing cases.
|
||||
//
|
||||
// A unified `Cases` type is forthcoming, and thus `ExecutionCases` exists for backwards
|
||||
// compatibility.
|
||||
struct ExecutionCases
|
||||
{
|
||||
using TestDescription= std::tuple< std::string, args_type, return_type >;
|
||||
|
||||
std::vector< TestDescription > tests;
|
||||
|
||||
explicit
|
||||
ExecutionCases( std::initializer_list< TestDescription > initList )
|
||||
: tests( initList ) {}
|
||||
|
||||
int
|
||||
operator() () const
|
||||
{
|
||||
int failureCount= 0;
|
||||
for( const auto &[ comment, params, expected ]: tests )
|
||||
{
|
||||
if( C::debugCaseTypes ) std::cerr << boost::core::demangle( typeid( params ).name() ) << std::endl;
|
||||
breakpoint();
|
||||
const auto witness= std::apply( function, params );
|
||||
const auto result= witness == expected;
|
||||
if( not result )
|
||||
{
|
||||
std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl;
|
||||
++failureCount;
|
||||
printDebugging< outputMode >( witness, expected );
|
||||
}
|
||||
else std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl;
|
||||
}
|
||||
|
||||
return failureCount;
|
||||
}
|
||||
};
|
||||
|
||||
struct ExceptionCases_real
|
||||
{
|
||||
using Invoker= std::function< void () >;
|
||||
struct ExceptionHandler
|
||||
{
|
||||
std::function< bool ( Invoker ) > impl;
|
||||
|
||||
bool operator() ( Invoker invoker ) const { return impl( invoker ); }
|
||||
|
||||
ExceptionHandler() : impl
|
||||
{
|
||||
[]( Invoker invoker )
|
||||
{
|
||||
try
|
||||
{
|
||||
invoker();
|
||||
return true;
|
||||
}
|
||||
catch( ... ) { return false; }
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
template< typename T >
|
||||
requires( SameAs< T, std::type_identity< void > > or SameAs< T, std::nothrow_t > )
|
||||
ExceptionHandler( T ) : impl
|
||||
{
|
||||
[]( Invoker invoker )
|
||||
{
|
||||
try
|
||||
{
|
||||
invoker();
|
||||
return true;
|
||||
}
|
||||
catch( ... ) { return false; }
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
template< typename T >
|
||||
requires( not SameAs< T, void > )
|
||||
ExceptionHandler( std::type_identity< T > ) : impl
|
||||
{
|
||||
[]( Invoker invoker )
|
||||
{
|
||||
try
|
||||
{
|
||||
invoker();
|
||||
return false;
|
||||
}
|
||||
catch( const T & ) { return true; }
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
template< typename T >
|
||||
ExceptionHandler( const T exemplar ) : impl
|
||||
{
|
||||
[expected= std::string{ exemplar.what() }]( Invoker invoker )
|
||||
{
|
||||
try
|
||||
{
|
||||
invoker();
|
||||
std::cerr << " " << C::testInfo << "NOTE" << resetStyle << ": expected exception `"<< typeid( T ).name()
|
||||
<< "` wasn't thrown." << std::endl;
|
||||
return false;
|
||||
}
|
||||
catch( const T &ex )
|
||||
{
|
||||
const std::string witness= ex.what();
|
||||
const bool rv= witness == expected;
|
||||
if( not rv )
|
||||
{
|
||||
std::cerr << " " << C::testInfo << "NOTE" << resetStyle << ": expected exception `"<< typeid( T ).name()
|
||||
<< "` wasn't thrown." << std::endl;
|
||||
printDebugging< outputMode >( witness, expected );
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
// This checker is invoked during `catch( ... )`
|
||||
ExceptionHandler( const std::function< bool () > checker ) : impl
|
||||
{
|
||||
[=]( Invoker invoker )
|
||||
{
|
||||
try
|
||||
{
|
||||
invoker();
|
||||
return false;
|
||||
}
|
||||
catch( ... ) { checker(); } // The `checker` can use `throw` to run any complex checks it needs.
|
||||
}
|
||||
}
|
||||
{}
|
||||
};
|
||||
|
||||
using TestDescription= std::tuple< std::string, args_type, ExceptionHandler >;
|
||||
|
||||
std::vector< TestDescription > tests;
|
||||
|
||||
|
||||
explicit
|
||||
ExceptionCases_real( std::initializer_list< TestDescription > initList )
|
||||
: tests( initList ) {}
|
||||
|
||||
int
|
||||
operator() () const
|
||||
{
|
||||
int failureCount= 0;
|
||||
for( const auto &[ comment, params, checker ]: tests )
|
||||
{
|
||||
if( C::debugCaseTypes ) std::cerr << boost::core::demangle( typeid( params ).name() ) << std::endl;
|
||||
breakpoint();
|
||||
auto invoker= [&]{ std::apply( function, params ); };
|
||||
const auto result= checker( invoker );
|
||||
if( not result )
|
||||
{
|
||||
std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl;
|
||||
++failureCount;
|
||||
}
|
||||
else std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl;
|
||||
}
|
||||
|
||||
return failureCount;
|
||||
}
|
||||
};
|
||||
|
||||
using ComputedBase= compute_base_t< return_type >;
|
||||
|
||||
struct UniversalCases
|
||||
|
Reference in New Issue
Block a user