From c6b66aa7b5f9bc93ba1b6ae88dbc491718e36d1c Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Mon, 13 Nov 2023 11:45:56 -0500 Subject: [PATCH] Individual TableTest cases can be disabled. --- Testing/TableTest.cc | 2 +- Testing/TableTest.h | 81 +++++++++++++++++++++++++++++++-- Testing/TableTest.test/test2.cc | 19 ++++---- Testing/colors.h | 3 +- Testing/test.cc | 4 +- 5 files changed, 92 insertions(+), 17 deletions(-) diff --git a/Testing/TableTest.cc b/Testing/TableTest.cc index 2ed377c..b4052a0 100644 --- a/Testing/TableTest.cc +++ b/Testing/TableTest.cc @@ -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(); diff --git a/Testing/TableTest.h b/Testing/TableTest.h index 48e9a00..4f08a8e 100644 --- a/Testing/TableTest.h +++ b/Testing/TableTest.h @@ -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; +} diff --git a/Testing/TableTest.test/test2.cc b/Testing/TableTest.test/test2.cc index 0e8588a..8a11d68 100644 --- a/Testing/TableTest.test/test2.cc +++ b/Testing/TableTest.test/test2.cc @@ -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." } }, }; }; } diff --git a/Testing/colors.h b/Testing/colors.h index cb32624..af9caac 100644 --- a/Testing/colors.h +++ b/Testing/colors.h @@ -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 ); } } } diff --git a/Testing/test.cc b/Testing/test.cc index 9d7b596..bf48001 100644 --- a/Testing/test.cc +++ b/Testing/test.cc @@ -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; } }