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
Change reporting of CAPTURE'd variables
- Commit
be4f6ab8e19ff16d17c8a6d9287999c6b965d04e- Author
- Martin Hořeňovský ·
- Parents
fd6c7aee6dff
Changes
include/catch.hpp | 8 +++--- .../SelfTest/Baselines/console.std.approved.txt | 4 +-- .../SelfTest/Baselines/console.sw.approved.txt | 32 ++++++++++++++++++++-- projects/SelfTest/Baselines/junit.sw.approved.txt | 6 ++-- projects/SelfTest/Baselines/xml.sw.approved.txt | 31 +++++++++++++++++++-- projects/SelfTest/ToStringGeneralTests.cpp | 14 ++++++++++ 6 files changed, 81 insertions(+), 14 deletions(-) diff --git a/include/catch.hpp b/include/catch.hpp index 997f3ccc..5d009ee0 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -116,8 +116,8 @@ LeakDetector leakDetector; #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg ) #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) -#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) -#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) +#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CATCH_CAPTURE" ) +#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CATCH_CAPTURE" ) #ifdef CATCH_CONFIG_VARIADIC_MACROS #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) @@ -185,8 +185,8 @@ LeakDetector leakDetector; #define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) #define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg ) #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) -#define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) -#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) +#define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CAPTURE" ) +#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CAPTURE" ) #ifdef CATCH_CONFIG_VARIADIC_MACROS #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index ecd074a5..e5dd3d31 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -890,6 +890,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 163 | 118 passed | 43 failed | 2 failed as expected -assertions: 953 | 849 passed | 86 failed | 18 failed as expected +test cases: 164 | 119 passed | 43 failed | 2 failed as expected +assertions: 955 | 851 passed | 86 failed | 18 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 55137b31..72d5dc07 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -603,6 +603,32 @@ PASSED: with expansion: true +------------------------------------------------------------------------------- +Capture and info messages + Capture should stringify like assertions +------------------------------------------------------------------------------- +ToStringGeneralTests.cpp:<line number> +............................................................................... + +ToStringGeneralTests.cpp:<line number>: +PASSED: + REQUIRE( true ) +with message: + i := 2 + +------------------------------------------------------------------------------- +Capture and info messages + Info should NOT stringify the way assertions do +------------------------------------------------------------------------------- +ToStringGeneralTests.cpp:<line number> +............................................................................... + +ToStringGeneralTests.cpp:<line number>: +PASSED: + REQUIRE( true ) +with message: + 3 + ------------------------------------------------------------------------------- Character pretty printing Specifically escaped @@ -3292,7 +3318,7 @@ with expansion: re>" ------------------------------------------------------------------------------- -Long text is truncted +Long text is truncated ------------------------------------------------------------------------------- TestMain.cpp:<line number> ............................................................................... @@ -9324,6 +9350,6 @@ MiscTests.cpp:<line number>: PASSED: =============================================================================== -test cases: 163 | 117 passed | 44 failed | 2 failed as expected -assertions: 955 | 849 passed | 88 failed | 18 failed as expected +test cases: 164 | 118 passed | 44 failed | 2 failed as expected +assertions: 957 | 851 passed | 88 failed | 18 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 400b1c8b..41cfb464 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesspanner> - <testsuite name="<exe-name>" errors="13" failures="76" tests="956" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="13" failures="76" tests="958" 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}"/> @@ -83,6 +83,8 @@ ExceptionTests.cpp:<line number> <testcase classname="Assertions then sections" name="A section" time="{duration}"/> <testcase classname="Assertions then sections" name="A section/Another section" time="{duration}"/> <testcase classname="Assertions then sections" name="A section/Another other section" time="{duration}"/> + <testcase classname="Capture and info messages" name="Capture should stringify like assertions" time="{duration}"/> + <testcase classname="Capture and info messages" name="Info should NOT stringify the way assertions do" time="{duration}"/> <testcase classname="Character pretty printing" name="Specifically escaped" time="{duration}"/> <testcase classname="Character pretty printing" name="General chars" time="{duration}"/> <testcase classname="Character pretty printing" name="Low ASCII" time="{duration}"/> @@ -250,7 +252,7 @@ ConditionTests.cpp:<line number> <testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/No wrapping" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap before" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap after" time="{duration}"/> - <testcase classname="global" name="Long text is truncted" time="{duration}"/> + <testcase classname="global" name="Long text is truncated" time="{duration}"/> <testcase classname="global" name="ManuallyRegistered" time="{duration}"/> <testcase classname="global" name="Matchers can be (AllOf) composed with the && operator" time="{duration}"/> <testcase classname="global" name="Matchers can be (AnyOf) composed with the || operator" time="{duration}"/> diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 62e3abaf..f242568b 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -643,6 +643,31 @@ </Section> <OverallResult success="true"/> </TestCase> + <TestCase name="Capture and info messages" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > + <Section name="Capture should stringify like assertions" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > + <Original> + true + </Original> + <Expanded> + true + </Expanded> + </Expression> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> + <Section name="Info should NOT stringify the way assertions do" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > + <Original> + true + </Original> + <Expanded> + true + </Expanded> + </Expression> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> + <OverallResult success="true"/> + </TestCase> <TestCase name="Character pretty printing" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > <Section name="Specifically escaped" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > <Expression success="true" type="CHECK" filename="projects/<exe-name>/ToStringGeneralTests.cpp" > @@ -3409,7 +3434,7 @@ re>" </Section> <OverallResult success="true"/> </TestCase> - <TestCase name="Long text is truncted" tags="[Text][Truncated]" filename="projects/<exe-name>/TestMain.cpp" > + <TestCase name="Long text is truncated" tags="[Text][Truncated]" filename="projects/<exe-name>/TestMain.cpp" > <Expression success="true" type="CHECK_THAT" filename="projects/<exe-name>/TestMain.cpp" > <Original> t.toString(), EndsWith( "... message truncated due to excessive size" ) @@ -9885,7 +9910,7 @@ spanner <OverallResult success="true"/> </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="849" failures="89" expectedFailures="18"/> + <OverallResults successes="851" failures="89" expectedFailures="18"/> </Group> - <OverallResults successes="849" failures="88" expectedFailures="18"/> + <OverallResults successes="851" failures="88" expectedFailures="18"/> </Catch> diff --git a/projects/SelfTest/ToStringGeneralTests.cpp b/projects/SelfTest/ToStringGeneralTests.cpp index a9fa4b83..bca913fb 100644 --- a/projects/SelfTest/ToStringGeneralTests.cpp +++ b/projects/SelfTest/ToStringGeneralTests.cpp @@ -38,3 +38,17 @@ TEST_CASE( "Character pretty printing" ){ } } } + + +TEST_CASE( "Capture and info messages" ) { + SECTION("Capture should stringify like assertions") { + int i = 2; + CAPTURE(i); + REQUIRE(true); + } + SECTION("Info should NOT stringify the way assertions do") { + int i = 3; + INFO(i); + REQUIRE(true); + } +}