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

Add extra test binary & test for CATCH_CONFIG_FAST_COMPILE

Closes #3100
Commit
9f7c9f6872308d4e7c32fff2f1ac6640aa866b6a
Author
Martin Hořeňovský ·
Parents
919385f7046b

Files · Download .tar.gz

Changes

 tests/ExtraTests/CMakeLists.txt            | 14 +++++++
 tests/ExtraTests/ToDo.txt                  |  1 -
 tests/ExtraTests/X07-FastCompileMacros.cpp | 63 ++++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt
index 29d72b76..5ee07cca 100644
--- a/tests/ExtraTests/CMakeLists.txt
+++ b/tests/ExtraTests/CMakeLists.txt
@@ -526,6 +526,19 @@ set_tests_properties(TestSpecs::SkippingAllTestsFails
     WILL_FAIL ON
 )
 
+add_executable(FastCompileMacros ${TESTS_DIR}/X07-FastCompileMacros.cpp)
+target_link_libraries(FastCompileMacros PRIVATE Catch2_buildall_interface)
+target_compile_definitions(FastCompileMacros PRIVATE CATCH_CONFIG_FAST_COMPILE)
+
+add_test(
+  NAME CompileConfiguration::FastCompile
+  COMMAND $<TARGET_FILE:FastCompileMacros>
+)
+set_tests_properties(CompileConfiguration::FastCompile
+  PROPERTIES
+    PASS_REGULAR_EXPRESSION "test cases:  6 \\| 1 passed \\| 1 failed \\| 4 failed as expected\nassertions: 13 \\| 6 passed \\| 2 failed \\| 5 failed as expected"
+)
+
 # This sets up a one-off executable that compiles against the amalgamated
 # files, and then runs it for a super simple check that the amalgamated
 # files are usable.
@@ -595,6 +608,7 @@ set(EXTRA_TEST_BINARIES
   NoTests
   ListenersGetEventsBeforeReporters
   MixingClearedAndUnclearedMessages
+  FastCompileMacros
   InfiniteGenerators
   ThreadSafetyTests
 #  DebugBreakMacros
diff --git a/tests/ExtraTests/ToDo.txt b/tests/ExtraTests/ToDo.txt
index a2ed36b2..139eacfd 100644
--- a/tests/ExtraTests/ToDo.txt
+++ b/tests/ExtraTests/ToDo.txt
@@ -3,7 +3,6 @@ yet:
 
     CATCH_CONFIG_COUNTER                    // Use __COUNTER__ to generate unique names for test cases
     CATCH_CONFIG_WINDOWS_SEH                // Enable SEH handling on Windows
-    CATCH_CONFIG_FAST_COMPILE               // Sacrifices some (rather minor) features for compilation speed
     CATCH_CONFIG_POSIX_SIGNALS              // Enable handling POSIX signals
     CATCH_CONFIG_WINDOWS_CRTDBG             // Enable leak checking using Windows's CRT Debug Heap
     CATCH_CONFIG_DEFAULT_REPORTER
diff --git a/tests/ExtraTests/X07-FastCompileMacros.cpp b/tests/ExtraTests/X07-FastCompileMacros.cpp
new file mode 100644
index 00000000..66d11664
--- /dev/null
+++ b/tests/ExtraTests/X07-FastCompileMacros.cpp
@@ -0,0 +1,63 @@
+
+//              Copyright Catch2 Authors
+// Distributed under the Boost Software License, Version 1.0.
+//   (See accompanying file LICENSE.txt or copy at
+//        https://www.boost.org/LICENSE_1_0.txt)
+
+// SPDX-License-Identifier: BSL-1.0
+
+/**\file
+ * Test that various basic macros work with CATCH_CONFIG_FAST_COMPILE.
+ *
+ * Note that the current checking is rather loose. We check that the
+ * macros compile, and that the test cases (don't) fail as they are
+ * supposed to.
+ */
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <stdexcept>
+
+namespace {
+
+    [[noreturn]]
+    static void throws() {
+        throw std::runtime_error{ "sup" };
+    }
+    static void doesnt_throw() {}
+    [[noreturn]]
+    static int throws_i() {
+        throw std::runtime_error{ "sup" };
+    }
+
+} // namespace
+
+TEST_CASE( "Passing macros work" ) {
+    REQUIRE( 1 != 2 );
+    CHECK( 2 == 2 );
+    REQUIRE_THROWS( throws() );
+    REQUIRE_NOTHROW( doesnt_throw() );
+}
+
+TEST_CASE( "Failing macros work", "[!shouldfail]" ) {
+    CHECK( 1 != 2 );
+    CHECK( 2 == 2 );
+    CHECK( 3 == 2 );
+}
+
+TEST_CASE( "Failing NOTHROW works", "[!shouldfail]" ) {
+    REQUIRE_NOTHROW( throws() );
+}
+
+TEST_CASE( "Failing THROW works", "[!shouldfail]" ) {
+    REQUIRE_THROWS( doesnt_throw() );
+}
+
+TEST_CASE( "Unexpected exception in REQUIRE gets inverted properly",
+           "[!shouldfail]" ) {
+    REQUIRE( throws_i() == 1 );
+}
+
+TEST_CASE( "Unexpected exception in REQUIRE fails properly" ) {
+    REQUIRE( throws_i() == 2 );
+}