Commit Graph

4537 Commits

Author SHA1 Message Date
Martin Hořeňovský
432695291a
Flush AND sleep 2024-09-15 20:46:24 +02:00
Martin Hořeňovský
e63f3cc817
Refactor pipe-based redirect to not always create new thread and pipe 2024-09-15 20:22:40 +02:00
Martin Hořeňovský
986ee2c793 WIP: rebase pipe redirect onto current redirect interface 2024-09-13 19:17:39 +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
Martin Hořeňovský
fa5a53df17
Explicitly silence Wnon-virtual-dtor in Decomposer and MatchExpr
Closes #2854
2024-04-30 23:51:36 +02:00
Martin Hořeňovský
a654e4b038
Don't include numerically unstable tests in approvals 2024-04-30 19:21:27 +02:00
Martin Hořeňovský
ef713582d2
Default StringMaker<FloatingPointType>::precision to max_digits10
`max_digits10` is the number of decimal digits that the type _can_
represent, in other words, the number of decimal digits needed to
disambiguate any two floating point numbers when serialized to
a string.
2024-04-30 17:18:48 +02:00
Martin Hořeňovský
efb39689d9 Add test for handleFatalErrorCondition within JUnit reporter 2024-04-21 21:52:33 +02:00
Altan Birler
42fe78d0ba Handle active Sections for fatal errors
Closes #1210

When a signal is caught, the destructors of Sections will not be called.
Thus, we must call `sectionEndedEarly` manually for those Sections.

Example test case:
```
TEST_CASE("broken") {
   SECTION("section") {
      /// Use illegal cpu instruction
      __asm__ __volatile__("ud2" : : : "memory");
   }
}
```
2024-04-21 21:52:33 +02:00
c8ef
2bce3e276b
add bazel build rule for SelfTest (#2857)
This PR primarily accomplishes two tasks:

1) It adds MODULE.bazel.lock to the .gitignore file.
2) It includes a Bazel build rule for SelfTest, which can be utilized with the command bazel test //tests:catch2_self_test.
2024-04-21 21:05:55 +02:00
Vincent Saulue-Laborde
df04df94db conanfile: fix cmake_target_name of Catch2::Catch2.
The "Catch2 without default main" target is currently unspecified in
Conan, and defaults to catch2::catch2base. This commit switches it back
to Catch2::Catch2, as specified in the docs.
2024-04-20 14:31:04 +02:00
AgostonSzepessy
f2320724a7
Fix build on ARM64EC (#2858)
Remove `#pragma intrinsic(_umul128)` because it doesn't work on
ARM64EC and x64 works without it.

Co-authored-by: Agoston Szepessy <agos@microsoft.com>
2024-04-19 10:36:37 +02:00
Vincent Saulue-Laborde
8e80b8f22c conanfile: set compatibility_cppstr = False.
The Catch libraries have different API/ABI depending on the c++
standard they are compiled with. For example, the following function
isn't in the binary when compiled with C++14, only with C++17 or later:

StringMaker<std::string_view>::convert(std::string_view str);

By default, Conan is allowed to serve Catch libraries compiled in C++14
into a project using C++17/20, potentially causing linker errors
because of missing symbols. This PR overrides this default behaviour:
the C++ standard of the Catch library will exactly match the one of
the requiring project (building Catch from source if necessary).
2024-04-18 21:47:12 +02:00
Ian Bell
53ddf37af4
Use Catch::StringMaker for output in WithinRelMatcher (#2846)
The WithinRelMatcher does not listen to the precision specification; it just naively pipes to stringstream. If you specify the precision, that has no impact on the outputted values when the match fails.

This fix makes the WithinRelMatcher listen to the precision (https://github.com/catchorg/Catch2/blob/devel/docs/tostring.md#floating-point-precision) specified by: Catch::StringMaker<float>::precision
2024-04-15 13:35:39 +02:00
Martin Hořeňovský
029fe3b460
Actually check for x64 target with MSVC 2024-04-13 22:51:17 +02:00
Martin Hořeňovský
65794fd2b8
Fix ARM64 windows builds
Apparently I looked at the docs for umulh when checking availability,
and umul128 is x64 only.
2024-04-12 16:40:06 +02:00
Chris Thrasher
838f8d71cb
Remove unnecessary CMake variables (#2853)
* Remove unnecessary variable

* Remove unused variable
2024-04-11 15:39:08 +02:00
Martin Hořeňovský
b5373dadca
v3.5.4 2024-04-10 12:05:46 +02:00