diff options
| author | Martin Hořeňovský | 2026-07-06 11:03:38 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-07-06 11:03:47 +0200 |
| commit | 9f7c9f6872308d4e7c32fff2f1ac6640aa866b6a (patch) | |
| tree | df8d984d0bf74fedf77d9ad4efea9574fb153bac /tests/ExtraTests/X07-FastCompileMacros.cpp | |
| parent | 919385f7046b61ae0960d02977d95674cbe20d85 (diff) | |
| download | catch3-9f7c9f6872308d4e7c32fff2f1ac6640aa866b6a.tar.gz | |
Add extra test binary & test for CATCH_CONFIG_FAST_COMPILE
Closes #3100
Diffstat (limited to 'tests/ExtraTests/X07-FastCompileMacros.cpp')
| -rw-r--r-- | tests/ExtraTests/X07-FastCompileMacros.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
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 ); +} |