From 33fa7cc71183439bd2dc5d02b98196dc1e3fd88e Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 13 Jun 2024 18:02:49 -0400 Subject: [PATCH 1/3] Expose the stream value adaptor for tests. This will permit calling this stream adaptor from various contexts which are test related. --- Testing/printDebugging.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Testing/printDebugging.h b/Testing/printDebugging.h index 1dd12e2..4b2dc44 100644 --- a/Testing/printDebugging.h +++ b/Testing/printDebugging.h @@ -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; @@ -143,7 +146,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 }; } From fc02d1a0c3b27a63be75398b6dd108e17863520b Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 13 Jun 2024 18:03:33 -0400 Subject: [PATCH 2/3] Relax the test print debugging rules. A type which cannot be printed when streamed in "Relaxed" mode will simply print the typeid and that's it. This is opposed to its original behaviour which would be a compile time error. --- Testing/printDebugging.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Testing/printDebugging.h b/Testing/printDebugging.h index 4b2dc44..7e0229f 100644 --- a/Testing/printDebugging.h +++ b/Testing/printDebugging.h @@ -127,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 << ""; + } + else static_assert( dependent_value< false, T >, "One of the types used in the testing table does not support stringification." ); } } From b44539cab102b18b4d005a52103d92de31d1a0c0 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 13 Jun 2024 18:04:33 -0400 Subject: [PATCH 3/3] Table tests now print argument information about failed cases. At least they'll print as much information as they can. Unstreamable input types will just print typeid information. --- Testing/TableTest.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Testing/TableTest.h b/Testing/TableTest.h index 26a3e4f..b956b1e 100644 --- a/Testing/TableTest.h +++ b/Testing/TableTest.h @@ -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 ¶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() }; } @@ -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 ) {