diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 35169ad..0745782 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -1,3 +1,3 @@ add_subdirectory( TableTest.test ) -add_library( unit-test SHARED testlib.cc test.cc ) +add_library( unit-test SHARED testlib.cc test.cc TableTest.cc ) diff --git a/Testing/TableTest.h b/Testing/TableTest.h index d37ad6a..018dd16 100644 --- a/Testing/TableTest.h +++ b/Testing/TableTest.h @@ -33,7 +33,7 @@ static_assert( __cplusplus > 2020'99 ); #include "colors.h" #include "printDebugging.h" -namespace Alepha::Hydrogen::Testing ::detail:: table_test +namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m { inline namespace exports {} @@ -271,36 +271,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test virtual ~UniversalCasesBase()= default; - int - operator() () const - { - int failureCount= 0; - for( const auto &[ comment, checker ]: tests ) - { - const auto [result, supplement]= checker( comment ); - if( result == TestResult::Failed ) - { - ++failureCount; - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - if( supplement.has_value() ) - { - std::cout << " " << C::testWarn << "DETAILS" << resetStyle << ": " << supplement.value() << std::endl; - } - } - else - { - std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl; - if( supplement.has_value() ) - { - std::cout << " " << C::testWarn << "INFO: " << resetStyle << ": " << supplement.value() << std::endl; - } - } - breakpoint(); - } - - return failureCount; - } - + int operator() () const; }; template< FunctionVariable auto function, OutputMode outputMode > @@ -326,48 +297,27 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test args_type args; UniversalHandler handler; }; - std::vector< TestDescription > tests; + UniversalCasesBase tests; UniversalCases( std::initializer_list< TestDescription > initList ) - : tests( initList ) { - } - - int - operator() () const - { - int failureCount= 0; - for( const auto &[ comment, params, checker ]: tests ) + for( const auto [ comment, params, handler ]: initList ) { if( C::debugCaseTypes ) std::cerr << boost::core::demangle( typeid( params ).name() ) << std::endl; - auto invoker= [&] + auto invoker= [=] { breakpoint(); return std::apply( function, params ); }; - const auto [result, supplement]= checker( invoker, comment ); - if( result == TestResult::Failed ) + const auto checker= [=]( const auto comment ) { - ++failureCount; - std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; - if( supplement.has_value() ) - { - std::cout << " " << C::testWarn << "DETAILS" << resetStyle << ": " << supplement.value() << std::endl; - } - } - else - { - std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl; - if( supplement.has_value() ) - { - std::cout << " " << C::testWarn << "INFO: " << resetStyle << ": " << supplement.value() << std::endl; - } - } - breakpoint(); + return handler( invoker, comment ); + }; + tests.tests.push_back( { comment, checker } ); } - - return failureCount; } + + int operator() () const { return tests(); } }; // When the `UniversalCases` impl is ready to go, then this alias shim can be redirected to that form. Then I can @@ -380,7 +330,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test }; } -namespace Alepha::Hydrogen::Testing::inline exports::inline table_test +namespace Alepha::Hydrogen::Testing::inline exports::inline TableTest_m { - using namespace detail::table_test::exports; + using namespace detail::TableTest_m::exports; }