diff --git a/docs/logging.md b/docs/logging.md index a659b3e8..01c6fbc7 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -26,6 +26,10 @@ The message is always reported but does not fail the test. The message is reported and the test case fails. +**FAIL_CHECK(** _message expression_ **)** + +AS `FAIL`, but does not abort the test + ## Quickly capture a variable value **CAPTURE(** _expression_ **)** diff --git a/include/catch.hpp b/include/catch.hpp index 5d009ee0..91ef93b7 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -126,6 +126,7 @@ LeakDetector leakDetector; #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ ) + #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "CATCH_FAIL_CHECK", __VA_ARGS__ ) #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ ) #else #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) @@ -134,6 +135,7 @@ LeakDetector leakDetector; #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description ) #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg ) + #define CATCH_FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "CATCH_FAIL_CHECK", msg ) #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg ) #endif #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) @@ -189,20 +191,22 @@ LeakDetector leakDetector; #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__ ) - #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) - #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) - #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) - #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) - #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ ) - #define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ ) +#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) +#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) +#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) +#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) +#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ ) +#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "FAIL_CHECK", __VA_ARGS__ ) +#define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ ) #else - #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) +#define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description ) #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg ) + #define FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "FAIL_CHECK", msg ) #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg ) #endif #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index fe0c0863..ef6948d2 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -287,6 +287,20 @@ MessageTests.cpp: MessageTests.cpp:: FAILED: +------------------------------------------------------------------------------- +FAIL_CHECK does not abort the test +------------------------------------------------------------------------------- +MessageTests.cpp: +............................................................................... + +MessageTests.cpp:: FAILED: +explicitly with message: + This is a failure + +MessageTests.cpp:: +warning: + This message appears in the output + ------------------------------------------------------------------------------- INFO and WARN do not abort tests ------------------------------------------------------------------------------- @@ -901,6 +915,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 165 | 119 passed | 44 failed | 2 failed as expected -assertions: 957 | 852 passed | 87 failed | 18 failed as expected +test cases: 166 | 119 passed | 44 failed | 3 failed as expected +assertions: 958 | 852 passed | 87 failed | 19 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 4c92d229..7558e0c3 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -61,7 +61,7 @@ with expansion: MiscTests.cpp:: PASSED: - REQUIRE( (*__errno_location ()) == 1 ) + REQUIRE( (*__error()) == 1 ) with expansion: 1 == 1 @@ -1216,6 +1216,20 @@ MessageTests.cpp: MessageTests.cpp:: FAILED: +------------------------------------------------------------------------------- +FAIL_CHECK does not abort the test +------------------------------------------------------------------------------- +MessageTests.cpp: +............................................................................... + +MessageTests.cpp:: FAILED: +explicitly with message: + This is a failure + +MessageTests.cpp:: +warning: + This message appears in the output + ------------------------------------------------------------------------------- Factorials are computed ------------------------------------------------------------------------------- @@ -9367,6 +9381,6 @@ MiscTests.cpp:: PASSED: =============================================================================== -test cases: 165 | 118 passed | 45 failed | 2 failed as expected -assertions: 959 | 852 passed | 89 failed | 18 failed as expected +test cases: 166 | 118 passed | 45 failed | 3 failed as expected +assertions: 960 | 852 passed | 89 failed | 19 failed as expected diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt index 6c4f19a0..aec6b675 100644 --- a/projects/SelfTest/Baselines/console.swa4.approved.txt +++ b/projects/SelfTest/Baselines/console.swa4.approved.txt @@ -61,7 +61,7 @@ with expansion: MiscTests.cpp:: PASSED: - REQUIRE( (*__errno_location ()) == 1 ) + REQUIRE( (*__error()) == 1 ) with expansion: 1 == 1 @@ -82,7 +82,10 @@ ConditionTests.cpp:: FAILED: with expansion: false -=============================================================================== -test cases: 5 | 3 passed | 2 failed -assertions: 11 | 7 passed | 4 failed +ConditionTests.cpp:: FAILED: + CHECK_FALSE( true ) + +=============================================================================== +test cases: 5 | 3 passed | 1 failed | 1 failed as expected +assertions: 12 | 7 passed | 4 failed | 1 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 2bec8e6b..44a6e56a 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,6 +1,6 @@ - + @@ -199,6 +199,12 @@ MessageTests.cpp: +MessageTests.cpp: + + + + +This is a failure MessageTests.cpp: diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index f77b7e52..5db8eff2 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -50,7 +50,7 @@ - + f() == 0 @@ -61,13 +61,13 @@ - (*__errno_location ()) == 1 + (*__error()) == 1 1 == 1 - + @@ -1378,6 +1378,15 @@ + + + This is a failure + + + This message appears in the output + + + @@ -10007,7 +10016,7 @@ spanner - + - + diff --git a/projects/SelfTest/MessageTests.cpp b/projects/SelfTest/MessageTests.cpp index 87a85a82..bed9c137 100644 --- a/projects/SelfTest/MessageTests.cpp +++ b/projects/SelfTest/MessageTests.cpp @@ -53,6 +53,13 @@ TEST_CASE( "INFO gets logged on failure, even if captured before successful asse TEST_CASE( "FAIL aborts the test", "[failing][messages][.]" ) { FAIL( "This is a " << "failure" ); // This should output the message and abort + WARN( "We should never see this"); +} + +TEST_CASE( "FAIL_CHECK does not abort the test", "[failing][messages][.]" ) +{ + FAIL_CHECK( "This is a " << "failure" ); // This should output the message then continue + WARN( "This message appears in the output"); } #ifdef CATCH_CONFIG_VARIADIC_MACROS