Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorMartin Hořeňovský2026-07-06 11:03:38 +0200
committerMartin Hořeňovský2026-07-06 11:03:47 +0200
commit9f7c9f6872308d4e7c32fff2f1ac6640aa866b6a (patch)
treedf8d984d0bf74fedf77d9ad4efea9574fb153bac /tests
parent919385f7046b61ae0960d02977d95674cbe20d85 (diff)
downloadcatch3-9f7c9f6872308d4e7c32fff2f1ac6640aa866b6a.tar.gz
Add extra test binary & test for CATCH_CONFIG_FAST_COMPILE
Closes #3100
Diffstat (limited to 'tests')
-rw-r--r--tests/ExtraTests/CMakeLists.txt14
-rw-r--r--tests/ExtraTests/ToDo.txt1
-rw-r--r--tests/ExtraTests/X07-FastCompileMacros.cpp63
3 files changed, 77 insertions, 1 deletions
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 );
+}