catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Add tests for #835
- Commit
ace70407a260a023fd3513740251df1e676435bd- Author
- Martin Hořeňovský ·
- Parents
613e1466f9ef
Changes
include/internal/catch_console_colour_impl.hpp | 2 ++ .../SelfTest/Baselines/console.std.approved.txt | 15 ++++++++++++-- .../SelfTest/Baselines/console.sw.approved.txt | 21 +++++++++++++++++-- .../SelfTest/Baselines/console.swa4.approved.txt | 24 +++++++++++++++++----- projects/SelfTest/Baselines/junit.sw.approved.txt | 7 ++++++- projects/SelfTest/Baselines/xml.sw.approved.txt | 23 +++++++++++++++++++-- projects/SelfTest/MiscTests.cpp | 12 +++++++++++ 7 files changed, 92 insertions(+), 12 deletions(-) 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<IConfig const> 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 @@ <exe-name> is a <version> host application. Run with -? for options +------------------------------------------------------------------------------- +#835 -- errno should not be touched by Catch +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: 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:<line number> +............................................................................... + +MiscTests.cpp:<line number>: FAILED: + CHECK( f() == 0 ) +with expansion: + 1 == 0 + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( (*__errno_location ()) == 1 ) +with expansion: + 1 == 1 + ------------------------------------------------------------------------------- 'Not' checks that should fail ------------------------------------------------------------------------------- @@ -9350,6 +9367,6 @@ MiscTests.cpp:<line number>: 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:<line number> +............................................................................... + +MiscTests.cpp:<line number>: FAILED: + CHECK( f() == 0 ) +with expansion: + 1 == 0 + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( (*__errno_location ()) == 1 ) +with expansion: + 1 == 1 + ------------------------------------------------------------------------------- 'Not' checks that should fail ------------------------------------------------------------------------------- @@ -65,10 +82,7 @@ ConditionTests.cpp:<line number>: FAILED: with expansion: false -ConditionTests.cpp:<line number>: 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 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesspanner> - <testsuite name="<exe-name>" errors="13" failures="76" tests="958" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="13" failures="77" tests="960" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="global" name="#542" time="{duration}"/> <testcase classname="global" name="#809" time="{duration}"/> + <testcase classname="global" name="#835 -- errno should not be touched by Catch" time="{duration}"> + <failure message="1 == 0" type="CHECK"> +MiscTests.cpp:<line number> + </failure> + </testcase> <testcase classname="global" name="'Not' checks that should fail" time="{duration}"> <failure message="false != false" type="CHECK"> ConditionTests.cpp:<line number> 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 @@ </Expression> <OverallResult success="true"/> </TestCase> + <TestCase name="#835 -- errno should not be touched by Catch" filename="projects/<exe-name>/MiscTests.cpp" > + <Expression success="false" type="CHECK" filename="projects/<exe-name>/MiscTests.cpp" > + <Original> + f() == 0 + </Original> + <Expanded> + 1 == 0 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/MiscTests.cpp" > + <Original> + (*__errno_location ()) == 1 + </Original> + <Expanded> + 1 == 1 + </Expanded> + </Expression> + <OverallResult success="false"/> + </TestCase> <TestCase name="'Not' checks that should fail" tags="[.][failing][hide]" filename="projects/<exe-name>/ConditionTests.cpp" > <Expression success="false" type="CHECK" filename="projects/<exe-name>/ConditionTests.cpp" > <Original> @@ -9988,7 +10007,7 @@ spanner <OverallResult success="true"/> </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="851" failures="89" expectedFailures="18"/> + <OverallResults successes="852" failures="90" expectedFailures="18"/> </Group> - <OverallResults successes="851" failures="88" expectedFailures="18"/> + <OverallResults successes="852" failures="89" expectedFailures="18"/> </Catch> 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 <iostream> +#include <cerrno> 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. +}