1
0
forked from Alepha/Alepha

Permit std::nothrow_t for no throwing cases, in addition to std::type_identity< void >.

This commit is contained in:
2023-10-28 11:59:23 -04:00
parent 48549ff465
commit bca067add4
2 changed files with 95 additions and 5 deletions

View File

@ -129,8 +129,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
{}
#endif
#if 0
#if 1
template< typename T >
requires( not SameAs< T, void > )
BasicUniversalHandler( std::type_identity< T > ) : impl
{
[]( Invoker invoker, const std::string &comment )
@ -150,6 +151,27 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
}
{}
template< typename T >
requires( SameAs< T, std::type_identity< void > > or SameAs< T, std::nothrow_t > )
BasicUniversalHandler( T ) : impl
{
[]( Invoker invoker, const std::string &comment )
{
try
{
std::ignore= invoker();
std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl;
return TestResult::Passed;
}
catch( const T & )
{
std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl;
return TestResult::Failed;
}
}
}
{}
template< DerivedFrom< std::exception > T >
BasicUniversalHandler( const T exemplar ) : impl
{
@ -251,6 +273,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
#if 0
template< typename T >
requires( not SameAs< T, void > )
BasicUniversalHandler( std::type_identity< T > ) : impl
{
[]( Invoker invoker, const std::string &comment )
@ -270,6 +293,27 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
}
{}
template< typename T >
requires( SameAs< T, std::type_identity< void > > or SameAs< T, std::nothrow_t > )
BasicUniversalHandler( T ) : impl
{
[]( Invoker invoker, const std::string &comment )
{
try
{
std::ignore= invoker();
std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl;
return TestResult::Passed;
}
catch( const T & )
{
std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl;
return TestResult::Failed;
}
}
}
{}
template< DerivedFrom< std::exception > T >
BasicUniversalHandler( const T exemplar ) : impl
{
@ -370,8 +414,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
{}
#endif
#if 0
#if 1
template< typename T >
requires( not SameAs< T, void > )
BasicUniversalHandler( std::type_identity< T > ) : impl
{
[]( Invoker invoker, const std::string &comment )
@ -391,6 +436,27 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
}
{}
template< typename T >
requires( SameAs< T, std::type_identity< void > > or SameAs< T, std::nothrow_t > )
BasicUniversalHandler( T ) : impl
{
[]( Invoker invoker, const std::string &comment )
{
try
{
std::ignore= invoker();
std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl;
return TestResult::Passed;
}
catch( const T & )
{
std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl;
return TestResult::Failed;
}
}
}
{}
template< DerivedFrom< std::exception > T >
BasicUniversalHandler( const T exemplar ) : impl
{
@ -660,7 +726,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
}
};
struct ExceptionCases
struct ExceptionCases_real
{
using Invoker= std::function< void () >;
struct ExceptionHandler
@ -684,6 +750,23 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
{}
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( const T & ) { return false; }
}
}
{}
template< typename T >
requires( not SameAs< T, void > )
ExceptionHandler( std::type_identity< T > ) : impl
{
[]( Invoker invoker )
@ -748,7 +831,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
explicit
ExceptionCases( std::initializer_list< TestDescription > initList )
ExceptionCases_real( std::initializer_list< TestDescription > initList )
: tests( initList ) {}
int
@ -814,6 +897,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
// retire the `ExceptionCases` and `ExecutionCases` forms and replace them with an alias to `UniversalCases`.
using Cases= ExecutionCases;
//using Cases= UniversalCases;
using ExceptionCases= ExceptionCases_real;
//using ExceptionCases= UniversalCases;
};
#ifdef DISABLED

View File

@ -42,7 +42,11 @@ static auto init= enroll <=[]
{
{ "Complete var",
{ "$H$ $W$", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' },
{}
std::nothrow
},
{ "Complete var",
{ "$H$ $W$", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' },
std::type_identity< void >{}
},
{ "Incomplete var",
{ "$H$ $W", { { "H", lambaste<="Hello" }, { "W", lambaste<="World" } }, '$' },