More macros are now variadic

Also added tests for them
This commit is contained in:
Martin Hořeňovský 2017-05-03 19:10:27 +02:00
parent c5c3d368a2
commit a9128d0fac
6 changed files with 212 additions and 40 deletions

View File

@ -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<void>(expr); \
static_cast<void>(__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<void>(expr); \
static_cast<void>(__VA_ARGS__); \
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
} \
catch( ... ) { \

View File

@ -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

View File

@ -823,6 +823,74 @@ PASSED:
with expansion:
5 == 5
-------------------------------------------------------------------------------
Commas in various macros are allowed
-------------------------------------------------------------------------------
TrickyTests.cpp:<line number>
...............................................................................
TrickyTests.cpp:<line number>:
PASSED:
REQUIRE_THROWS( std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} )
TrickyTests.cpp:<line number>:
PASSED:
CHECK_THROWS( std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} )
TrickyTests.cpp:<line number>:
PASSED:
REQUIRE_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} )
TrickyTests.cpp:<line number>:
PASSED:
CHECK_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} )
TrickyTests.cpp:<line number>:
PASSED:
REQUIRE( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
with expansion:
{ 1, 2 } == { 1, 2 }
TrickyTests.cpp:<line number>:
PASSED:
CHECK( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
with expansion:
{ 1, 2 } == { 1, 2 }
TrickyTests.cpp:<line number>:
PASSED:
REQUIRE_FALSE( std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} )
with expansion:
!({ 1, 2 } == { 1, 2, 3 })
TrickyTests.cpp:<line number>:
PASSED:
CHECK_FALSE( std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} )
with expansion:
!({ 1, 2 } == { 1, 2, 3 })
TrickyTests.cpp:<line number>:
PASSED:
CHECK_NOFAIL( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
with expansion:
{ 1, 2 } == { 1, 2 }
TrickyTests.cpp:<line number>:
PASSED:
CHECKED_IF( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
with expansion:
{ 1, 2 } == { 1, 2 }
TrickyTests.cpp:<line number>:
PASSED:
REQUIRE( true )
TrickyTests.cpp:<line number>:
PASSED:
CHECKED_ELSE( std::vector<int>{1, 2} == std::vector<int>{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:<line number>
...............................................................................
TrickyTests.cpp:<line number>:
PASSED:
REQUIRE( std::vector<int>{1, 2} == std::vector<int>{1, 2} )
with expansion:
{ 1, 2 } == { 1, 2 }
-------------------------------------------------------------------------------
atomic if
-------------------------------------------------------------------------------
@ -9492,6 +9548,6 @@ MiscTests.cpp:<line number>:
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

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesspanner>
<testsuite name="<exe-name>" errors="13" failures="77" tests="972" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="13" failures="77" tests="983" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="#748 - captures with unexpected exceptions" name="outside assertions" time="{duration}">
<error type="TEST_CASE">
@ -109,6 +109,7 @@ ExceptionTests.cpp:<line number>
<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}"/>
<testcase classname="global" name="Commas in various macros are allowed" time="{duration}"/>
<testcase classname="global" name="Comparing function pointers" time="{duration}"/>
<testcase classname="global" name="Comparing member function pointers" time="{duration}"/>
<testcase classname="global" name="Comparisons between ints where one side is computed" time="{duration}"/>
@ -608,7 +609,6 @@ ExceptionTests.cpp:<line number>
<testcase classname="XmlEncode" name="string with quotes" time="{duration}"/>
<testcase classname="XmlEncode" name="string with control char (1)" time="{duration}"/>
<testcase classname="XmlEncode" name="string with control char (x7F)" time="{duration}"/>
<testcase classname="global" name="assertions with commas are allowed" time="{duration}"/>
<testcase classname="global" name="atomic if" time="{duration}"/>
<testcase classname="global" name="boolean member" time="{duration}"/>
<testcase classname="global" name="checkedElse" time="{duration}"/>

View File

@ -898,6 +898,105 @@
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Commas in various macros are allowed" filename="projects/<exe-name>/TrickyTests.cpp" >
<Expression success="true" type="REQUIRE_THROWS" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
</Original>
<Expanded>
std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
</Expanded>
</Expression>
<Expression success="true" type="CHECK_THROWS" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
</Original>
<Expanded>
std::vector&lt;constructor_throws>{constructor_throws{}, constructor_throws{}}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
</Original>
<Expanded>
std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
</Expanded>
</Expression>
<Expression success="true" type="CHECK_NOTHROW" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
</Original>
<Expanded>
std::vector&lt;int>{1, 2, 3} == std::vector&lt;int>{1, 2, 3}
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
</Original>
<Expanded>
{ 1, 2 } == { 1, 2 }
</Expanded>
</Expression>
<Expression success="true" type="CHECK" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
</Original>
<Expanded>
{ 1, 2 } == { 1, 2 }
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_FALSE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
!std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2, 3}
</Original>
<Expanded>
!({ 1, 2 } == { 1, 2, 3 })
</Expanded>
</Expression>
<Expression success="true" type="CHECK_FALSE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
!std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2, 3}
</Original>
<Expanded>
!({ 1, 2 } == { 1, 2, 3 })
</Expanded>
</Expression>
<Expression success="true" type="CHECK_NOFAIL" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
</Original>
<Expanded>
{ 1, 2 } == { 1, 2 }
</Expanded>
</Expression>
<Expression success="true" type="CHECKED_IF" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
</Original>
<Expanded>
{ 1, 2 } == { 1, 2 }
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
true
</Original>
<Expanded>
true
</Expanded>
</Expression>
<Expression success="true" type="CHECKED_ELSE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
</Original>
<Expanded>
{ 1, 2 } == { 1, 2 }
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Comparing function pointers" tags="[Tricky][function pointer]" filename="projects/<exe-name>/TrickyTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
@ -9086,14 +9185,6 @@ there"
<OverallResult success="true"/>
</TestCase>
<TestCase name="assertions with commas are allowed" filename="projects/<exe-name>/TrickyTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
std::vector&lt;int>{1, 2} == std::vector&lt;int>{1, 2}
</Original>
<Expanded>
{ 1, 2 } == { 1, 2 }
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="atomic if" tags="[0][failing]" filename="projects/<exe-name>/MiscTests.cpp" >
@ -10139,7 +10230,7 @@ spanner <OverallResult success="true"/>
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="861" failures="90" expectedFailures="21"/>
<OverallResults successes="872" failures="90" expectedFailures="21"/>
</Group>
<OverallResults successes="861" failures="89" expectedFailures="21"/>
<OverallResults successes="872" failures="89" expectedFailures="21"/>
</Catch>

View File

@ -396,6 +396,31 @@ TEST_CASE( "has printf", "" ) {
}
TEST_CASE( "assertions with commas are allowed" ) {
REQUIRE( std::vector<int>{1, 2} == std::vector<int>{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{}, constructor_throws{}} );
CHECK_THROWS( std::vector<constructor_throws>{constructor_throws{}, constructor_throws{}} );
REQUIRE_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} );
CHECK_NOTHROW( std::vector<int>{1, 2, 3} == std::vector<int>{1, 2, 3} );
REQUIRE(std::vector<int>{1, 2} == std::vector<int>{1, 2});
CHECK( std::vector<int>{1, 2} == std::vector<int>{1, 2} );
REQUIRE_FALSE(std::vector<int>{1, 2} == std::vector<int>{1, 2, 3});
CHECK_FALSE( std::vector<int>{1, 2} == std::vector<int>{1, 2, 3} );
CHECK_NOFAIL( std::vector<int>{1, 2} == std::vector<int>{1, 2} );
CHECKED_IF( std::vector<int>{1, 2} == std::vector<int>{1, 2} ) {
REQUIRE(true);
} CHECKED_ELSE( std::vector<int>{1, 2} == std::vector<int>{1, 2} ) {
CHECK(true);
}
}