forked from Alepha/Alepha
Unified testing output.
This should eliminate the duplicate "PASSED" or "FAILED" lines. I think I can type-erase some of this sufficiently to make the output rendering be in its own TU... then tweaks to test output format will mostly require a relink, not a rebuild.
This commit is contained in:
@ -34,6 +34,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
|
||||
{
|
||||
enum class OutputMode { All, Relaxed };
|
||||
|
||||
template< OutputMode outputMode, typename T >
|
||||
void streamDebugging( const T &witness, const T &expected );
|
||||
|
||||
template< OutputMode outputMode, typename T >
|
||||
void printDebugging( const T &witness, const T &expected );
|
||||
}
|
||||
@ -126,40 +129,51 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
|
||||
}
|
||||
|
||||
template< OutputMode outputMode, typename T >
|
||||
std::string
|
||||
stringifyValue( const T &v )
|
||||
struct Adaptor
|
||||
{
|
||||
std::ostringstream oss;
|
||||
streamValue< outputMode >( v, oss );
|
||||
return std::move( oss ).str();
|
||||
const T &element;
|
||||
|
||||
friend std::ostream &
|
||||
operator << ( std::ostream &os, const Adaptor &a )
|
||||
{
|
||||
streamValue< outputMode >( a, os );
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
template< OutputMode outputMode, typename T >
|
||||
auto
|
||||
streamAdaptValue( const T &v )
|
||||
{
|
||||
return Adaptor< outputMode, std::decay_t< T > >{ v };
|
||||
}
|
||||
|
||||
inline void
|
||||
printDebuggingForStrings( const std::string &witness, const std::string &expected )
|
||||
streamDebuggingForStrings( std::ostream &stream, const std::string &witness, const std::string &expected )
|
||||
{
|
||||
const std::size_t amount= std::min( witness.size(), expected.size() );
|
||||
if( witness.size() != expected.size() )
|
||||
{
|
||||
std::cout << "Witness string size did not match the expected string size. Only mismatches found in the first "
|
||||
stream << "Witness string size did not match the expected string size. Only mismatches found in the first "
|
||||
<< amount << " characters will be printed." << std::endl;
|
||||
}
|
||||
|
||||
for( int i= 0; i < amount; ++i )
|
||||
{
|
||||
if( witness.at( i ) == expected.at( i ) ) continue;
|
||||
std::cout << "Mismatch at index: " << i << std::endl;
|
||||
std::cout << "witness: " << witness.at( i ) << std::endl;
|
||||
std::cout << "expected: " << expected.at( i ) << std::endl;
|
||||
stream << "Mismatch at index: " << i << std::endl;
|
||||
stream << "witness: " << witness.at( i ) << std::endl;
|
||||
stream << "expected: " << expected.at( i ) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
template< OutputMode outputMode, typename T >
|
||||
void
|
||||
exports::printDebugging( const T &witness, const T &expected )
|
||||
exports::streamDebugging( std::ostream &stream, const T &witness, const T &expected )
|
||||
{
|
||||
if constexpr( std::is_same_v< std::string, std::decay_t< T > > )
|
||||
{
|
||||
printDebuggingForStrings( witness, expected );
|
||||
streamDebuggingForStrings( stream, witness, expected );
|
||||
}
|
||||
else if constexpr( Meta::is_sequence_v< T > )
|
||||
{
|
||||
@ -167,14 +181,14 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
|
||||
{
|
||||
if( witness.size() == expected.size() ) for( std::size_t i= 0; i < witness.size(); ++i )
|
||||
{
|
||||
if( witness.at( i ) != expected.at( i ) ) printDebuggingForStrings( witness.at( i ), expected.at( i ) );
|
||||
if( witness.at( i ) != expected.at( i ) ) streamDebuggingForStrings( stream, witness.at( i ), expected.at( i ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( witness.size() != expected.size() )
|
||||
{
|
||||
std::cout << "Witness sequence size of " << witness.size() << " did not match the expected sequence size of "
|
||||
stream << "Witness sequence size of " << witness.size() << " did not match the expected sequence size of "
|
||||
<< expected.size() << std::endl;
|
||||
}
|
||||
|
||||
@ -184,7 +198,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
|
||||
{
|
||||
if( not first )
|
||||
{
|
||||
std::cout << "Mismatch at witness index " << std::distance( begin( witness ), next.first ) << " and "
|
||||
stream << "Mismatch at witness index " << std::distance( begin( witness ), next.first ) << " and "
|
||||
<< "expected index " << std::distance( begin( expected ), next.second ) << std::endl;
|
||||
++next.first; ++next.second;
|
||||
}
|
||||
@ -194,9 +208,16 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << std::endl
|
||||
<< "computed: " << stringifyValue< outputMode >( witness ) << std::endl
|
||||
<< "expected: " << stringifyValue< outputMode >( expected ) << std::endl << std::endl;
|
||||
stream << std::endl
|
||||
<< "computed: " << streamAdaptValue< outputMode >( witness ) << std::endl
|
||||
<< "expected: " << streamAdaptValue< outputMode >( expected ) << std::endl << std::endl;
|
||||
}
|
||||
|
||||
template< OutputMode outputMode, typename T >
|
||||
void
|
||||
exports::printDebugging( const T &witness, const T &expected )
|
||||
{
|
||||
streamDebugging( std::cout, witness, expected );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user