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

changed macro names: EXPECT -> REQUIRE, *_NOT -> *_FALSE

Commit
a2d20951a266bc1f5ccc2b0373a6cc4ecac26ef8
Author
Phil Nash ·
Parents
de77ff3b29fe

Files · Download .tar.gz

Changes

 Test/ClassTests.cpp     |  4 +--
 Test/ConditionTests.cpp | 93 ++++++++++++++++++++++++-------------------------
 Test/ExceptionTests.cpp |  6 ++--
 Test/MiscTests.cpp      |  6 ++--
 Test/TestMain.cpp       | 10 +++---
 Test/TrickyTests.cpp    |  4 +--
 catch.hpp               | 11 +++---
 7 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/Test/ClassTests.cpp b/Test/ClassTests.cpp
index 9213d34f..b205ed78 100644
--- a/Test/ClassTests.cpp
+++ b/Test/ClassTests.cpp
@@ -25,11 +25,11 @@ namespace
         
         void succeedingCase()
         {            
-            EXPECT( s == "hello" );
+            REQUIRE( s == "hello" );
         }
         void failingCase()
         {            
-            EXPECT( s == "world" );
+            REQUIRE( s == "world" );
         }
     };
 }
diff --git a/Test/ConditionTests.cpp b/Test/ConditionTests.cpp
index a48b29e8..6200f862 100644
--- a/Test/ConditionTests.cpp
+++ b/Test/ConditionTests.cpp
@@ -29,23 +29,22 @@ struct TestData
     double double_pi;
 };
 
-// These tests all use the CHECK macro, which continues if the specific test fails.
-// This allows us to see all results, even if an earlier check fails - which is 
-// particularly important for the "should fail" checks
+// The "failing" tests all use the CHECK macro, which continues if the specific test fails.
+// This allows us to see all results, even if an earlier check fails
 
 // Equality tests
 TEST_CASE( "succeeding/conditions/equality", "Equality checks that should succeed" )
 {
     TestData data;
     
-    CHECK( data.int_seven == 7 );
-    CHECK( data.float_nine_point_one == Approx( 9.1f ) );
-    CHECK( data.double_pi == Approx( 3.1415926535 ) );
-    CHECK( data.str_hello == "hello" );
-    CHECK( data.str_hello.size() == 5 );
+    REQUIRE( data.int_seven == 7 );
+    REQUIRE( data.float_nine_point_one == Approx( 9.1f ) );
+    REQUIRE( data.double_pi == Approx( 3.1415926535 ) );
+    REQUIRE( data.str_hello == "hello" );
+    REQUIRE( data.str_hello.size() == 5 );
 
     double x = 1.1 + 0.1 + 0.1;
-    CHECK( x == Approx( 1.3 ) );
+    REQUIRE( x == Approx( 1.3 ) );
 }
 
 TEST_CASE( "failing/conditions/equality", "Equality checks that should fail" )
@@ -73,17 +72,17 @@ TEST_CASE( "succeeding/conditions/inequality", "Inequality checks that should su
 {
     TestData data;
     
-    CHECK( data.int_seven != 6 );
-    CHECK( data.int_seven != 8 );
-    CHECK( data.float_nine_point_one != Approx( 9.11f ) );
-    CHECK( data.float_nine_point_one != Approx( 9.0f ) );
-    CHECK( data.float_nine_point_one != 1 );
-    CHECK( data.float_nine_point_one != 0 );
-    CHECK( data.double_pi != Approx( 3.1415 ) );
-    CHECK( data.str_hello != "goodbye" );
-    CHECK( data.str_hello != "hell" );
-    CHECK( data.str_hello != "hello1" );
-    CHECK( data.str_hello.size() != 6 );
+    REQUIRE( data.int_seven != 6 );
+    REQUIRE( data.int_seven != 8 );
+    REQUIRE( data.float_nine_point_one != Approx( 9.11f ) );
+    REQUIRE( data.float_nine_point_one != Approx( 9.0f ) );
+    REQUIRE( data.float_nine_point_one != 1 );
+    REQUIRE( data.float_nine_point_one != 0 );
+    REQUIRE( data.double_pi != Approx( 3.1415 ) );
+    REQUIRE( data.str_hello != "goodbye" );
+    REQUIRE( data.str_hello != "hell" );
+    REQUIRE( data.str_hello != "hello1" );
+    REQUIRE( data.str_hello.size() != 6 );
 }
 
 TEST_CASE( "failing/conditions/inequality", "Inequality checks that should fails" )
@@ -102,27 +101,27 @@ TEST_CASE( "succeeding/conditions/ordered", "Ordering comparison checks that sho
 {
     TestData data;
     
-    CHECK( data.int_seven < 8 );
-    CHECK( data.int_seven > 6 );
-    CHECK( data.int_seven > 0 );
-    CHECK( data.int_seven > -1 );
+    REQUIRE( data.int_seven < 8 );
+    REQUIRE( data.int_seven > 6 );
+    REQUIRE( data.int_seven > 0 );
+    REQUIRE( data.int_seven > -1 );
 
-    CHECK( data.int_seven >= 7 );
-    CHECK( data.int_seven >= 6 );
-    CHECK( data.int_seven <= 7 );
-    CHECK( data.int_seven <= 8 );
+    REQUIRE( data.int_seven >= 7 );
+    REQUIRE( data.int_seven >= 6 );
+    REQUIRE( data.int_seven <= 7 );
+    REQUIRE( data.int_seven <= 8 );
     
-    CHECK( data.float_nine_point_one > 9 );
-    CHECK( data.float_nine_point_one < 10 );
-    CHECK( data.float_nine_point_one < 9.2 );
+    REQUIRE( data.float_nine_point_one > 9 );
+    REQUIRE( data.float_nine_point_one < 10 );
+    REQUIRE( data.float_nine_point_one < 9.2 );
     
-    CHECK( data.str_hello <= "hello" );
-    CHECK( data.str_hello >= "hello" );
+    REQUIRE( data.str_hello <= "hello" );
+    REQUIRE( data.str_hello >= "hello" );
     
-    CHECK( data.str_hello < "hellp" );
-    CHECK( data.str_hello < "zebra" );
-    CHECK( data.str_hello > "hellm" );
-    CHECK( data.str_hello > "a" );
+    REQUIRE( data.str_hello < "hellp" );
+    REQUIRE( data.str_hello < "zebra" );
+    REQUIRE( data.str_hello > "hellm" );
+    REQUIRE( data.str_hello > "a" );
 }
 
 TEST_CASE( "failing/conditions/ordered", "Ordering comparison checks that should fail" )
@@ -159,20 +158,20 @@ TEST_CASE( "failing/conditions/ordered", "Ordering comparison checks that should
 // This means we can't isolate it when we decompose. The simple CHECK( !false ) form, therefore,
 // cannot have the operand value extracted. The test will work correctly, and the situation
 // is detected and a warning issued.
-// An alternative form of the macros (CHECK_NOT and EXPECT_NOT) can be used instead to capture
+// An alternative form of the macros (CHECK_FALSE and REQUIRE_FALSE) can be used instead to capture
 // the operand value.
 TEST_CASE( "succeeding/conditions/not", "'Not' checks that should succeed" )
 {
     bool falseValue = false;
     
-    CHECK( !false );
-    CHECK_NOT( false );
+    REQUIRE( !false );
+    REQUIRE_FALSE( false );
 
-    CHECK( !falseValue );
-    CHECK_NOT( falseValue );
+    REQUIRE( !falseValue );
+    REQUIRE_FALSE( falseValue );
 
-    CHECK( !(1 == 2) );
-    CHECK_NOT( 1 == 2 );
+    REQUIRE( !(1 == 2) );
+    REQUIRE_FALSE( 1 == 2 );
 }
 
 TEST_CASE( "failing/conditions/not", "'Not' checks that should fail" )
@@ -180,12 +179,12 @@ TEST_CASE( "failing/conditions/not", "'Not' checks that should fail" )
     bool trueValue = true;
     
     CHECK( !true );
-    CHECK_NOT( true );
+    CHECK_FALSE( true );
     
     CHECK( !trueValue );
-    CHECK_NOT( trueValue );
+    CHECK_FALSE( trueValue );
     
     CHECK( !(1 == 1) );
-    CHECK_NOT( 1 == 1 );
+    CHECK_FALSE( 1 == 1 );
 }
 
diff --git a/Test/ExceptionTests.cpp b/Test/ExceptionTests.cpp
index 35ba0b9a..327b6d0b 100644
--- a/Test/ExceptionTests.cpp
+++ b/Test/ExceptionTests.cpp
@@ -29,9 +29,9 @@ namespace
 
 TEST_CASE( "succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" )
 {
-    CHECK_THROWS_AS( thisThrows(), std::domain_error );
-    CHECK_NOTHROW( thisDoesntThrow() );
-    EXPECT_THROWS( thisThrows() );
+    REQUIRE_THROWS_AS( thisThrows(), std::domain_error );
+    REQUIRE_NOTHROW( thisDoesntThrow() );
+    REQUIRE_THROWS( thisThrows() );
 }
 
 TEST_CASE( "failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" )
diff --git a/Test/MiscTests.cpp b/Test/MiscTests.cpp
index 5ec21d31..0aee8c32 100644
--- a/Test/MiscTests.cpp
+++ b/Test/MiscTests.cpp
@@ -19,13 +19,13 @@ TEST_CASE( "succeeding/Misc/Sections", "random SECTION tests" )
     
     SECTION( "s1", "doesn't equal" )
     {
-        EXPECT( a != b );
-        EXPECT( b != a );
+        REQUIRE( a != b );
+        REQUIRE( b != a );
     }
 
     SECTION( "s2", "not equal" )
     {
-        EXPECT_NOT( a == b);
+        REQUIRE_FALSE( a == b);
     }
 }
 
diff --git a/Test/TestMain.cpp b/Test/TestMain.cpp
index b2bf7f84..dd7eb367 100644
--- a/Test/TestMain.cpp
+++ b/Test/TestMain.cpp
@@ -14,7 +14,7 @@
 #include "../catch_runner.hpp"
 
 // This code runs the meta tests and verifies that the failing ones failed and the successful ones succeeded
-/*
+///*
 int main (int argc, char * const argv[])
 {
     using namespace Catch;
@@ -61,13 +61,13 @@ int main (int argc, char * const argv[])
 
     if( result == 0 )
     {
-        const size_t expectedTestCaseCount = 99; // !TBD factor this out
+        const size_t expectedTestCaseCount = 102; // !TBD factor this out
         size_t testCaseCount = runner.getSuccessCount() + runner.getFailureCount();
         std::cout << "All " << testCaseCount << " tests completed successfully" << std::endl;
         if( testCaseCount != expectedTestCaseCount )
         {
             std::cerr   << "- but we were expecting " << expectedTestCaseCount
-                        << " test to run. Where some added or removed, or were they not compiled in?" 
+                        << " test to run. Were some added or removed, or were they not compiled in?" 
                         << std::endl;
             return 1;
         }        
@@ -75,5 +75,5 @@ int main (int argc, char * const argv[])
     }
     return result;
 }
-*/
-#include "catch_default_main.hpp"
\ No newline at end of file
+//*/
+//#include "catch_default_main.hpp"
\ No newline at end of file
diff --git a/Test/TrickyTests.cpp b/Test/TrickyTests.cpp
index e12aa9af..88ed5962 100644
--- a/Test/TrickyTests.cpp
+++ b/Test/TrickyTests.cpp
@@ -29,7 +29,7 @@ TEST_CASE( "succeeding/Tricky/std::pair", "Parsing a std::pair" )
     std::pair<int, int> aNicePair( 1, 2 );
 
     // !TBD: would be nice if this could compile without the extra parentheses
-    EXPECT( (std::pair<int, int>( 1, 2 )) == aNicePair );
+    REQUIRE( (std::pair<int, int>( 1, 2 )) == aNicePair );
     
 }
 
@@ -39,7 +39,7 @@ TEST_CASE( "succeeding/Tricky/complex lhs", "Where the LHS is not a simple value
     int b = 2;
 
     // This only captures part of the expression, but issues a warning about the rest
-    EXPECT( a == 2 || b == 2 );
+    REQUIRE( a == 2 || b == 2 );
 }
 
 struct Opaque
diff --git a/catch.hpp b/catch.hpp
index bea9a31d..77022800 100644
--- a/catch.hpp
+++ b/catch.hpp
@@ -32,14 +32,15 @@
 
 //////
 
-#define EXPECT( expr ) INTERNAL_CATCH_TEST( expr, false, true, "EXPECT" )
-#define EXPECT_NOT( expr ) INTERNAL_CATCH_TEST( expr, true, true, "EXPECT_NOT" )
+#define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, false, true, "REQUIRE" )
+#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, true, true, "REQUIRE_FALSE" )
 
-#define EXPECT_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., false, true, "EXPECT_THROWS" )
-#define EXPECT_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, false, true, "EXPECT_THROWS_AS" )
+#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., false, true, "REQUIRE_THROWS" )
+#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, false, true, "REQUIRE_THROWS_AS" )
+#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_THROWS_AS( expr, Catch::DummyExceptionType_DontUse, true, true, "REQUIRE_NOTHROW" )
 
 #define CHECK( expr ) INTERNAL_CATCH_TEST( expr, false, false, "CHECK" )
-#define CHECK_NOT( expr ) INTERNAL_CATCH_TEST( expr, true, false, "CHECK_NOT" )
+#define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, true, false, "CHECK_FALSE" )
 
 #define CHECK_THROWS( expr )  INTERNAL_CATCH_THROWS( expr, ..., false. false, "CHECK_THROWS" )
 #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, false, false, "CHECK_THROWS_AS" )