diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d5521a84..7ff57b9f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -79,6 +79,7 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/TestRegistrations.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Clara.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/ColourImpl.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/FloatingPoint.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index f9ab0b77..fadb2747 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -104,6 +104,7 @@ Nor would this :test-result: PASS Character pretty printing :test-result: PASS Clara::Arg supports single-arg parse the way Opt does :test-result: PASS Clara::Opt supports accept-many lambdas +:test-result: PASS ColourGuard behaviour :test-result: PASS Combining MatchAllOfGeneric does not nest :test-result: PASS Combining MatchAnyOfGeneric does not nest :test-result: PASS Combining MatchNotOfGeneric does not nest diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index f9a6431f..f05de0ab 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -102,6 +102,7 @@ :test-result: PASS Character pretty printing :test-result: PASS Clara::Arg supports single-arg parse the way Opt does :test-result: PASS Clara::Opt supports accept-many lambdas +:test-result: PASS ColourGuard behaviour :test-result: PASS Combining MatchAllOfGeneric does not nest :test-result: PASS Combining MatchAnyOfGeneric does not nest :test-result: PASS Combining MatchNotOfGeneric does not nest diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 723e6470..c4425048 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -366,6 +366,33 @@ Clara.tests.cpp:: passed: name == "foo" for: "foo" == "foo" Clara.tests.cpp:: passed: !(parse_result) for: !{?} Clara.tests.cpp:: passed: parse_result for: {?} Clara.tests.cpp:: passed: res == std::vector{ "aaa", "bbb" } for: { "aaa", "bbb" } == { "aaa", "bbb" } +ColourImpl.tests.cpp:: passed: streamWrapper.str().empty() for: true +ColourImpl.tests.cpp:: passed: streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" for: "1 +Using code: 2 +2 +Using code: 0 +3 +" +== +"1 +Using code: 2 +2 +Using code: 0 +3 +" +ColourImpl.tests.cpp:: passed: streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" for: "Using code: 2 +A +B +Using code: 0 +C +" +== +"Using code: 2 +A +B +Using code: 0 +C +" Matchers.tests.cpp:: passed: with 1 message: 'std::is_same< decltype( ( MatcherA() && MatcherB() ) && MatcherC() ), Catch::Matchers::Detail:: MatchAllOfGeneric>::value' Matchers.tests.cpp:: passed: 1, ( MatcherA() && MatcherB() ) && MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) Matchers.tests.cpp:: passed: with 1 message: 'std::is_same< decltype( MatcherA() && ( MatcherB() && MatcherC() ) ), Catch::Matchers::Detail:: MatchAllOfGeneric>::value' diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index a39bbfdc..55d2cf6a 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -364,6 +364,33 @@ Clara.tests.cpp:: passed: name == "foo" for: "foo" == "foo" Clara.tests.cpp:: passed: !(parse_result) for: !{?} Clara.tests.cpp:: passed: parse_result for: {?} Clara.tests.cpp:: passed: res == std::vector{ "aaa", "bbb" } for: { "aaa", "bbb" } == { "aaa", "bbb" } +ColourImpl.tests.cpp:: passed: streamWrapper.str().empty() for: true +ColourImpl.tests.cpp:: passed: streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" for: "1 +Using code: 2 +2 +Using code: 0 +3 +" +== +"1 +Using code: 2 +2 +Using code: 0 +3 +" +ColourImpl.tests.cpp:: passed: streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" for: "Using code: 2 +A +B +Using code: 0 +C +" +== +"Using code: 2 +A +B +Using code: 0 +C +" Matchers.tests.cpp:: passed: with 1 message: 'std::is_same< decltype( ( MatcherA() && MatcherB() ) && MatcherC() ), Catch::Matchers::Detail:: MatchAllOfGeneric>::value' Matchers.tests.cpp:: passed: 1, ( MatcherA() && MatcherB() ) && MatcherC() for: 1 ( equals: (int) 1 or (float) 1.0f and equals: (long long) 1 and equals: (T) 1 ) Matchers.tests.cpp:: passed: with 1 message: 'std::is_same< decltype( MatcherA() && ( MatcherB() && MatcherC() ) ), Catch::Matchers::Detail:: MatchAllOfGeneric>::value' diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index e37fd27c..ca0a77e5 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1395,6 +1395,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 385 | 309 passed | 69 failed | 7 failed as expected -assertions: 2216 | 2061 passed | 128 failed | 27 failed as expected +test cases: 386 | 310 passed | 69 failed | 7 failed as expected +assertions: 2219 | 2064 passed | 128 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 256d347d..9da51362 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -3023,6 +3023,66 @@ Clara.tests.cpp:: PASSED: with expansion: { "aaa", "bbb" } == { "aaa", "bbb" } +------------------------------------------------------------------------------- +ColourGuard behaviour + ColourGuard is disengaged by default +------------------------------------------------------------------------------- +ColourImpl.tests.cpp: +............................................................................... + +ColourImpl.tests.cpp:: PASSED: + REQUIRE( streamWrapper.str().empty() ) +with expansion: + true + +------------------------------------------------------------------------------- +ColourGuard behaviour + ColourGuard is engaged by op<< +------------------------------------------------------------------------------- +ColourImpl.tests.cpp: +............................................................................... + +ColourImpl.tests.cpp:: PASSED: + REQUIRE( streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" ) +with expansion: + "1 + Using code: 2 + 2 + Using code: 0 + 3 + " + == + "1 + Using code: 2 + 2 + Using code: 0 + 3 + " + +------------------------------------------------------------------------------- +ColourGuard behaviour + ColourGuard can be engaged explicitly +------------------------------------------------------------------------------- +ColourImpl.tests.cpp: +............................................................................... + +ColourImpl.tests.cpp:: PASSED: + REQUIRE( streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" ) +with expansion: + "Using code: 2 + A + B + Using code: 0 + C + " + == + "Using code: 2 + A + B + Using code: 0 + C + " + ------------------------------------------------------------------------------- Combining MatchAllOfGeneric does not nest ------------------------------------------------------------------------------- @@ -17811,6 +17871,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 385 | 295 passed | 83 failed | 7 failed as expected -assertions: 2231 | 2061 passed | 143 failed | 27 failed as expected +test cases: 386 | 296 passed | 83 failed | 7 failed as expected +assertions: 2234 | 2064 passed | 143 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 27975ad9..4738113a 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -3021,6 +3021,66 @@ Clara.tests.cpp:: PASSED: with expansion: { "aaa", "bbb" } == { "aaa", "bbb" } +------------------------------------------------------------------------------- +ColourGuard behaviour + ColourGuard is disengaged by default +------------------------------------------------------------------------------- +ColourImpl.tests.cpp: +............................................................................... + +ColourImpl.tests.cpp:: PASSED: + REQUIRE( streamWrapper.str().empty() ) +with expansion: + true + +------------------------------------------------------------------------------- +ColourGuard behaviour + ColourGuard is engaged by op<< +------------------------------------------------------------------------------- +ColourImpl.tests.cpp: +............................................................................... + +ColourImpl.tests.cpp:: PASSED: + REQUIRE( streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" ) +with expansion: + "1 + Using code: 2 + 2 + Using code: 0 + 3 + " + == + "1 + Using code: 2 + 2 + Using code: 0 + 3 + " + +------------------------------------------------------------------------------- +ColourGuard behaviour + ColourGuard can be engaged explicitly +------------------------------------------------------------------------------- +ColourImpl.tests.cpp: +............................................................................... + +ColourImpl.tests.cpp:: PASSED: + REQUIRE( streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" ) +with expansion: + "Using code: 2 + A + B + Using code: 0 + C + " + == + "Using code: 2 + A + B + Using code: 0 + C + " + ------------------------------------------------------------------------------- Combining MatchAllOfGeneric does not nest ------------------------------------------------------------------------------- @@ -17803,6 +17863,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 385 | 295 passed | 83 failed | 7 failed as expected -assertions: 2231 | 2061 passed | 143 failed | 27 failed as expected +test cases: 386 | 296 passed | 83 failed | 7 failed as expected +assertions: 2234 | 2064 passed | 143 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 84c3625e..3a099b4f 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -387,6 +387,9 @@ Exception.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index d1a41e13..527f7ba0 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -386,6 +386,9 @@ Exception.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 9d6e859f..92db65df 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -94,6 +94,11 @@ + + + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index a412dbc2..c9074bf0 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -93,6 +93,11 @@ + + + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 3080c4a5..5da402f2 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -730,6 +730,12 @@ ok {test-number} - !(parse_result) for: !{?} ok {test-number} - parse_result for: {?} # Clara::Opt supports accept-many lambdas ok {test-number} - res == std::vector{ "aaa", "bbb" } for: { "aaa", "bbb" } == { "aaa", "bbb" } +# ColourGuard behaviour +ok {test-number} - streamWrapper.str().empty() for: true +# ColourGuard behaviour +ok {test-number} - streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" for: "1 Using code: 2 2 Using code: 0 3 " == "1 Using code: 2 2 Using code: 0 3 " +# ColourGuard behaviour +ok {test-number} - streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" for: "Using code: 2 A B Using code: 0 C " == "Using code: 2 A B Using code: 0 C " # Combining MatchAllOfGeneric does not nest ok {test-number} - with 1 message: 'std::is_same< decltype( ( MatcherA() && MatcherB() ) && MatcherC() ), Catch::Matchers::Detail:: MatchAllOfGeneric>::value' # Combining MatchAllOfGeneric does not nest @@ -4464,5 +4470,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2231 +1..2234 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 60011180..1e637a17 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -728,6 +728,12 @@ ok {test-number} - !(parse_result) for: !{?} ok {test-number} - parse_result for: {?} # Clara::Opt supports accept-many lambdas ok {test-number} - res == std::vector{ "aaa", "bbb" } for: { "aaa", "bbb" } == { "aaa", "bbb" } +# ColourGuard behaviour +ok {test-number} - streamWrapper.str().empty() for: true +# ColourGuard behaviour +ok {test-number} - streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" for: "1 Using code: 2 2 Using code: 0 3 " == "1 Using code: 2 2 Using code: 0 3 " +# ColourGuard behaviour +ok {test-number} - streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" for: "Using code: 2 A B Using code: 0 C " == "Using code: 2 A B Using code: 0 C " # Combining MatchAllOfGeneric does not nest ok {test-number} - with 1 message: 'std::is_same< decltype( ( MatcherA() && MatcherB() ) && MatcherC() ), Catch::Matchers::Detail:: MatchAllOfGeneric>::value' # Combining MatchAllOfGeneric does not nest @@ -4456,5 +4462,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2231 +1..2234 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 4963db33..43324e06 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -241,6 +241,8 @@ Exception.tests.cpp:|nunexpected exception with message:|n "unexpe ##teamcity[testFinished name='Clara::Arg supports single-arg parse the way Opt does' duration="{duration}"] ##teamcity[testStarted name='Clara::Opt supports accept-many lambdas'] ##teamcity[testFinished name='Clara::Opt supports accept-many lambdas' duration="{duration}"] +##teamcity[testStarted name='ColourGuard behaviour'] +##teamcity[testFinished name='ColourGuard behaviour' duration="{duration}"] ##teamcity[testStarted name='Combining MatchAllOfGeneric does not nest'] ##teamcity[testFinished name='Combining MatchAllOfGeneric does not nest' duration="{duration}"] ##teamcity[testStarted name='Combining MatchAnyOfGeneric does not nest'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index b91e8c75..3bc028a4 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -241,6 +241,8 @@ Exception.tests.cpp:|nunexpected exception with message:|n "unexpe ##teamcity[testFinished name='Clara::Arg supports single-arg parse the way Opt does' duration="{duration}"] ##teamcity[testStarted name='Clara::Opt supports accept-many lambdas'] ##teamcity[testFinished name='Clara::Opt supports accept-many lambdas' duration="{duration}"] +##teamcity[testStarted name='ColourGuard behaviour'] +##teamcity[testFinished name='ColourGuard behaviour' duration="{duration}"] ##teamcity[testStarted name='Combining MatchAllOfGeneric does not nest'] ##teamcity[testFinished name='Combining MatchAllOfGeneric does not nest' duration="{duration}"] ##teamcity[testStarted name='Combining MatchAnyOfGeneric does not nest'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 5a028632..fdd4c3b7 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -3308,6 +3308,66 @@ Nor would this + +
+ + + streamWrapper.str().empty() + + + true + + + +
+
+ + + streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" + + + "1 +Using code: 2 +2 +Using code: 0 +3 +" +== +"1 +Using code: 2 +2 +Using code: 0 +3 +" + + + +
+
+ + + streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" + + + "Using code: 2 +A +B +Using code: 0 +C +" +== +"Using code: 2 +A +B +Using code: 0 +C +" + + + +
+ +
@@ -20931,6 +20991,6 @@ loose text artifact - - + + diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index da925a2f..5d0f7951 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -3308,6 +3308,66 @@ Nor would this
+ +
+ + + streamWrapper.str().empty() + + + true + + + +
+
+ + + streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" + + + "1 +Using code: 2 +2 +Using code: 0 +3 +" +== +"1 +Using code: 2 +2 +Using code: 0 +3 +" + + + +
+
+ + + streamWrapper.str() == "Using code: 2\nA\nB\nUsing code: 0\nC\n" + + + "Using code: 2 +A +B +Using code: 0 +C +" +== +"Using code: 2 +A +B +Using code: 0 +C +" + + + +
+ +
@@ -20930,6 +20990,6 @@ There is no extra whitespace here - - + + diff --git a/tests/SelfTest/IntrospectiveTests/ColourImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/ColourImpl.tests.cpp new file mode 100644 index 00000000..4da7c4b3 --- /dev/null +++ b/tests/SelfTest/IntrospectiveTests/ColourImpl.tests.cpp @@ -0,0 +1,63 @@ + +// Copyright Catch2 Authors +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// SPDX-License-Identifier: BSL-1.0 + +#include +#include + +#include + +namespace { + class TestColourImpl : public Catch::ColourImpl { + using Catch::ColourImpl::ColourImpl; + // Inherited via ColourImpl + void use( Catch::Colour::Code colourCode ) const override { + m_stream->stream() << "Using code: " << colourCode << '\n'; + } + }; + + class TestStringStream : public Catch::IStream { + mutable std::stringstream m_stream; + public: + std::ostream& stream() const override { + return m_stream; + } + + std::string str() const { return m_stream.str(); } + }; +} + +TEST_CASE("ColourGuard behaviour", "[console-colours]") { + TestStringStream streamWrapper; + TestColourImpl colourImpl( &streamWrapper ); + auto& stream = streamWrapper.stream(); + + SECTION("ColourGuard is disengaged by default") { + { auto guard = colourImpl.guardColour( Catch::Colour::Red ); } + + REQUIRE( streamWrapper.str().empty() ); + } + + SECTION("ColourGuard is engaged by op<<") { + stream << "1\n" << colourImpl.guardColour( Catch::Colour::Red ) << "2\n"; + stream << "3\n"; + + REQUIRE( streamWrapper.str() == "1\nUsing code: 2\n2\nUsing code: 0\n3\n" ); + } + + SECTION("ColourGuard can be engaged explicitly") { + { + auto guard = + colourImpl.guardColour( Catch::Colour::Red ).engage( stream ); + stream << "A\n" + << "B\n"; + } + stream << "C\n"; + REQUIRE( streamWrapper.str() == + "Using code: 2\nA\nB\nUsing code: 0\nC\n" ); + } +}