Commit Graph

888 Commits

Author SHA1 Message Date
Martin Hořeňovský 9be81c0e05 Move resetAssertionInfo into RunContext::reportExpr
Because `RunContext::populateReaction` no longer implicitly depends
on the value of `RunContext::m_lastAssertionInfo`, we don't have to
delay the reset until `RunContext::reportExpr` is finished.
2025-07-16 21:58:42 +02:00
Martin Hořeňovský efcb76874e Store only lineinfo if m_lastAssertionInfo is going to be reset
`RunContext::resetAssertionInfo` overwrites everything in
`m_lastAssertionInfo` except for the lineInfo, so if the reset
is called at the end of a copying function, we can save work
by copying only the lineInfo.
2025-07-16 21:52:05 +02:00
Martin Hořeňovský 895b8af6bd Avoid needless copy in handling fatal errors 2025-07-16 21:50:20 +02:00
Martin Hořeňovský 066f00acf5 Pass result disposition into RunContext::populateReaction directly
This avoids implicit dataflow through RunContext::m_lastAssertionInfo,
which will be useful in later refactoring.
2025-07-16 21:43:00 +02:00
Martin Hořeňovský 1b72e45354 Cache config::abortAfter and config::shouldDebugBreak in RunContext 2025-07-16 21:29:53 +02:00
Martin Hořeňovský f7968e9697 Constify various autoregistry globals to avoid clang-tidy complaints
Closes #2582
2025-07-15 15:23:32 +02:00
Martin Hořeňovský a483b6d7d3 Default to randomized test case order 2025-07-15 12:10:40 +02:00
Martin Hořeňovský b9c018b38a Use template variables for our trait-likes in Clara 2025-07-15 11:49:39 +02:00
Martin Hořeňovský 050e14dce0 Disable Wmissing-noreturn for test files
Adding unreachable to `FAIL` and `SKIP` made Clang become very good
at figuring out that tests of `FAIL` and `SKIP` will never return
and thus could be marked as [[noreturn]].

To avoid introducing lot of warning suppression noise into the
test files, we just disable it instead.
2025-07-14 12:15:25 +02:00
Martin Hořeňovský 6097bd6ee9 Mark code past FAIL and SKIP as unreachable
This helps the compiler see that the execution does not continue,
which in turn means that it is not an error if the user does not
return value from the function after FAIL/SKIP.

Closes #2941
2025-07-14 10:39:48 +02:00
Martin Hořeňovský b62413aee3 Add stream flushes after reporters print out the test run metadata.
This ensures that the test run metadata are printed even if the
process dies right after.

Closes #2964
2025-07-10 23:51:31 +02:00
Martin Hořeňovský 39c32b9662 Avoid needless string temporary in template product test registration 2025-07-09 12:29:36 +02:00
Clement Courbet 2de12cb05f Allow using only types in TEMPLATE_TEST_CASE_SIG. (#2995)
Right now `TEMPLATE_TEST_CASE_SIG` fails to compile when the signature contains only types:

```
TEMPLATE_TEST_CASE_SIG(
  "TemplateTestSig: compiles with two type parameters",
  "[template][onlytypes]",
  ((typename U, typename V), U, V), (int,int)) {}
```

The trick is to resolve the ambiguity between the two overloads of
`get_wrapper` (`TypeList` and `Nttp`) by making one match more strongly.
We also need to allow `reg_test` to register more than one type.

Add unit tests.

Fixes #2680

---------

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2025-07-08 14:26:25 +02:00
Omar Boukli-Hacene 8dc9f1a124 Move header from internal
Move `catch_test_run_info.hpp` from directory
`src/catch2/internal/` to be directly under `src/catch2/`.

Header `catch_test_run_info.hpp` defines `Catch::TestRunInfo` which is part of the public API, since it is required when overriding `Catch::EventListenerBase`.

Fixes issue caught by Clang Tidy misc-include-cleaner check.
2025-07-07 17:27:48 +02:00
Tyson Jones bd2d918f32 patched >2-digit tag-count padding in base reporter
Passing the CLI argument '--list-tags' outputs a list like:

```
All available tags:
  11  [mytag]
   4  [myothertag]
2 tags
```

However, the width of the tag-count column was previously hardcoded to 2, such that the formatting broke (with the tag names awkwardly misaligned/displaced) for 3+ digit tag counts. This occurred whenever a tag contains one hundred or more tests, and would result in formatting like:

```
All available tags:
  11  [mytag]
  100  [myjumbotag]
   4  [myothertag]
3 tags
```

This patch pre-computes the maximum number of digits among the tag counts, expanding the padding when there are more than 100 tests in a tag (and handling when tags are empty). It now outputs e.g.

```
All available tags:
   11  [mytag]
  100  [myjumbotag]
    4  [myothertag]
3 tags
```
2025-07-02 14:13:07 +02:00
Jean-Michaël Celerier d134b0cae3 clang: do not issue bogus warnings about integer manipulation in hash functions with fsanitize=undefined/integer (#2965)
With -fsanitize=integer every over/under-flowing integer manipulation triggers a warning.
This is extremely useful as it allows to find some non-obvious bugs such as

    for(size_t i = 0; i < N - 1; i++) { ... }

But it comes with a lot of false positives, for instance with every hash function
doing shifting on unsigned integer. Random number generators are also often detected
with this sanitizer.

This marks a few of these functions as safe in this case.

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2025-07-02 13:30:36 +02:00
Eisuke Kawashima 416b075211 fix: make deleted member function public 2025-06-15 13:26:38 -06:00
Eisuke Kawashima 1de7d0ed7b Remove redundant override specifier from functions that are declared final 2025-06-14 18:42:43 -06:00
Chris Thrasher 5abfc0aa9c Add return code constants to API 2025-04-29 09:26:28 -06:00
Martin Hořeňovský 1e7b879fae Small include cleanup 2025-04-29 13:15:34 +02:00
ZXShady 4ff57aba42 Use variable templates 2025-04-27 21:14:04 -06:00
Chris Thrasher 5a6d70eebb Remove unused headers 2025-04-27 11:08:41 -06:00
Chris Thrasher 4c93a595a1 Fix typos 2025-04-26 22:46:42 -06:00
Chris Thrasher 8cfca70ae8 Fix formatting of CMake files
2 spaces seems to be the more common indentation level so that's what
I unified around.
2025-04-26 10:38:36 -06:00
Chris Thrasher 2b60af89e2 v3.8.1 2025-04-08 12:40:18 -06:00
abhishekbelgaonkar23 f51dc98dfc Fix: Clang 19 -Wc++20-extensions warning (#2910) 2025-04-07 15:45:34 -06:00
Martin Hořeňovský 914aeecfe2 v3.8.0 2025-01-06 00:41:45 +01:00
Michal Bukovský 6e9c34aa20 add meson option to not install library 2025-01-05 20:10:45 +01:00
Martin Hořeňovský b0d0aa43e6 Fix crash when stringifying pre 1970 dates on Windows
`gmtime*` on Windows fails on dates pre 1970, and because we didn't
check the return code, we would then pass invalid `tm` struct to
`strftime` causing it to assert.

Closes #2944
2025-01-05 16:04:38 +01:00
Michal Bukovský 7bbd4b9075 Fix using from_range with std::vector<>::const_iterator 2024-11-09 18:46:07 +01:00
Martin Hořeňovský 119a7bbe53 Cleanup clang-tidy warning about enum sizes 2024-10-29 21:06: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
Pino Toscano a6ee7e20cd Use isatty() when using GNU libc
While isatty() is a POSIX interface and theoretically could be used
more broadly than on Linux and macOS, use a conservative approach and
use it on any platform that uses GNU libc.
2024-10-19 20:36:19 +02:00
Sven Fischer 0b2af56271 Explicitly cast values of different types
In case the warning -Werror=conversion is active with GCC, the warnings
about "conversion from A to B may change value" lead to a compilation
error. This explicitly convert the values to address these warnings.
2024-10-14 21:37:35 +02:00
Stefan Haller 69d62abc9a Provide overloads for {Unordered}RangeEquals taking a std::initializer_list
This allows writing something like

  const auto v = calculateSomeVectorOfInts();
  CHECK_THAT(v, RangeEquals({1, 2, 3}));

Fixes #2915.
2024-10-14 21:02:03 +02:00
Stefan Haller 1e0ccb1b21 Use default parameter for comparison instead of overloads in {Unordered}RangeEquals
Saves some code duplication.
2024-10-14 21:02:03 +02:00
Stefan Haller 5ad66ada7b Fix typos in comments 2024-10-14 21:02:03 +02:00
Martin Hořeňovský fa43b77429 v3.7.1 2024-09-17 10:45:43 +02:00
Martin Hořeňovský e200443b84 Fix compilation error from missing include in xmlwriter.hpp
Fixes #2907
2024-09-15 22:17:39 +02:00
Martin Hořeňovský ce22c0fe8a Standardize exit codes for various failures
The main reason for this is to be able to distinguish between
different errors (or "errors") based on the return code. Before
this change, it was impossible to use the exit code to figure out
whether a test binary failed because all tests were skipped or
because exactly 4 assertions have failed.

This meant that using `catch_discover_tests` and telling it to
check for exit code == 4 to determine skipped tests could lead to
false negatives.
2024-09-13 21:33:45 +02:00
Martin Hořeňovský 18df97df00 Sprinkle some constexpr around to make Jason happy
Most of these will not matter in practice due to C++14 imposing
significant limitations on what else we can make constexpr, and we cannot
have references outliving the constexpr context either way.
2024-09-13 16:40:11 +02:00
Martin Hořeňovský e97ebe62e7 Remove superfluous include 2024-09-13 16:39:55 +02:00
Martin Hořeňovský b2b7cbdc31 Remove pointless internal macro 2024-09-13 16:39:53 +02:00
Martin Hořeňovský 412cad546a Avoid needless copy of string in runContext::handleMessage 2024-09-13 16:39:51 +02:00
Martin Hořeňovský bd70515c08 Add the catch_config_prefix_messages.hpp to builds
Closes #2903
2024-09-13 16:39:49 +02:00
Martin Hořeňovský 7a89b75737 Use steady_clock in the timer 2024-09-13 16:39:47 +02:00
Mark Jansen 02d3304782 Fix bug in TokenStream parser
When presented with just '-' it would access the string at position [1]
2024-09-13 15:32:49 +02:00
Kasper Laudrup bc63412e2a Suppress GCC useless-cast warning from CHECK_THROWS_MATCHES
Suppress warning from GCC about useless cast in the
CHECK_THROWS_MATCHES macro the same way it is already being done for
the similar CHECK macros.
2024-09-06 16:04:35 +02:00
Martin Hořeňovský fa306fc85e Improve performance of SonarQube reporter handling passing assertions
This mirrors the changes done to the JUnit reporter in commit
fe483c056d
2024-08-14 12:33:55 +02:00
Martin Hořeňovský 31588bb4f5 v3.7.0 2024-08-14 12:05:21 +02:00