Commit Graph

4551 Commits

Author SHA1 Message Date
Holger Kaelberer
0321d2fce3 Catch.cmake: Remove redundant CTEST_FILE param 2024-11-22 11:05:50 +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ý
f5cee49c71
Add test for iterators with const T as the value_type 2024-11-11 06:49:11 +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ý
9c5a4cf44e
Enable CMake project folders for better target organization
Closes #2917
2024-10-27 23:07:55 +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ý
7c2e1fb1b2
Update Intel Mac builds to macos-13 images for MacOS GitHub Actions
macos-12 images will be removed on 3.12.2024, and macos-14 no
longer support Intel-based MacOS in free (OSS) tier.
2024-10-26 16:55:15 +02: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ý
79f2d66ea3
Use SKIP_RETURN_CODE test property in catch_discover_tests
I also added `SKIP_IS_FAILURE` option to the `catch_discover_tests`
function, to allow users to get back the old behaviour.

Closes #2873
2024-09-17 09:35: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
Mark Jansen
77eca4e819 Simplify instructions by not changing directories for the ctest command 2024-09-13 14:45:04 +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ý
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ý
f24569a1b4
Large output redirect refactor
This rework changes two important things

1) the output redirect is deactivated while control is given to the reporters.
   This means that combining reporters that write to stdout with capturing
   reporters, e.g. `./tests -s -r console -r junit::out=junit.xml`, no
   longer leads to the capturing reporter seeing all the output from
   the other reporter captured.

Trying this with the `SelfTest` binary would previously lead to JUnit
spending **hours** trying to escape all of ConsoleReporter's output and
write it to the output file. I actually ended up killing the process
after 3 hours, during which the JUnit reporter wrote something like 50 MBs
of output to a file.

2) The redirect object's lifetime is tied to the `RunContext`, instead
  of being constructed for every partial test case run separately.

This has no effect on the basic StreamRedirect, but improves the FileRedirect
significantly. Previously, running many tests in single process with this
redirect (e.g. running `SelfTest -r junit`) would cause later tests to
always fail before starting, due to exceeding the limit of temporary files.

For the current `SelfTest` binary, the old implementation would lead to
**295** test failures from not being able to initiate the redirect. The
new implementation completely eliminates them.

----

There is one downside to the new implementation of FileRedirect, specific
to Linux. Running the `SelfTest` binary on Linux causes 3-4 tests to have
no captured stdout/stderr, even though the tests were supposed to be
writing there (there was no output to the actual stdout/stderr either,
the output was just completely lost).

Since this never happen for smaller test case sets, nor does it reproduce
on other platforms, this implementation is still strictly better than
the old one, and thus it can get reasonably merged.
2024-08-13 23:32:24 +02:00
Martin Hořeňovský
a579b5f640
Properly handle prepending user-specified paths to DYLD_FRAMEWORK_PATH 2024-08-13 23:05:21 +02:00
Chien-Yu Lin
1538be67cb Respect path order of DL_PATHS in catch_discover_tests function 2024-08-13 22:23:16 +02:00
Omar Boukli-Hacene
9721048a32 Move header from internal
Move `catch_case_sensitive.hpp` from directory
`src/catch2/internal/internal` to be directly under `src/catch2/`.

Header `catch_case_sensitive.hpp` defines `enum CaseSensitive` which is
part of the public API, since it is exposed by the string matcher
contracts.

Fixes issue caught by Clang Tidy misc-include-cleaner check.
2024-08-13 19:51:00 +02:00
Martin Hořeňovský
aad0a3a8d6
Prune away g++-11 build from Mac 2024-08-13 19:36:19 +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
Martin Hořeňovský
fe483c056d
Improve performance of JUnit reporter when handling passing assertions
This is done by no longer requiring all assertions to be seen
by the JUnit reporter. Since the JUnit reporter never outputs
all assertions, even with `-s`, the only difference from storing
passing assertions in the `CumulativeReporterBase` was some
bookkeeping in deciding which sections are relevant to the output.

Given `TEST_CASE` that just runs many passing assertions, e.g.

```
TEST_CASE( "PERFORMANCE_TEST_CASE", "[.]" ) {
    for (size_t i = 0; i < 1000'000'000; ++i) {
        REQUIRE( i == i );
    }
}
```

the new JUnit reporter will finish in 5:47, using up ~7.7 MB of RAM.
The old JUnit reporter would finish in 0:30, due to bad_alloc
after using up 14.5 GB of RAM (the system has 16 GB total).

If the total number of assertions is lowered to 10M, the old
implementation uses up ~7.1 GB of RAM and finishes in 12 minutes.
The new implementation still needs only ~7.7 MB of RAM, and finishes
in 4 minutes.

There is a slight downside in that the output is slightly different;
the new implementation will include the `TEST_CASE` level section
in output, even if it does not have its own assertion. In other words,
given a `TEST_CASE` like this

```
TEST_CASE( "JsonWriter", "[JSON][JsonWriter]" ) {
    std::stringstream stream;
    SECTION( "Newly constructed JsonWriter does nothing" ) {
        Catch::JsonValueWriter writer{ stream };
        REQUIRE( stream.str() == "" );
    }

    SECTION( "Calling writeObject will create an empty pair of braces" ) {
        { auto writer = Catch::JsonValueWriter{ stream }.writeObject(); }
        REQUIRE( stream.str() == "{\n}" );
    }
}
```

the new implementation will output 3 `testcase` tags, 2 for the explicit
 `SECTION`s with tests, and 1 for the top level section.

However, this can be worked-around if required, and the performance
improvement is such that it is worth changing the current output,
even if it needs to be fixed in the future.

Closes #2897
2024-08-13 19:13:03 +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ý
33e24b14fc
Add missing break to a switch to silence fall-through warning
Closes #2891
2024-07-31 17:38:02 +02:00
Martin Hořeňovský
a40dd478f3
Update docs for REQUIRE_THROWS_MATCHES 2024-07-27 14:02:28 +02:00
Andy Phillips
85b7f3d6ab
Add optional argument to catch_discover_tests to set DYLD_FRAMEWORK_PATH (#2880)
* Added optional argument to catch_discover_tests to set the DYLD_FRAMEWORK_PATH environment variable on Apple platforms.
2024-07-22 19:25:24 +02:00
Martin Hořeňovský
7af96bbb22
Slight improvement to computing clock resolution in benchmarking 2024-07-22 10:54:16 +02:00
Martin Hořeňovský
22e6490325
Remove copyability from BenchmarkFunction
Technically we should be able to remove moveability as well, but
then we would need a larger surgery. This already improves the
compile times and binary sizes by a surprising amount.
2024-07-22 10:54:14 +02:00
Martin Hořeňovský
595bf9864e
Update to macos-12 GHA image
Since the last time, macos-12 has fixed the toolchain's linker
crash bug, so we can update here. macos-13 has a new and exciting
bug when unwinding exceptions in binaries compiled with GCC, so
we cannot update all the way at this time.
2024-07-22 10:47:25 +02:00
Vertexwahn
381f29e974 Bazel support: Update skylib version to 1.6.1 2024-07-22 10:21:44 +02:00
KStocky
37c8b2d2b3 Adding unapproved.txt files to gitignore 2024-07-19 22:21:09 +02:00
KStocky
292d64da32 Ignore all files with the name CMakeUserPresets.json 2024-07-19 22:08:57 +02:00
Martin Hořeňovský
4e8d92bf02
v3.6.0 2024-05-05 20:58:18 +02:00
Jeremy Rifkin
8ce2426e53
Handle ANSI escape sequences when performing column wrapping (#2849)
This PR adds functionality to skip around ANSI escape sequences in catch_textflow so they do not contribute to line length and line wrapping code does not split escape sequences in the middle. I've implemented this by creating a AnsiSkippingString abstraction that has a bidirectional iterator that can skip around escape sequences while iterating. Additionally I refactored Column::const_iterator to be iterator-based rather than index-based so this abstraction is a simple drop-in for std::string.

Currently only color sequences are handled, other escape sequences are left unaffected.

Motivation: Text with ANSI color sequences gets messed up when being output by Catch2 #2833.
2024-05-04 23:43:52 +02:00