forked from Alepha/Alepha
Individual TableTest cases can be disabled.
This commit is contained in:
@ -25,7 +25,7 @@ namespace Alepha::Hydrogen::Testing::detail::TableTest_m
|
||||
std::cout << " " << C::testPass << "PASSED CASE" << resetStyle << ": " << comment << std::endl;
|
||||
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();
|
||||
|
@ -39,7 +39,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
|
||||
|
||||
namespace C:: inline Colors
|
||||
{
|
||||
using namespace testing_colors::C::Colors;
|
||||
using namespace testing_colors::C:: Colors;
|
||||
}
|
||||
|
||||
enum class TestResult { Passed, Failed };
|
||||
@ -304,6 +304,65 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
|
||||
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 >
|
||||
struct exports::TableTest
|
||||
{
|
||||
@ -323,7 +382,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
|
||||
|
||||
struct TestDescription
|
||||
{
|
||||
std::string comment;
|
||||
CaseComment comment;
|
||||
args_type args;
|
||||
UniversalHandler handler;
|
||||
};
|
||||
@ -343,7 +402,18 @@ namespace Alepha::Hydrogen::Testing ::detail:: TableTest_m
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
namespace Alepha::Hydrogen::Testing::inline exports::inline literals::inline test_literals
|
||||
{
|
||||
using namespace detail::TableTest_m::exports::literals;
|
||||
}
|
||||
|
@ -75,16 +75,15 @@ namespace
|
||||
{ "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. */
|
||||
#if 0
|
||||
{ "Basic value case", { -42 }, { 42, 42, 42 } },
|
||||
{ "Ignore exceptions case (`std::nothrow`)", { -42 }, std::nothrow },
|
||||
{ "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 exception", { 42 }, std::type_identity< std::exception >{} },
|
||||
{ "Expect exception value specific", { 42 }, DerivedError{ "Cannot be negative." } },
|
||||
{ "Expect exception value specific (loose)", { 42 }, std::runtime_error{ "Cannot be negative." } },
|
||||
{ "Expect exception value specific (wrong)", { -42 }, std::logic_error{ "Cannot be negative." } },
|
||||
#endif
|
||||
/* A few different ways of disabling these tests are shown below. */
|
||||
{ Skip <="Basic value case", { -42 }, { 42, 42, 42 } },
|
||||
{ !!Disable <="Ignore exceptions case (`std::nothrow`)", { -42 }, std::nothrow },
|
||||
{ -Enable <="Ignore exceptions case (`std::type_identity< void >`)", { -42 }, std::type_identity< void >{} },
|
||||
{ -"Expect exception type runtime_error"_case, { 42 }, std::type_identity< std::runtime_error >{} },
|
||||
{ Disable <="Expect exception type exception", { 42 }, std::type_identity< std::exception >{} },
|
||||
{ !"Expect exception value specific"_case, { 42 }, DerivedError{ "Cannot be negative." } },
|
||||
{ Skip <="Expect exception value specific (loose)", { 42 }, std::runtime_error{ "Cannot be negative." } },
|
||||
{ Skip <="Expect exception value specific (wrong)", { -42 }, std::logic_error{ "Cannot be negative." } },
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -13,7 +13,8 @@ namespace Alepha::Hydrogen::Testing ::detail:: testing_colors
|
||||
inline const auto testFail= createStyle( "test-failure", setFgColor( BasicTextColor::red ) );
|
||||
inline const auto testPass= createStyle( "test-success", setFgColor( BasicTextColor::green ) );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ namespace Alepha::Hydrogen::Testing::detail::testing
|
||||
|
||||
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
|
||||
{
|
||||
test();
|
||||
@ -66,7 +66,7 @@ namespace Alepha::Hydrogen::Testing::detail::testing
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
std::cout << C::testInfo << "FINISHED" << resetStyle << ": " << name << std::endl;
|
||||
std::cout << C::testStat << "FINISHED" << resetStyle << ": " << name << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user