775 Commits

Author SHA1 Message Date
Martin Hořeňovský
d547cae549 Fix bad error reporting for nested exceptions in default configuration
Bad handling of `TestFailureException` when translating unexpected
exceptions inside assertion macros led to the unexpected exceptions
handling erroring out through throwing the same exception again.

This was then backstopped by the machinery for handling uncaught
exceptions from assertions, which is normally used by the
`CATCH_CONFIG_FAST_COMPILE` machinery, where we assume that it can
only be invoked because the assertion macros are not configured to
catch assertions.

Closes #1292
2025-07-27 21:41:02 +02:00
Martin Hořeňovský
fee81626d2 v3.9.0 2025-07-24 22:01:46 +02:00
Martin Hořeňovský
b6c5a635bb Link to the thread safety documentation from docs/Readme.md 2025-07-24 21:59:56 +02:00
Martin Hořeňovský
4ed3088190 Remove 'thread safe assertions' from limitations.md
We now provide thread safe assertions as a configuration option.
2025-07-24 21:57:49 +02:00
Martin Hořeňovský
bdc634e9f1 Document that the default test run order is now random 2025-07-24 21:55:30 +02:00
Martin Hořeňovský
2a8a8a7210 Add configuration option to make assertions thread-safe
All the previous refactoring to make the assertion fast paths
smaller and faster also allows us to implement the fast paths
just with thread-local and atomic variables, without full mutexes.

However, the performance overhead of thread-safe assertions is
still significant for single threaded usage:

|  slowdown |  Debug  | Release |
|-----------|--------:|--------:|
| fast path |   1.04x |   1.43x |
| slow path |   1.16x |   1.22x |

Thus, we don't make the assertions thread-safe by default, and instead
provide a build-time configuration option that the users can set to get
thread-safe assertions.

This commit is functional, but it still needs some follow-up work:
 * We do not need full seq_cst increments for the atomic counters,
   and using weaker ones can be faster.
 * We brute-force updating the reporter-friendly totals from internal
   atomic counters by doing it everywhere. We should properly trace
   where this is needed instead.
 * Message macros (`INFO`, `UNSCOPED_INFO`, `CAPTURE`, etc) are not
   made thread safe in this commit, but they can be made thread safe
   in the future, by building on top of this work.
 * Add more tests, including with thread-sanitizer, and compiled
   examples to the repository. Right now, these changes have been
   compiled with tsan manually, but these tests are not added to CI.

Closes #2948
2025-07-24 10:10:00 +02:00
Martin Hořeňovský
1aa6fa215c Backfill release version placeholders that used wrong format 2025-07-24 00:02:08 +02:00
Martin Hořeňovský
10aef62f21 Regularize scoped message lifetime to only consider the object's scope
This means that:
1) Scoped messages are always removed at the end of their scope,
   even if the scope ended due to an exception.
2) Scoped messages outlive section end, if that section's scope is
   enclosed in their own.

Previously neither of these were true, which has led to a number
of surprising behaviour, where e.g. this:
```cpp
TEST_CASE() {
    try {
        INFO( "some info" );
        throw std::runtime_error( "ex" );
    } catch (std::exception const&) {}

    REQUIRE( false );
}
```
would print "some info" as the message for the assertion, while this:
```cpp
TEST_CASE() {
    INFO("Hello");
    SECTION("dummy") {}
    REQUIRE(false);
}
```
would not print out "Hello" as the message for the assertion.

This had an underlying reason, in that it was trying to helpfully
keep the messages around in case of unexpected exceptions, so that
code like this:
```cpp
TEST_CASE() {
    auto [input, expected] = GENERATE(...);
    CAPTURE(input);
    auto result = transform(input); // throws
    REQUIRE(result == expected);
}
```
would report the value of `input` when `transform` throws. However,
it was surprising in practice and was causing various issues around
handling of messages in other cases.

Closes #1759
Closes #2019
Closes #2959
2025-07-21 21:50:47 +02:00
Martin Hořeňovský
8c3ffe05e1 Skeleton for applying deprecation warnings 2025-07-21 21:50:43 +02:00
Martin Hořeňovský
db6171a706 Mention ReporterPreferences::shouldReportAllAssertionStarts in docs 2025-07-17 22:57:18 +02:00
Chris Thrasher
ac207fc90f Use latest release in docs 2025-06-15 13:05:41 -06:00
Chris Thrasher
5abfc0aa9c Add return code constants to API 2025-04-29 09:26:28 -06:00
Chris Thrasher
4c93a595a1 Fix typos 2025-04-26 22:46:42 -06:00
Mark Jansen
5b3b228603 Update generator docs with relevant headers 2025-04-12 12:05:58 -06:00
Chris Thrasher
2b60af89e2 v3.8.1 2025-04-08 12:40:18 -06:00
Martin Hořeňovský
914aeecfe2 v3.8.0 2025-01-06 00:41:45 +01:00
Martin Hořeňovský
232e893785 Downgrade required CMake to 3.16
We still want to build VS 2017 through AppVeyor, and those images
have CMake 3.16.2 installed. We could install newer CMake as part
of the build, but since we don't use newer CMake features yet, this
is simpler.
2025-01-05 23:45:00 +01:00
Martin Hořeňovský
7d7b2f89f2 Support adding test tags as CTest labels in catch_discover_tests
We also bump the minimum CMake version to 3.20 as per #2943
2025-01-05 20:02:00 +01:00
Thomas Braun
506276c592 Fix wrong reference to REGISTER_ENUM
This was renamed to CATCH_REGISTER_ENUM in 541f1ed1 (Only provide
CATCH_REGISTER_ENUM, 2019-04-21).
2024-11-12 23:29:54 +01:00
Martin Hořeňovský
e260288807 Allow disabling use of __builtin_constant_p in internal macros
Turns out that even in GCC, the expression in `__builtin_cosntant_p`
can end up evaluated and side-effects executed. To allow users to
work around this bug, I added a configuration option to disable its
use in internal macros.

Related to #2925
2024-10-27 20:27:03 +01:00
Martin Hořeňovský
fa43b77429 v3.7.1 2024-09-17 10:45:43 +02:00
Mark Jansen
77eca4e819 Simplify instructions by not changing directories for the ctest command 2024-09-13 14:45:04 +02:00
Martin Hořeňovský
35c3403fbb Fix typo in release notes 2024-08-14 12:27:57 +02:00
Martin Hořeňovský
31588bb4f5 v3.7.0 2024-08-14 12:05:21 +02:00
Martin Hořeňovský
008676a741 Use correct matcher name in the matcher example in assertion docs 2024-08-13 19:21:07 +02:00
SirNate0
b15158c1db Fix typo in test-cases-and-sections.md 2024-08-13 12:28:03 +02:00
Martin Hořeňovský
8898cc6160 Mark non-const function for TEST_CASE_METHOD as deprecated 2024-08-05 20:13:03 +02:00
Keith Stockdale
f7cd0ba051 TEST_CASE_PERSISTENT_FIXTURE: A new fixture macro for allowing persistent fixtures throughout a TEST_CASE (#2885)
This PR introduces a new `TEST_CASE` macro called `TEST_CASE_PERSISTENT_FIXTURE`. `TEST_CASE_PERSISTENT_FIXTURE` offers the same functionality as `TEST_CASE_METHOD` except for one difference. The object on which the test method is invoked is only created once for all invocations of the test case. The object is created just after the `testCaseStarting` event is broadcast and the object is destroyed just before the `testCaseEnding` event is broadcast.

The main motivation for this new functionality is to allow `TEST_CASE`s to do expensive setup and teardown once per `TEST_CASE`, without having to resort to abusing event listeners or static function variables with manual initialization.


Implements #1602

---------

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2024-08-05 17:01:41 +02:00
Martin Hořeňovský
a40dd478f3 Update docs for REQUIRE_THROWS_MATCHES 2024-07-27 14:02:28 +02:00
Martin Hořeňovský
4e8d92bf02 v3.6.0 2024-05-05 20:58:18 +02:00
Martin Hořeňovský
b5373dadca v3.5.4 2024-04-10 12:05:46 +02:00
Martin Hořeňovský
9271083a04 Merge pull request #2850 from jeremy-rifkin/jr/mention-succeed-in-loggingmd
Mention SUCCEED along with FAIL in logging.md
2024-03-30 15:59:43 +01:00
Jeremy
07701f946a Mention SUCCEED along with FAIL in logging.md 2024-03-29 15:40:18 -05:00
Martin Hořeňovský
c0dfe13bb6 Improve example for custom options in reporter spec 2024-03-26 23:28:48 +01:00
Martin Hořeňovský
cad65c5003 Fix insufficiently escaped backslash in docs 2024-03-26 23:23:15 +01:00
Martin Hořeňovský
8ac8190e49 v3.5.3 2024-03-01 22:07:10 +01:00
Martin Hořeňovský
28c2f0b0c2 Mention x87 and ffast-math breaking FP random gen reproducibility 2024-02-19 15:02:11 +01:00
Martin Hořeňovský
2e1b02a0e2 Document issue with spaceship operator in assertion and MSVC 2024-02-19 15:02:10 +01:00
Martin Hořeňovský
82e9b9b5f2 Update CMake build instructions for current CMake version 2024-02-19 15:02:08 +01:00
Fernando J. Iglesias García
031a163a2c Improve tutorial.md with link to two-file setup instructions. 2024-02-19 15:01:14 +01:00
Letu Ren
b817497528 Fix number of current reporter
There are nine reporters in Catch2 3.5.2, Automake, compact, console,
JSON, JUnit, SonarQube, TAP, TeamCity and XML.
2024-02-16 21:29:57 +01:00
Julia Paluch
4f1b24df77 clarify duration unit in docs 2024-02-16 21:29:19 +01:00
Fædon Jóhannes
3157d6bbf1 Add Bazel instructions to integration docs (#2812)
Co-authored-by: Fædon Jóhannes Sinis <fs@treble.tech>
2024-02-16 16:58:09 +01:00
Martin Hořeňovský
79205da6a6 Fix typo in release notes for v3.5.2 2024-01-15 14:23:00 +01:00
Martin Hořeňovský
05e10dfccc v3.5.2 2024-01-15 14:13:53 +01:00
Martin Hořeňovský
f981c9cbca v3.5.1 2023-12-31 15:15:04 +01:00
Martin Hořeňovský
3acb8b30f1 More detailed examples for lifetimes in combined matcher exprs
Example taken from #2777
2023-12-13 17:24:23 +01:00
Martin Hořeňovský
3f23192e55 Fix typo in release notes 2023-12-13 17:24:18 +01:00
Martin Hořeňovský
53d0d913a4 v3.5.0 2023-12-11 00:55:40 +01:00
Simhon Chourasia
d4e9fb8aa5 Highlight that SECTIONs rerun the entire test case from beginning (#2749) 2023-12-10 22:35:54 +01:00