diff --git a/Testing/TableTest.h b/Testing/TableTest.h index f3377e7..5834ad7 100644 --- a/Testing/TableTest.h +++ b/Testing/TableTest.h @@ -60,24 +60,17 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test using compute_base_t= typename decltype( compute_base_f< std::decay_t< T > >() )::type; template< typename return_type, OutputMode outputMode > - struct BasicUniversalHandler; - - template< Primitive return_type, OutputMode outputMode > - struct BasicUniversalHandler< return_type, outputMode > + struct BasicUniversalHandler + : compute_base_t< return_type > { + using ComputedBase= compute_base_t< return_type >; + using ComputedBase::ComputedBase; + using Invoker= std::function< return_type () >; + std::function< TestResult ( Invoker, const std::string & ) > impl; - TestResult - operator() ( Invoker invoker, const std::string &comment ) const - { - return impl( invoker, comment ); - //if constexpr( std::is_base_of_v< std::decay_t< return_type >, ComputedBase > ) - } - -#if 1 - BasicUniversalHandler( const return_type expected ) - : impl + BasicUniversalHandler( const return_type expected ) : impl { [expected]( Invoker invoker, const std::string &comment ) { @@ -93,7 +86,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test } }; const auto result= witness == expected ? TestResult::Passed : TestResult::Failed; - + if( result == TestResult::Failed ) { if( witness.has_value() ) @@ -108,100 +101,12 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test } } {} -#endif - -#if 1 - template< typename T > - requires( not SameAs< T, void > ) - BasicUniversalHandler( std::type_identity< T > ) : impl - { - []( Invoker invoker, const std::string &comment ) - { - try - { - std::ignore= invoker(); - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - return TestResult::Failed; - } - catch( const T & ) - { - std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl; - return TestResult::Passed; - } - } - } - {} - - 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( ... ) - { - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - return TestResult::Failed; - } - } - } - {} - - template< DerivedFrom< std::exception > T > - BasicUniversalHandler( const T exemplar ) : impl - { - [expected= std::string{ exemplar.what() }]( Invoker invoker, const std::string &comment ) - { - try - { - invoker(); - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - std::cout << " " << C::testInfo << "NOTE" << resetStyle << ": expected exception `" - << typeid( T ).name() - << "` wasn't thrown." << std::endl; - return TestResult::Failed; - } - catch( const T &ex ) - { - const std::string witness= ex.what(); - const TestResult rv= witness == expected ? TestResult::Passed : TestResult::Failed; - if( rv == TestResult::Failed ) - { - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - std::cout << " " << C::testInfo << "NOTE" << resetStyle << ": expected message did not match." << std::endl; - printDebugging< outputMode >( witness, expected ); - } - return rv; - } - } - } - {} -#endif - }; - - template< Aggregate return_type, OutputMode outputMode > - struct BasicUniversalHandler< return_type, outputMode > - : compute_base_t< return_type > - { - using ComputedBase= compute_base_t< return_type >; - using ComputedBase::ComputedBase; - - using Invoker= std::function< return_type () >; - - std::function< TestResult ( Invoker, const std::string & ) > impl; TestResult operator() ( Invoker invoker, const std::string &comment ) const { if( impl != nullptr ) return impl( invoker, comment ); - //if constexpr( std::is_base_of_v< std::decay_t< return_type >, ComputedBase > ) - if constexpr( true ) + if constexpr( std::is_base_of_v< std::decay_t< return_type >, ComputedBase > ) { const return_type *const expected_p= this; const auto expected= *expected_p; @@ -234,7 +139,6 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test else throw std::logic_error( "Somehow we didn't setup impl, and it's not an adapted case!" ); } -#if 1 template< typename T > requires( not SameAs< T, void > ) BasicUniversalHandler( std::type_identity< T > ) : impl @@ -307,135 +211,8 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test } } {} -#endif }; - template< typename return_type, OutputMode outputMode > - struct BasicUniversalHandler - : return_type - { - using return_type::return_type; - - BasicUniversalHandler( return_type rt ) : return_type( rt ) {} - - using Invoker= std::function< return_type () >; - - std::function< TestResult ( Invoker, const std::string & ) > impl; - - TestResult - operator() ( Invoker invoker, const std::string &comment ) const - { - if( impl != nullptr ) return impl( invoker, comment ); - //if constexpr( std::is_base_of_v< std::decay_t< return_type >, ComputedBase > ) - if constexpr( true ) - { - const return_type *const expected_p= this; - const auto expected= *expected_p; - const auto witness= Utility::evaluate <=[&]() -> std::optional< return_type > - { - try - { - return invoker(); - } - catch( ... ) - { - return std::nullopt; - } - }; - const auto result= witness == expected ? TestResult::Passed : TestResult::Failed; - - if( result == TestResult::Failed ) - { - if( witness.has_value() ) - { - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - printDebugging< outputMode >( witness.value(), expected ); - } - else std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": Unexpected exception in \"" << comment << '"' << std::endl; - } - else std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl; - return result; - } - else throw std::logic_error( "Somehow we didn't setup impl, and it's not an adapted case!" ); - } - -#if 1 - template< typename T > - requires( not SameAs< T, void > ) - BasicUniversalHandler( std::type_identity< T > ) : impl - { - []( Invoker invoker, const std::string &comment ) - { - try - { - std::ignore= invoker(); - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - return TestResult::Failed; - } - catch( const T & ) - { - std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl; - return TestResult::Passed; - } - } - } - {} - - 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( ... ) - { - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - return TestResult::Failed; - } - } - } - {} - - template< DerivedFrom< std::exception > T > - BasicUniversalHandler( const T exemplar ) : impl - { - [expected= std::string{ exemplar.what() }]( Invoker invoker, const std::string &comment ) - { - try - { - invoker(); - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - std::cout << " " << C::testInfo << "NOTE" << resetStyle << ": expected exception `" - << typeid( T ).name() - << "` wasn't thrown." << std::endl; - return TestResult::Failed; - } - catch( const T &ex ) - { - const std::string witness= ex.what(); - const TestResult rv= witness == expected ? TestResult::Passed : TestResult::Failed; - if( rv == TestResult::Failed ) - { - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - std::cout << " " << C::testInfo << "NOTE" << resetStyle << ": expected message did not match." << std::endl; - printDebugging< outputMode >( witness, expected ); - } - return rv; - } - } - } - {} -#endif - }; - - - template< typename F > concept FunctionVariable= requires( const F &f ) @@ -443,7 +220,6 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test { std::function{ f } }; }; - namespace exports { template< FunctionVariable auto, OutputMode outputMode= OutputMode::All > struct TableTest; @@ -523,7 +299,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test breakpoint(); return std::apply( function, params ); }; - const TestResult result= checker( invoker, comment ); + const auto result= checker( invoker, comment ); if( result == TestResult::Failed ) { std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl;