Progmasoft Git

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

Fix compilation error when lambdas are used in assertions

This is a partial revert of b7b346c3e5603.
Commit
5198fd3c9a4cd943786020abbdfc15dc5789be6f
Author
Martin Hořeňovský ·
Parents
08f8a81b2c7e

Files · Download .tar.gz

Changes

 src/catch2/internal/catch_compiler_capabilities.hpp |  2 --
 src/catch2/internal/catch_test_macro_impl.hpp       |  2 +-
 tests/SelfTest/Baselines/automake.sw.approved.txt   |  1 +
 tests/SelfTest/Baselines/compact.sw.approved.txt    |  1 +
 tests/SelfTest/Baselines/console.std.approved.txt   |  4 ++--
 tests/SelfTest/Baselines/console.sw.approved.txt    | 15 +++++++++++++--
 tests/SelfTest/Baselines/junit.sw.approved.txt      |  3 ++-
 tests/SelfTest/Baselines/sonarqube.sw.approved.txt  |  1 +
 tests/SelfTest/Baselines/tap.sw.approved.txt        |  4 +++-
 tests/SelfTest/Baselines/teamcity.sw.approved.txt   |  2 ++
 tests/SelfTest/Baselines/xml.sw.approved.txt        | 15 +++++++++++++--
 tests/SelfTest/UsageTests/Compilation.tests.cpp     |  3 +++
 12 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/src/catch2/internal/catch_compiler_capabilities.hpp b/src/catch2/internal/catch_compiler_capabilities.hpp
index 2cc7fd3c..f7a4632d 100644
--- a/src/catch2/internal/catch_compiler_capabilities.hpp
+++ b/src/catch2/internal/catch_compiler_capabilities.hpp
@@ -148,8 +148,6 @@
 #  define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
 #  define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION  __pragma( warning(pop) )
 
-#  define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)sizeof(__VA_ARGS__)
-
 #  if _MSC_VER >= 1900 // Visual Studio 2015 or newer
 #    define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
 #  endif
diff --git a/src/catch2/internal/catch_test_macro_impl.hpp b/src/catch2/internal/catch_test_macro_impl.hpp
index 560a4d5b..ffb767ed 100644
--- a/src/catch2/internal/catch_test_macro_impl.hpp
+++ b/src/catch2/internal/catch_test_macro_impl.hpp
@@ -56,7 +56,7 @@
             CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
         } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
         INTERNAL_CATCH_REACT( catchAssertionHandler ) \
-    } while( false )
+    } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) )
 
 ///////////////////////////////////////////////////////////////////////////////
 #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt
index e67937c7..a2e09a16 100644
--- a/tests/SelfTest/Baselines/automake.sw.approved.txt
+++ b/tests/SelfTest/Baselines/automake.sw.approved.txt
@@ -138,6 +138,7 @@ Nor would this
 :test-result: FAIL INFO is reset for each loop
 :test-result: XFAIL Inequality checks that should fail
 :test-result: PASS Inequality checks that should succeed
+:test-result: PASS Lambdas in assertions
 :test-result: PASS Less-than inequalities with different epsilons
 :test-result: PASS ManuallyRegistered
 :test-result: PASS Matchers can be (AllOf) composed with the && operator
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt
index 95bb91ee..464843ab 100644
--- a/tests/SelfTest/Baselines/compact.sw.approved.txt
+++ b/tests/SelfTest/Baselines/compact.sw.approved.txt
@@ -818,6 +818,7 @@ Condition.tests.cpp:<line number>: passed: data.str_hello != "goodbye" for: "hel
 Condition.tests.cpp:<line number>: passed: data.str_hello != "hell" for: "hello" != "hell"
 Condition.tests.cpp:<line number>: passed: data.str_hello != "hello1" for: "hello" != "hello1"
 Condition.tests.cpp:<line number>: passed: data.str_hello.size() != 6 for: 5 != 6
+Compilation.tests.cpp:<line number>: passed: []() { return true; }() for: true
 Approx.tests.cpp:<line number>: passed: d <= Approx( 1.24 ) for: 1.23 <= Approx( 1.24 )
 Approx.tests.cpp:<line number>: passed: d <= Approx( 1.23 ) for: 1.23 <= Approx( 1.23 )
 Approx.tests.cpp:<line number>: passed: !(d <= Approx( 1.22 )) for: !(1.23 <= Approx( 1.22 ))
diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt
index 234837e4..f5b3d035 100644
--- a/tests/SelfTest/Baselines/console.std.approved.txt
+++ b/tests/SelfTest/Baselines/console.std.approved.txt
@@ -1380,6 +1380,6 @@ due to unexpected exception with message:
   Why would you throw a std::string?
 
 ===============================================================================
-test cases:  331 |  257 passed |  70 failed |  4 failed as expected
-assertions: 1872 | 1720 passed | 131 failed | 21 failed as expected
+test cases:  332 |  258 passed |  70 failed |  4 failed as expected
+assertions: 1873 | 1721 passed | 131 failed | 21 failed as expected
 
diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt
index 9516b0b8..4aaf169e 100644
--- a/tests/SelfTest/Baselines/console.sw.approved.txt
+++ b/tests/SelfTest/Baselines/console.sw.approved.txt
@@ -6116,6 +6116,17 @@ Condition.tests.cpp:<line number>: PASSED:
 with expansion:
   5 != 6
 
+-------------------------------------------------------------------------------
+Lambdas in assertions
+-------------------------------------------------------------------------------
+Compilation.tests.cpp:<line number>
+...............................................................................
+
+Compilation.tests.cpp:<line number>: PASSED:
+  REQUIRE( []() { return true; }() )
+with expansion:
+  true
+
 -------------------------------------------------------------------------------
 Less-than inequalities with different epsilons
 -------------------------------------------------------------------------------
@@ -14647,6 +14658,6 @@ Misc.tests.cpp:<line number>
 Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
-test cases:  331 |  241 passed |  86 failed |  4 failed as expected
-assertions: 1889 | 1720 passed | 148 failed | 21 failed as expected
+test cases:  332 |  242 passed |  86 failed |  4 failed as expected
+assertions: 1890 | 1721 passed | 148 failed | 21 failed as expected
 
diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt
index de0e9c6b..d0707fce 100644
--- a/tests/SelfTest/Baselines/junit.sw.approved.txt
+++ b/tests/SelfTest/Baselines/junit.sw.approved.txt
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <testsuitesloose text artifact
 >
-  <testsuite name="<exe-name>" errors="17" failures="132" tests="1890" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="132" tests="1891" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
       <property name="random-seed" value="1"/>
@@ -769,6 +769,7 @@ Condition.tests.cpp:<line number>
       </failure>
     </testcase>
     <testcase classname="<exe-name>.global" name="Inequality checks that should succeed" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="Lambdas in assertions" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Less-than inequalities with different epsilons" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="ManuallyRegistered" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Matchers can be (AllOf) composed with the &amp;&amp; operator" time="{duration}"/>
diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
index c50a6876..e067cac7 100644
--- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
+++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt
@@ -393,6 +393,7 @@ Class.tests.cpp:<line number>
     <testCase name="#809" duration="{duration}"/>
     <testCase name="#833" duration="{duration}"/>
     <testCase name="#872" duration="{duration}"/>
+    <testCase name="Lambdas in assertions" duration="{duration}"/>
     <testCase name="Optionally static assertions" duration="{duration}"/>
   </file>
   <file path="tests/<exe-name>/UsageTests/Condition.tests.cpp">
diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt
index 0168d313..7a39fc91 100644
--- a/tests/SelfTest/Baselines/tap.sw.approved.txt
+++ b/tests/SelfTest/Baselines/tap.sw.approved.txt
@@ -1618,6 +1618,8 @@ ok {test-number} - data.str_hello != "hell" for: "hello" != "hell"
 ok {test-number} - data.str_hello != "hello1" for: "hello" != "hello1"
 # Inequality checks that should succeed
 ok {test-number} - data.str_hello.size() != 6 for: 5 != 6
+# Lambdas in assertions
+ok {test-number} - []() { return true; }() for: true
 # Less-than inequalities with different epsilons
 ok {test-number} - d <= Approx( 1.24 ) for: 1.23 <= Approx( 1.24 )
 # Less-than inequalities with different epsilons
@@ -3770,5 +3772,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
 ok {test-number} -
 # xmlentitycheck
 ok {test-number} -
-1..1881
+1..1882
 
diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
index a48b4612..5d760c5e 100644
--- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt
+++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt
@@ -352,6 +352,8 @@ Condition.tests.cpp:<line number>|nexpression failed|n  CHECK( data.str_hello.si
 ##teamcity[testFinished name='Inequality checks that should fail' duration="{duration}"]
 ##teamcity[testStarted name='Inequality checks that should succeed']
 ##teamcity[testFinished name='Inequality checks that should succeed' duration="{duration}"]
+##teamcity[testStarted name='Lambdas in assertions']
+##teamcity[testFinished name='Lambdas in assertions' duration="{duration}"]
 ##teamcity[testStarted name='Less-than inequalities with different epsilons']
 ##teamcity[testFinished name='Less-than inequalities with different epsilons' duration="{duration}"]
 ##teamcity[testStarted name='ManuallyRegistered']
diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt
index b1c59382..8cffea07 100644
--- a/tests/SelfTest/Baselines/xml.sw.approved.txt
+++ b/tests/SelfTest/Baselines/xml.sw.approved.txt
@@ -7635,6 +7635,17 @@ Nor would this
       </Expression>
       <OverallResult success="true"/>
     </TestCase>
+    <TestCase name="Lambdas in assertions" filename="tests/<exe-name>/UsageTests/Compilation.tests.cpp" >
+      <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Compilation.tests.cpp" >
+        <Original>
+          []() { return true; }()
+        </Original>
+        <Expanded>
+          true
+        </Expanded>
+      </Expression>
+      <OverallResult success="true"/>
+    </TestCase>
     <TestCase name="Less-than inequalities with different epsilons" tags="[Approx]" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" >
       <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" >
         <Original>
@@ -17557,7 +17568,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="1720" failures="149" expectedFailures="21"/>
+    <OverallResults successes="1721" failures="149" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="1720" failures="148" expectedFailures="21"/>
+  <OverallResults successes="1721" failures="148" expectedFailures="21"/>
 </Catch>
diff --git a/tests/SelfTest/UsageTests/Compilation.tests.cpp b/tests/SelfTest/UsageTests/Compilation.tests.cpp
index 839a1662..5a0ab65e 100644
--- a/tests/SelfTest/UsageTests/Compilation.tests.cpp
+++ b/tests/SelfTest/UsageTests/Compilation.tests.cpp
@@ -231,6 +231,9 @@ namespace { namespace CompilationTests {
         }
     }
 
+    TEST_CASE("Lambdas in assertions") {
+        REQUIRE([]() { return true; }());
+    }
 
 }} // namespace CompilationTests