1
0
forked from Alepha/Alepha

Enable printing case arguments on failed tests

The `TableTest` mechanism now prints as much detailed information
as it can get about the case arguments in any failed test case.

Git-commit-built-by: Merge branch 'print-test-inputs'
This commit is contained in:
2024-06-14 11:51:00 -04:00
2 changed files with 20 additions and 4 deletions

View File

@ -165,8 +165,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
}
{}
template< typename ... Params >
std::tuple< TestResult, std::optional< std::string > >
operator() ( Invoker invoker, const std::string &comment ) const
operator() ( Invoker invoker, const std::string &comment, const std::tuple< Params... > params ) const
{
if( impl != nullptr ) return impl( invoker, comment );
if constexpr( std::is_base_of_v< std::decay_t< return_type >, ComputedBase > )
@ -202,6 +203,14 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
streamDebugging< outputMode >( oss, std::get< return_type >( witness ), expected );
}
else oss << "Unexpected exception of type: " << std::get< ErrorMessage >( witness ).mesg;
oss << std::endl << "Test inputs were: " << std::endl;
int index= 0;
tuple_for_each( params ) <=[&]( const auto &param )
{
// Debugging output for test inputs is relaxed, as it's not required they be streamable?
oss << "Argument " << index++ << ": " << streamAdaptValue< OutputMode::Relaxed >( param ) << std::endl;
};
}
return { result, oss.str().empty() ? std::optional< std::string >{} : std::move( oss ).str() };
}
@ -472,7 +481,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
};
const auto checker= [=]( const auto comment )
{
return handler( invoker, comment );
return handler( invoker, comment, params );
};
if( comment.state == CaseComment::Enabled )
{

View File

@ -39,6 +39,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
template< OutputMode outputMode, typename T >
void printDebugging( const T &witness, const T &expected );
template< OutputMode outputMode, typename T >
auto streamAdaptValue( const T &v );
}
using namespace std::literals::string_literals;
@ -124,7 +127,11 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
}
else
{
static_assert( dependent_value< false, T >, "One of the types used in the testing table does not support stringification." );
if constexpr( outputMode == OutputMode::Relaxed )
{
oss << "<Unstreamable object of type `" << typeid( v ).name() << "`>";
}
else static_assert( dependent_value< false, T >, "One of the types used in the testing table does not support stringification." );
}
}
@ -143,7 +150,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
template< OutputMode outputMode, typename T >
auto
streamAdaptValue( const T &v )
exports::streamAdaptValue( const T &v )
{
return Adaptor< outputMode, std::decay_t< T > >{ v };
}