diff --git a/include/internal/catch_console_colour_impl.hpp b/include/internal/catch_console_colour_impl.hpp index ba2a9d1c..426bba29 100644 --- a/include/internal/catch_console_colour_impl.hpp +++ b/include/internal/catch_console_colour_impl.hpp @@ -9,6 +9,7 @@ #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED #include "catch_console_colour.hpp" +#include "catch_errno_guard.hpp" namespace Catch { namespace { @@ -148,6 +149,7 @@ namespace { }; IColourImpl* platformColourInstance() { + ErrnoGuard guard; Ptr config = getCurrentContext().getConfig(); UseColour::YesOrNo colourMode = config ? config->useColour() diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index e5dd3d31..fe0c0863 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -3,6 +3,17 @@ is a host application. Run with -? for options +------------------------------------------------------------------------------- +#835 -- errno should not be touched by Catch +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: FAILED: + CHECK( f() == 0 ) +with expansion: + 1 == 0 + ------------------------------------------------------------------------------- 'Not' checks that should fail ------------------------------------------------------------------------------- @@ -890,6 +901,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 164 | 119 passed | 43 failed | 2 failed as expected -assertions: 955 | 851 passed | 86 failed | 18 failed as expected +test cases: 165 | 119 passed | 44 failed | 2 failed as expected +assertions: 957 | 852 passed | 87 failed | 18 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 72d5dc07..4c92d229 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -48,6 +48,23 @@ PASSED: with expansion: 42 == {?} +------------------------------------------------------------------------------- +#835 -- errno should not be touched by Catch +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: FAILED: + CHECK( f() == 0 ) +with expansion: + 1 == 0 + +MiscTests.cpp:: +PASSED: + REQUIRE( (*__errno_location ()) == 1 ) +with expansion: + 1 == 1 + ------------------------------------------------------------------------------- 'Not' checks that should fail ------------------------------------------------------------------------------- @@ -9350,6 +9367,6 @@ MiscTests.cpp:: PASSED: =============================================================================== -test cases: 164 | 118 passed | 44 failed | 2 failed as expected -assertions: 957 | 851 passed | 88 failed | 18 failed as expected +test cases: 165 | 118 passed | 45 failed | 2 failed as expected +assertions: 959 | 852 passed | 89 failed | 18 failed as expected diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt index 098c33d2..6c4f19a0 100644 --- a/projects/SelfTest/Baselines/console.swa4.approved.txt +++ b/projects/SelfTest/Baselines/console.swa4.approved.txt @@ -48,6 +48,23 @@ PASSED: with expansion: 42 == {?} +------------------------------------------------------------------------------- +#835 -- errno should not be touched by Catch +------------------------------------------------------------------------------- +MiscTests.cpp: +............................................................................... + +MiscTests.cpp:: FAILED: + CHECK( f() == 0 ) +with expansion: + 1 == 0 + +MiscTests.cpp:: +PASSED: + REQUIRE( (*__errno_location ()) == 1 ) +with expansion: + 1 == 1 + ------------------------------------------------------------------------------- 'Not' checks that should fail ------------------------------------------------------------------------------- @@ -65,10 +82,7 @@ ConditionTests.cpp:: FAILED: with expansion: false -ConditionTests.cpp:: FAILED: - CHECK_FALSE( true ) - =============================================================================== -test cases: 4 | 3 passed | 1 failed -assertions: 10 | 6 passed | 4 failed +test cases: 5 | 3 passed | 2 failed +assertions: 11 | 7 passed | 4 failed diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 41cfb464..2bec8e6b 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,9 +1,14 @@ - + + + +MiscTests.cpp: + + ConditionTests.cpp: diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index ab6ab08b..f77b7e52 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -50,6 +50,25 @@ + + + + f() == 0 + + + 1 == 0 + + + + + (*__errno_location ()) == 1 + + + 1 == 1 + + + + @@ -9988,7 +10007,7 @@ spanner - + - + diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp index 88a524f8..e98b2630 100644 --- a/projects/SelfTest/MiscTests.cpp +++ b/projects/SelfTest/MiscTests.cpp @@ -16,6 +16,7 @@ #include "../include/internal/catch_xmlwriter.hpp" #include +#include TEST_CASE( "random SECTION tests", "[.][sections][failing]" ) { @@ -393,3 +394,14 @@ TEST_CASE( "This test 'should' fail but doesn't", "[.][failing][!shouldfail]" ) TEST_CASE( "# A test name that starts with a #" ) { SUCCEED( "yay" ); } + + +static int f() { + return 1; +} + +TEST_CASE( "#835 -- errno should not be touched by Catch" ) { + errno = 1; + CHECK(f() == 0); + REQUIRE(errno == 1); // Check that f() doesn't touch errno. +}