1
0
forked from Alepha/Alepha

Individual TableTest cases can be disabled.

This commit is contained in:
2023-11-13 11:45:56 -05:00
parent 4682fe3ffb
commit c6b66aa7b5
5 changed files with 92 additions and 17 deletions

View File

@ -25,7 +25,7 @@ namespace Alepha::Hydrogen::Testing::detail::TableTest_m
std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl; std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl;
if( supplement.has_value() ) if( supplement.has_value() )
{ {
std::cout << " " << C::testWarn << "INFO: " << resetStyle << ": " << supplement.value() << std::endl; std::cout << " " << C::testInfo << "NOTE: " << resetStyle << ": " << supplement.value() << std::endl;
} }
} }
breakpoint(); breakpoint();

View File

@ -39,7 +39,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
namespace C:: inline Colors namespace C:: inline Colors
{ {
using namespace testing_colors::C::Colors; using namespace testing_colors::C:: Colors;
} }
enum class TestResult { Passed, Failed }; enum class TestResult { Passed, Failed };
@ -304,6 +304,65 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
int operator() () const; int operator() () const;
}; };
struct CaseComment
{
enum State : bool { Enabled= true, Disabled= false } state= Enabled;
std::string comment;
CaseComment( const Concepts::ConvertibleTo< std::string > auto &comment )
: comment( comment ) {}
explicit
CaseComment( const State state, const std::string &comment )
: state( state ), comment( comment ) {}
auto
operator not () const
{
return CaseComment{ State( not state ), comment };
}
auto
operator -() const
{
return CaseComment{ State( not state ), comment };
}
};
namespace exports
{
inline namespace literals
{
inline CaseComment
operator ""_case ( const char *const ch, const std::size_t amt )
{
return CaseComment{ std::string{ ch, ch + amt } };
}
}
enum { Enable= 1, Skip= -1, Disable= -1 };
inline auto
operator - ( const decltype( Enable ) e )
{
return decltype( Enable )( -int( e ) );
}
inline auto
operator not ( const decltype( Enable ) e )
{
return e == Enable ? Enable : Disable;
}
inline auto
operator <= ( const decltype( Enable ) token, const CaseComment &comment )
{
if( token == Disable ) return CaseComment{ CaseComment::Disabled, comment.comment };
else return CaseComment{ CaseComment::Enabled, comment.comment };
}
}
template< FunctionVariable auto function, OutputMode outputMode > template< FunctionVariable auto function, OutputMode outputMode >
struct exports::TableTest struct exports::TableTest
{ {
@ -323,7 +382,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
struct TestDescription struct TestDescription
{ {
std::string comment; CaseComment comment;
args_type args; args_type args;
UniversalHandler handler; UniversalHandler handler;
}; };
@ -343,7 +402,18 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
{ {
return handler( invoker, comment ); return handler( invoker, comment );
}; };
tests.tests.push_back( { comment, checker } ); if( comment.state == CaseComment::Enabled )
{
tests.tests.push_back( { comment.comment, checker } );
}
else
{
auto skippedHandler= [] ( const auto comment ) -> std::tuple< TestResult, std::optional< std::string > >
{
return { TestResult::Passed, "Skipped." };
};
tests.tests.push_back( { comment.comment, skippedHandler } );
}
} }
} }
@ -364,3 +434,8 @@ namespace Alepha::Hydrogen::Testing::inline exports::inline TableTest_m
{ {
using namespace detail::TableTest_m::exports; using namespace detail::TableTest_m::exports;
} }
namespace Alepha::Hydrogen::Testing::inline exports::inline literals::inline test_literals
{
using namespace detail::TableTest_m::exports::literals;
}

View File

@ -75,16 +75,15 @@ namespace
{ "Expect exception value specific (loose)", { -42 }, std::runtime_error{ "Cannot be negative." } }, { "Expect exception value specific (loose)", { -42 }, std::runtime_error{ "Cannot be negative." } },
/* These cases should fail, but we don't want to fail them in normal builds. */ /* These cases should fail, but we don't want to fail them in normal builds. */
#if 0 /* A few different ways of disabling these tests are shown below. */
{ "Basic value case", { -42 }, { 42, 42, 42 } }, { Skip <="Basic value case", { -42 }, { 42, 42, 42 } },
{ "Ignore exceptions case (`std::nothrow`)", { -42 }, std::nothrow }, { !!Disable <="Ignore exceptions case (`std::nothrow`)", { -42 }, std::nothrow },
{ "Ignore exceptions case (`std::type_identity< void >`)", { -42 }, std::type_identity< void >{} }, { -Enable <="Ignore exceptions case (`std::type_identity< void >`)", { -42 }, std::type_identity< void >{} },
{ "Expect exception type runtime_error", { 42 }, std::type_identity< std::runtime_error >{} }, { -"Expect exception type runtime_error"_case, { 42 }, std::type_identity< std::runtime_error >{} },
{ "Expect exception type exception", { 42 }, std::type_identity< std::exception >{} }, { Disable <="Expect exception type exception", { 42 }, std::type_identity< std::exception >{} },
{ "Expect exception value specific", { 42 }, DerivedError{ "Cannot be negative." } }, { !"Expect exception value specific"_case, { 42 }, DerivedError{ "Cannot be negative." } },
{ "Expect exception value specific (loose)", { 42 }, std::runtime_error{ "Cannot be negative." } }, { Skip <="Expect exception value specific (loose)", { 42 }, std::runtime_error{ "Cannot be negative." } },
{ "Expect exception value specific (wrong)", { -42 }, std::logic_error{ "Cannot be negative." } }, { Skip <="Expect exception value specific (wrong)", { -42 }, std::logic_error{ "Cannot be negative." } },
#endif
}; };
}; };
} }

View File

@ -13,7 +13,8 @@ namespace Alepha::Hydrogen::Testing ::detail:: testing_colors
inline const auto testFail= createStyle( "test-failure", setFgColor( BasicTextColor::red ) ); inline const auto testFail= createStyle( "test-failure", setFgColor( BasicTextColor::red ) );
inline const auto testPass= createStyle( "test-success", setFgColor( BasicTextColor::green ) ); inline const auto testPass= createStyle( "test-success", setFgColor( BasicTextColor::green ) );
inline const auto testWarn= createStyle( "test-warn", "italic ansi:5"_sgr ); inline const auto testWarn= createStyle( "test-warn", "italic ansi:5"_sgr );
inline const auto testInfo= createStyle( "test-info", "ext:rgb235"_sgr ); inline const auto testInfo= createStyle( "test-info", "italic ext:11"_sgr );
inline const auto testStat= createStyle( "test-status", "ext:rgb235"_sgr );
} }
} }
} }

View File

@ -46,7 +46,7 @@ namespace Alepha::Hydrogen::Testing::detail::testing
if( explicitlyNamed( name ) or not disabled and selected( name ) ) if( explicitlyNamed( name ) or not disabled and selected( name ) )
{ {
std::cout << C::testInfo << "BEGIN" << resetStyle << " : " << name << std::endl; std::cout << C::testStat << "BEGIN" << resetStyle << " : " << name << std::endl;
try try
{ {
test(); test();
@ -66,7 +66,7 @@ namespace Alepha::Hydrogen::Testing::detail::testing
std::cout << std::endl; std::cout << std::endl;
} }
std::cout << C::testInfo << "FINISHED" << resetStyle << ": " << name << std::endl; std::cout << C::testStat << "FINISHED" << resetStyle << ": " << name << std::endl;
} }
} }