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:
@ -165,8 +165,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
|
|||||||
}
|
}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
template< typename ... Params >
|
||||||
std::tuple< TestResult, std::optional< std::string > >
|
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( impl != nullptr ) return impl( invoker, comment );
|
||||||
if constexpr( std::is_base_of_v< std::decay_t< return_type >, ComputedBase > )
|
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 );
|
streamDebugging< outputMode >( oss, std::get< return_type >( witness ), expected );
|
||||||
}
|
}
|
||||||
else oss << "Unexpected exception of type: " << std::get< ErrorMessage >( witness ).mesg;
|
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 ¶m )
|
||||||
|
{
|
||||||
|
// 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() };
|
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 )
|
const auto checker= [=]( const auto comment )
|
||||||
{
|
{
|
||||||
return handler( invoker, comment );
|
return handler( invoker, comment, params );
|
||||||
};
|
};
|
||||||
if( comment.state == CaseComment::Enabled )
|
if( comment.state == CaseComment::Enabled )
|
||||||
{
|
{
|
||||||
|
@ -39,6 +39,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
|
|||||||
|
|
||||||
template< OutputMode outputMode, typename T >
|
template< OutputMode outputMode, typename T >
|
||||||
void printDebugging( const T &witness, const T &expected );
|
void printDebugging( const T &witness, const T &expected );
|
||||||
|
|
||||||
|
template< OutputMode outputMode, typename T >
|
||||||
|
auto streamAdaptValue( const T &v );
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace std::literals::string_literals;
|
using namespace std::literals::string_literals;
|
||||||
@ -124,7 +127,11 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
|
|||||||
}
|
}
|
||||||
else
|
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 >
|
template< OutputMode outputMode, typename T >
|
||||||
auto
|
auto
|
||||||
streamAdaptValue( const T &v )
|
exports::streamAdaptValue( const T &v )
|
||||||
{
|
{
|
||||||
return Adaptor< outputMode, std::decay_t< T > >{ v };
|
return Adaptor< outputMode, std::decay_t< T > >{ v };
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user