1
0
forked from Alepha/Alepha

Type erased much of TableTest.

This will let us adjust the output with fewer rebuilds.
This commit is contained in:
2023-11-11 18:53:50 -05:00
parent c9f7e9cbc3
commit 57511b2588
2 changed files with 14 additions and 64 deletions

View File

@ -1,3 +1,3 @@
add_subdirectory( TableTest.test ) add_subdirectory( TableTest.test )
add_library( unit-test SHARED testlib.cc test.cc ) add_library( unit-test SHARED testlib.cc test.cc TableTest.cc )

View File

@ -33,7 +33,7 @@ static_assert( __cplusplus > 2020'99 );
#include "colors.h" #include "colors.h"
#include "printDebugging.h" #include "printDebugging.h"
namespace Alepha::Hydrogen::Testing ::detail:: table_test namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
{ {
inline namespace exports {} inline namespace exports {}
@ -271,36 +271,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
virtual ~UniversalCasesBase()= default; virtual ~UniversalCasesBase()= default;
int int operator() () const;
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;
}
}; };
template< FunctionVariable auto function, OutputMode outputMode > template< FunctionVariable auto function, OutputMode outputMode >
@ -326,48 +297,27 @@ namespace Alepha::Hydrogen::Testing ::detail:: table_test
args_type args; args_type args;
UniversalHandler handler; UniversalHandler handler;
}; };
std::vector< TestDescription > tests; UniversalCasesBase tests;
UniversalCases( std::initializer_list< TestDescription > initList ) UniversalCases( std::initializer_list< TestDescription > initList )
: tests( initList )
{ {
} for( const auto [ comment, params, handler ]: 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; if( C::debugCaseTypes ) std::cerr << boost::core::demangle( typeid( params ).name() ) << std::endl;
auto invoker= [&] auto invoker= [=]
{ {
breakpoint(); breakpoint();
return std::apply( function, params ); return std::apply( function, params );
}; };
const auto [result, supplement]= checker( invoker, comment ); const auto checker= [=]( const auto comment )
if( result == TestResult::Failed )
{ {
++failureCount; return handler( invoker, comment );
std::cout << " " << C::testFail << "FAILED CASE" << resetStyle << ": " << comment << std::endl; };
if( supplement.has_value() ) tests.tests.push_back( { comment, checker } );
{
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 { return tests(); }
}; };
// When the `UniversalCases` impl is ready to go, then this alias shim can be redirected to that form. Then I can // 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;
} }