From a9128d0faca8bd0f0d323e5309c5322473fd7c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Wed, 3 May 2017 19:10:27 +0200 Subject: [PATCH] More macros are now variadic Also added tests for them --- include/internal/catch_capture.hpp | 20 ++-- .../Baselines/console.std.approved.txt | 4 +- .../Baselines/console.sw.approved.txt | 84 ++++++++++--- .../SelfTest/Baselines/junit.sw.approved.txt | 4 +- .../SelfTest/Baselines/xml.sw.approved.txt | 111 ++++++++++++++++-- projects/SelfTest/TrickyTests.cpp | 29 ++++- 6 files changed, 212 insertions(+), 40 deletions(-) diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index b0418d46..49673309 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -81,21 +81,21 @@ // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. /////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_IF( macroName, resultDisposition, expr ) \ - INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \ +#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ if( Catch::getResultCapture().getLastResult()->succeeded() ) /////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, expr ) \ - INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \ +#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \ + INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \ if( !Catch::getResultCapture().getLastResult()->succeeded() ) /////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, expr ) \ +#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \ do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__, resultDisposition ); \ try { \ - static_cast(expr); \ + static_cast(__VA_ARGS__); \ __catchResult.captureResult( Catch::ResultWas::Ok ); \ } \ catch( ... ) { \ @@ -105,12 +105,12 @@ } while( Catch::alwaysFalse() ) /////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, expr ) \ +#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, ... ) \ do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__, resultDisposition, #matcher ); \ if( __catchResult.allowThrows() ) \ try { \ - static_cast(expr); \ + static_cast(__VA_ARGS__); \ __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ } \ catch( ... ) { \ diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index b07d6f3a..c35d3bd1 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -940,6 +940,6 @@ with expansion: "first" == "second" =============================================================================== -test cases: 169 | 121 passed | 44 failed | 4 failed as expected -assertions: 969 | 861 passed | 87 failed | 21 failed as expected +test cases: 170 | 122 passed | 44 failed | 4 failed as expected +assertions: 980 | 872 passed | 87 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 9b857c4f..68227089 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -823,6 +823,74 @@ PASSED: with expansion: 5 == 5 +------------------------------------------------------------------------------- +Commas in various macros are allowed +------------------------------------------------------------------------------- +TrickyTests.cpp: +............................................................................... + +TrickyTests.cpp:: +PASSED: + REQUIRE_THROWS( std::vector{constructor_throws{}, constructor_throws{}} ) + +TrickyTests.cpp:: +PASSED: + CHECK_THROWS( std::vector{constructor_throws{}, constructor_throws{}} ) + +TrickyTests.cpp:: +PASSED: + REQUIRE_NOTHROW( std::vector{1, 2, 3} == std::vector{1, 2, 3} ) + +TrickyTests.cpp:: +PASSED: + CHECK_NOTHROW( std::vector{1, 2, 3} == std::vector{1, 2, 3} ) + +TrickyTests.cpp:: +PASSED: + REQUIRE( std::vector{1, 2} == std::vector{1, 2} ) +with expansion: + { 1, 2 } == { 1, 2 } + +TrickyTests.cpp:: +PASSED: + CHECK( std::vector{1, 2} == std::vector{1, 2} ) +with expansion: + { 1, 2 } == { 1, 2 } + +TrickyTests.cpp:: +PASSED: + REQUIRE_FALSE( std::vector{1, 2} == std::vector{1, 2, 3} ) +with expansion: + !({ 1, 2 } == { 1, 2, 3 }) + +TrickyTests.cpp:: +PASSED: + CHECK_FALSE( std::vector{1, 2} == std::vector{1, 2, 3} ) +with expansion: + !({ 1, 2 } == { 1, 2, 3 }) + +TrickyTests.cpp:: +PASSED: + CHECK_NOFAIL( std::vector{1, 2} == std::vector{1, 2} ) +with expansion: + { 1, 2 } == { 1, 2 } + +TrickyTests.cpp:: +PASSED: + CHECKED_IF( std::vector{1, 2} == std::vector{1, 2} ) +with expansion: + { 1, 2 } == { 1, 2 } + +TrickyTests.cpp:: +PASSED: + REQUIRE( true ) + +TrickyTests.cpp:: +PASSED: + CHECKED_ELSE( std::vector{1, 2} == std::vector{1, 2} ) +with expansion: + { 1, 2 } == { 1, 2 } + ------------------------------------------------------------------------------- Comparing function pointers ------------------------------------------------------------------------------- @@ -8461,18 +8529,6 @@ PASSED: with expansion: "[\x7F]" == "[\x7F]" -------------------------------------------------------------------------------- -assertions with commas are allowed -------------------------------------------------------------------------------- -TrickyTests.cpp: -............................................................................... - -TrickyTests.cpp:: -PASSED: - REQUIRE( std::vector{1, 2} == std::vector{1, 2} ) -with expansion: - { 1, 2 } == { 1, 2 } - ------------------------------------------------------------------------------- atomic if ------------------------------------------------------------------------------- @@ -9492,6 +9548,6 @@ MiscTests.cpp:: PASSED: =============================================================================== -test cases: 169 | 120 passed | 45 failed | 4 failed as expected -assertions: 971 | 861 passed | 89 failed | 21 failed as expected +test cases: 170 | 121 passed | 45 failed | 4 failed as expected +assertions: 982 | 872 passed | 89 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index ce6f7d23..5de62625 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,6 +1,6 @@ - + @@ -109,6 +109,7 @@ ExceptionTests.cpp: + @@ -608,7 +609,6 @@ ExceptionTests.cpp: - diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 32d233a1..f0bfebd8 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -898,6 +898,105 @@ + + + + std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} + + + std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} + + + + + std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} + + + std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} + + + + + std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} + + + std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} + + + + + std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} + + + std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} + + + + + std::vector<int>{1, 2} == std::vector<int>{1, 2} + + + { 1, 2 } == { 1, 2 } + + + + + std::vector<int>{1, 2} == std::vector<int>{1, 2} + + + { 1, 2 } == { 1, 2 } + + + + + !std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} + + + !({ 1, 2 } == { 1, 2, 3 }) + + + + + !std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} + + + !({ 1, 2 } == { 1, 2, 3 }) + + + + + std::vector<int>{1, 2} == std::vector<int>{1, 2} + + + { 1, 2 } == { 1, 2 } + + + + + std::vector<int>{1, 2} == std::vector<int>{1, 2} + + + { 1, 2 } == { 1, 2 } + + + + + true + + + true + + + + + std::vector<int>{1, 2} == std::vector<int>{1, 2} + + + { 1, 2 } == { 1, 2 } + + + + @@ -9086,14 +9185,6 @@ there" - - - std::vector<int>{1, 2} == std::vector<int>{1, 2} - - - { 1, 2 } == { 1, 2 } - - @@ -10139,7 +10230,7 @@ spanner - + - + diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index e5616d0e..4dfdf39e 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -396,6 +396,31 @@ TEST_CASE( "has printf", "" ) { } TEST_CASE( "assertions with commas are allowed" ) { - - REQUIRE( std::vector{1, 2} == std::vector{1, 2} ); +} + +namespace { + struct constructor_throws { + constructor_throws() { + throw 1; + } + }; +} + +TEST_CASE("Commas in various macros are allowed") { + REQUIRE_THROWS( std::vector{constructor_throws{}, constructor_throws{}} ); + CHECK_THROWS( std::vector{constructor_throws{}, constructor_throws{}} ); + REQUIRE_NOTHROW( std::vector{1, 2, 3} == std::vector{1, 2, 3} ); + CHECK_NOTHROW( std::vector{1, 2, 3} == std::vector{1, 2, 3} ); + + REQUIRE(std::vector{1, 2} == std::vector{1, 2}); + CHECK( std::vector{1, 2} == std::vector{1, 2} ); + REQUIRE_FALSE(std::vector{1, 2} == std::vector{1, 2, 3}); + CHECK_FALSE( std::vector{1, 2} == std::vector{1, 2, 3} ); + + CHECK_NOFAIL( std::vector{1, 2} == std::vector{1, 2} ); + CHECKED_IF( std::vector{1, 2} == std::vector{1, 2} ) { + REQUIRE(true); + } CHECKED_ELSE( std::vector{1, 2} == std::vector{1, 2} ) { + CHECK(true); + } }