diff --git a/src/catch2/internal/catch_stream.cpp b/src/catch2/internal/catch_stream.cpp index eca83dda..5ce6e255 100644 --- a/src/catch2/internal/catch_stream.cpp +++ b/src/catch2/internal/catch_stream.cpp @@ -99,6 +99,7 @@ namespace Detail { public: // IStream std::ostream& stream() const override { return m_os; } + bool isStdout() const override { return true; } }; /////////////////////////////////////////////////////////////////////////// diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp index 39a4c0c8..77a35760 100644 --- a/src/catch2/internal/catch_stream.hpp +++ b/src/catch2/internal/catch_stream.hpp @@ -25,6 +25,9 @@ namespace Catch { struct IStream { virtual ~IStream(); // = default virtual std::ostream& stream() const = 0; + // Win32 colour supports requires us to identify whether a stream + // is backed by stdout (so we can colour it) or not (and we can't). + virtual bool isStdout() const { return false; } }; auto makeStream( std::string const& filename ) -> Detail::unique_ptr; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2115a690..d5521a84 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -90,6 +90,7 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/IntrospectiveTests/TestSpecParser.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/TextFlow.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Sharding.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Stream.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index c575637f..bfeb3da7 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -122,11 +122,13 @@ Nor would this :test-result: PASS Composed matchers shortcircuit :test-result: FAIL Contains string matcher :test-result: PASS Copy and then generate a range +:test-result: PASS Cout stream properly declares it writes to stdout :test-result: FAIL Custom exceptions can be translated when testing for nothrow :test-result: FAIL Custom exceptions can be translated when testing for throwing as something else :test-result: FAIL Custom std-exceptions can be custom translated :test-result: PASS Default scale is invisible to comparison :test-result: PASS Directly creating an EnumInfo +:test-result: PASS Empty stream name opens cout stream :test-result: PASS Empty tag is not allowed :test-result: FAIL EndsWith string matcher :test-result: PASS Enums can quickly have stringification enabled using REGISTER_ENUM diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index 31c0b106..a4070375 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -120,11 +120,13 @@ :test-result: PASS Composed matchers shortcircuit :test-result: FAIL Contains string matcher :test-result: PASS Copy and then generate a range +:test-result: PASS Cout stream properly declares it writes to stdout :test-result: FAIL Custom exceptions can be translated when testing for nothrow :test-result: FAIL Custom exceptions can be translated when testing for throwing as something else :test-result: FAIL Custom std-exceptions can be custom translated :test-result: PASS Default scale is invisible to comparison :test-result: PASS Directly creating an EnumInfo +:test-result: PASS Empty stream name opens cout stream :test-result: PASS Empty tag is not allowed :test-result: FAIL EndsWith string matcher :test-result: PASS Enums can quickly have stringification enabled using REGISTER_ENUM diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 87e318dd..ea0ba61a 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -479,6 +479,7 @@ Generators.tests.cpp:: passed: elem % 2 == 1 for: 1 == 1 Generators.tests.cpp:: passed: elem % 2 == 1 for: 1 == 1 Generators.tests.cpp:: passed: call_count == 1 for: 1 == 1 Generators.tests.cpp:: passed: make_data().size() == test_count for: 6 == 6 +Stream.tests.cpp:: passed: Catch::makeStream( "-" )->isStdout() for: true Exception.tests.cpp:: failed: unexpected exception with message: 'custom exception - not std'; expression was: throwCustom() Exception.tests.cpp:: failed: unexpected exception with message: 'custom exception - not std'; expression was: throwCustom(), std::exception Exception.tests.cpp:: failed: unexpected exception with message: 'custom std exception' @@ -489,6 +490,7 @@ ToString.tests.cpp:: passed: enumInfo->lookup(1) == "Value2" for: V ToString.tests.cpp:: passed: enumInfo->lookup(3) == "{** unexpected enum value **}" for: {** unexpected enum value **} == "{** unexpected enum value **}" +Stream.tests.cpp:: passed: Catch::makeStream( "" )->isStdout() for: true Tag.tests.cpp:: passed: Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) Matchers.tests.cpp:: failed: testStringForMatching(), EndsWith( "Substring" ) for: "this string contains 'abc' as a substring" ends with: "Substring" Matchers.tests.cpp:: failed: testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No ) for: "this string contains 'abc' as a substring" ends with: "this" (case insensitive) diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 6c7c1baf..4de9e7eb 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -477,6 +477,7 @@ Generators.tests.cpp:: passed: elem % 2 == 1 for: 1 == 1 Generators.tests.cpp:: passed: elem % 2 == 1 for: 1 == 1 Generators.tests.cpp:: passed: call_count == 1 for: 1 == 1 Generators.tests.cpp:: passed: make_data().size() == test_count for: 6 == 6 +Stream.tests.cpp:: passed: Catch::makeStream( "-" )->isStdout() for: true Exception.tests.cpp:: failed: unexpected exception with message: 'custom exception - not std'; expression was: throwCustom() Exception.tests.cpp:: failed: unexpected exception with message: 'custom exception - not std'; expression was: throwCustom(), std::exception Exception.tests.cpp:: failed: unexpected exception with message: 'custom std exception' @@ -487,6 +488,7 @@ ToString.tests.cpp:: passed: enumInfo->lookup(1) == "Value2" for: V ToString.tests.cpp:: passed: enumInfo->lookup(3) == "{** unexpected enum value **}" for: {** unexpected enum value **} == "{** unexpected enum value **}" +Stream.tests.cpp:: passed: Catch::makeStream( "" )->isStdout() for: true Tag.tests.cpp:: passed: Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) Matchers.tests.cpp:: failed: testStringForMatching(), EndsWith( "Substring" ) for: "this string contains 'abc' as a substring" ends with: "Substring" Matchers.tests.cpp:: failed: testStringForMatching(), EndsWith( "this", Catch::CaseSensitive::No ) for: "this string contains 'abc' as a substring" ends with: "this" (case insensitive) diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 195e0ccb..0b6a78bc 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: 381 | 305 passed | 69 failed | 7 failed as expected -assertions: 2211 | 2056 passed | 128 failed | 27 failed as expected +test cases: 383 | 307 passed | 69 failed | 7 failed as expected +assertions: 2213 | 2058 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 d2d8a04f..8eb882e3 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -3805,6 +3805,17 @@ Generators.tests.cpp:: PASSED: with expansion: 6 == 6 +------------------------------------------------------------------------------- +Cout stream properly declares it writes to stdout +------------------------------------------------------------------------------- +Stream.tests.cpp: +............................................................................... + +Stream.tests.cpp:: PASSED: + REQUIRE( Catch::makeStream( "-" )->isStdout() ) +with expansion: + true + ------------------------------------------------------------------------------- Custom exceptions can be translated when testing for nothrow ------------------------------------------------------------------------------- @@ -3876,6 +3887,17 @@ with expansion: == "{** unexpected enum value **}" +------------------------------------------------------------------------------- +Empty stream name opens cout stream +------------------------------------------------------------------------------- +Stream.tests.cpp: +............................................................................... + +Stream.tests.cpp:: PASSED: + REQUIRE( Catch::makeStream( "" )->isStdout() ) +with expansion: + true + ------------------------------------------------------------------------------- Empty tag is not allowed ------------------------------------------------------------------------------- @@ -17764,6 +17786,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 381 | 291 passed | 83 failed | 7 failed as expected -assertions: 2226 | 2056 passed | 143 failed | 27 failed as expected +test cases: 383 | 293 passed | 83 failed | 7 failed as expected +assertions: 2228 | 2058 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 045f7e0d..64ff619b 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -3803,6 +3803,17 @@ Generators.tests.cpp:: PASSED: with expansion: 6 == 6 +------------------------------------------------------------------------------- +Cout stream properly declares it writes to stdout +------------------------------------------------------------------------------- +Stream.tests.cpp: +............................................................................... + +Stream.tests.cpp:: PASSED: + REQUIRE( Catch::makeStream( "-" )->isStdout() ) +with expansion: + true + ------------------------------------------------------------------------------- Custom exceptions can be translated when testing for nothrow ------------------------------------------------------------------------------- @@ -3874,6 +3885,17 @@ with expansion: == "{** unexpected enum value **}" +------------------------------------------------------------------------------- +Empty stream name opens cout stream +------------------------------------------------------------------------------- +Stream.tests.cpp: +............................................................................... + +Stream.tests.cpp:: PASSED: + REQUIRE( Catch::makeStream( "" )->isStdout() ) +with expansion: + true + ------------------------------------------------------------------------------- Empty tag is not allowed ------------------------------------------------------------------------------- @@ -17756,6 +17778,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 381 | 291 passed | 83 failed | 7 failed as expected -assertions: 2226 | 2056 passed | 143 failed | 27 failed as expected +test cases: 383 | 293 passed | 83 failed | 7 failed as expected +assertions: 2228 | 2058 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 b259f75d..e9db7259 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -425,6 +425,7 @@ Matchers.tests.cpp: + FAILED: @@ -450,6 +451,7 @@ Exception.tests.cpp: + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index 26b2f904..820be769 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -424,6 +424,7 @@ Matchers.tests.cpp: + FAILED: @@ -449,6 +450,7 @@ Exception.tests.cpp: + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index cc901e29..0b5dfb42 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -216,6 +216,10 @@ + + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 0359fa40..27061535 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -215,6 +215,10 @@ + + + + diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 5c36015e..f9f01296 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -956,6 +956,8 @@ ok {test-number} - elem % 2 == 1 for: 1 == 1 ok {test-number} - call_count == 1 for: 1 == 1 # Copy and then generate a range ok {test-number} - make_data().size() == test_count for: 6 == 6 +# Cout stream properly declares it writes to stdout +ok {test-number} - Catch::makeStream( "-" )->isStdout() for: true # Custom exceptions can be translated when testing for nothrow not ok {test-number} - unexpected exception with message: 'custom exception - not std'; expression was: throwCustom() # Custom exceptions can be translated when testing for throwing as something else @@ -972,6 +974,8 @@ ok {test-number} - enumInfo->lookup(0) == "Value1" for: Value1 == "Value1" ok {test-number} - enumInfo->lookup(1) == "Value2" for: Value2 == "Value2" # Directly creating an EnumInfo ok {test-number} - enumInfo->lookup(3) == "{** unexpected enum value **}" for: {** unexpected enum value **} == "{** unexpected enum value **}" +# Empty stream name opens cout stream +ok {test-number} - Catch::makeStream( "" )->isStdout() for: true # Empty tag is not allowed ok {test-number} - Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) # EndsWith string matcher @@ -4454,5 +4458,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2226 +1..2228 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 9eb4aaca..e56cde86 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -954,6 +954,8 @@ ok {test-number} - elem % 2 == 1 for: 1 == 1 ok {test-number} - call_count == 1 for: 1 == 1 # Copy and then generate a range ok {test-number} - make_data().size() == test_count for: 6 == 6 +# Cout stream properly declares it writes to stdout +ok {test-number} - Catch::makeStream( "-" )->isStdout() for: true # Custom exceptions can be translated when testing for nothrow not ok {test-number} - unexpected exception with message: 'custom exception - not std'; expression was: throwCustom() # Custom exceptions can be translated when testing for throwing as something else @@ -970,6 +972,8 @@ ok {test-number} - enumInfo->lookup(0) == "Value1" for: Value1 == "Value1" ok {test-number} - enumInfo->lookup(1) == "Value2" for: Value2 == "Value2" # Directly creating an EnumInfo ok {test-number} - enumInfo->lookup(3) == "{** unexpected enum value **}" for: {** unexpected enum value **} == "{** unexpected enum value **}" +# Empty stream name opens cout stream +ok {test-number} - Catch::makeStream( "" )->isStdout() for: true # Empty tag is not allowed ok {test-number} - Catch::TestCaseInfo( "", { "fake test name", "[]" }, dummySourceLineInfo ) # EndsWith string matcher @@ -4446,5 +4450,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2226 +1..2228 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index e7279bc4..ecd1ea02 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -279,6 +279,8 @@ Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringFor ##teamcity[testFinished name='Contains string matcher' duration="{duration}"] ##teamcity[testStarted name='Copy and then generate a range'] ##teamcity[testFinished name='Copy and then generate a range' duration="{duration}"] +##teamcity[testStarted name='Cout stream properly declares it writes to stdout'] +##teamcity[testFinished name='Cout stream properly declares it writes to stdout' duration="{duration}"] ##teamcity[testStarted name='Custom exceptions can be translated when testing for nothrow'] Exception.tests.cpp:|nunexpected exception with message:|n "custom exception - not std"|n REQUIRE_NOTHROW( throwCustom() )|nwith expansion:|n throwCustom()|n'] ##teamcity[testFinished name='Custom exceptions can be translated when testing for nothrow' duration="{duration}"] @@ -292,6 +294,8 @@ Exception.tests.cpp:|nunexpected exception with message:|n "custom ##teamcity[testFinished name='Default scale is invisible to comparison' duration="{duration}"] ##teamcity[testStarted name='Directly creating an EnumInfo'] ##teamcity[testFinished name='Directly creating an EnumInfo' duration="{duration}"] +##teamcity[testStarted name='Empty stream name opens cout stream'] +##teamcity[testFinished name='Empty stream name opens cout stream' duration="{duration}"] ##teamcity[testStarted name='Empty tag is not allowed'] ##teamcity[testFinished name='Empty tag is not allowed' duration="{duration}"] ##teamcity[testStarted name='EndsWith string matcher'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index 28912d91..40b01067 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -279,6 +279,8 @@ Matchers.tests.cpp:|nexpression failed|n CHECK_THAT( testStringFor ##teamcity[testFinished name='Contains string matcher' duration="{duration}"] ##teamcity[testStarted name='Copy and then generate a range'] ##teamcity[testFinished name='Copy and then generate a range' duration="{duration}"] +##teamcity[testStarted name='Cout stream properly declares it writes to stdout'] +##teamcity[testFinished name='Cout stream properly declares it writes to stdout' duration="{duration}"] ##teamcity[testStarted name='Custom exceptions can be translated when testing for nothrow'] Exception.tests.cpp:|nunexpected exception with message:|n "custom exception - not std"|n REQUIRE_NOTHROW( throwCustom() )|nwith expansion:|n throwCustom()|n'] ##teamcity[testFinished name='Custom exceptions can be translated when testing for nothrow' duration="{duration}"] @@ -292,6 +294,8 @@ Exception.tests.cpp:|nunexpected exception with message:|n "custom ##teamcity[testFinished name='Default scale is invisible to comparison' duration="{duration}"] ##teamcity[testStarted name='Directly creating an EnumInfo'] ##teamcity[testFinished name='Directly creating an EnumInfo' duration="{duration}"] +##teamcity[testStarted name='Empty stream name opens cout stream'] +##teamcity[testFinished name='Empty stream name opens cout stream' duration="{duration}"] ##teamcity[testStarted name='Empty tag is not allowed'] ##teamcity[testFinished name='Empty tag is not allowed' duration="{duration}"] ##teamcity[testStarted name='EndsWith string matcher'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 91dc7e3c..7ac33d42 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -4205,6 +4205,17 @@ Nor would this + + + + Catch::makeStream( "-" )->isStdout() + + + true + + + + @@ -4287,6 +4298,17 @@ Nor would this + + + + Catch::makeStream( "" )->isStdout() + + + true + + + + @@ -20879,6 +20901,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 e7dddbb0..9db2ef87 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -4205,6 +4205,17 @@ Nor would this + + + + Catch::makeStream( "-" )->isStdout() + + + true + + + + @@ -4287,6 +4298,17 @@ Nor would this + + + + Catch::makeStream( "" )->isStdout() + + + true + + + + @@ -20878,6 +20900,6 @@ There is no extra whitespace here - - + + diff --git a/tests/SelfTest/IntrospectiveTests/Stream.tests.cpp b/tests/SelfTest/IntrospectiveTests/Stream.tests.cpp new file mode 100644 index 00000000..8a3aad46 --- /dev/null +++ b/tests/SelfTest/IntrospectiveTests/Stream.tests.cpp @@ -0,0 +1,19 @@ + +// 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 + +TEST_CASE( "Cout stream properly declares it writes to stdout", "[streams]" ) { + REQUIRE( Catch::makeStream( "-" )->isStdout() ); +} + +TEST_CASE( "Empty stream name opens cout stream", "[streams]" ) { + REQUIRE( Catch::makeStream( "" )->isStdout() ); +}