Commit Graph

831 Commits

Author SHA1 Message Date
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ý 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
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
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
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
Martin Hořeňovský b5373dadca
v3.5.4 2024-04-10 12:05:46 +02:00
Martin Hořeňovský cd8f97e6c7
Explicitly outline TestRegistry destructor into .cpp file
This fixes compilation issue with C++23 mode against libstdc++.

Closes #2852
2024-04-08 13:57:59 +02:00
Martin Hořeňovský 71b11c4e33
Fix assertion for const instance of std::ordering
The issue was that `capture_by_value` was meant to be specialized
by plain type, e.g. `capture_by_value<std::weak_ordering>`, but
the TMP in Decomposer did not properly throw away `const` (and
`volatile`) qualifiers, before taking the value of `capture_by_value`.
2024-04-08 11:33:43 +02:00
Martin Hořeňovský bff6e35e2b
Replace last use of std::uniform_int_distribution with our own
Our implementation should be slightly faster, and has the
advantage of being consistent between platforms. This does not
have immediate user impact, because we currently use random_device
to generate random seed for resampling, but if we decide to change
this in the future, it is one less place to fix.
2024-04-03 13:28:26 +02:00
Martin Hořeňovský d99eb8bec8
Optimize 64x64 extended multiplication implementation
Now we use intrinsics when possible, and fallback to optimized
implementation in portable C++. The difference is about 4x when
we can use intrinsics and about 2x when we cannot.

This should speed up our Lemire's algorithm implementation nicely.
2024-04-03 13:28:25 +02:00
Martin Hořeňovský f181de9df4
Use SizedUnsignedType_t to pick UnsignedType for uniform_integer_distribution
The previously used `make_unsigned` approach combined with the overload
set of `extendedMult` caused compilation issues on MacOS platform. By
forcing the selection to be one of `std::uintX_t` types we don't need
to complicate the overload set further.
2024-04-03 13:27:10 +02:00
Martin Hořeňovský 7ce3579976
Allow CATCH_CONFIG_DEFAULT_REPORTER to be arbitrary reporter spec
Previously it could be just plain reporter name, e.g. `xml`, but
it could not specify other reporter options. This change is not
particularly useful for the built-in reporters, as it mostly comes
in handy for combining specific custom reporter with custom arguments,
and the built-in reporters do not have those.
2024-03-27 10:03:51 +01:00
morinmorin eb8f2c5810 Add workaround for unguarded use of __has_extension 2024-03-12 22:57:59 +01:00
Chris Thrasher 1a44e6f661 Use built-in CMake feature for requiring a specific language standard
This feature was added in CMake 3.8. Requiring specific language
features is an outdated approach that CMake stopped supporting in
favor of simply specifyin the specific language standard you want.

https://cmake.org/cmake/help/v3.10/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
2024-03-12 22:54:09 +01:00
Cristian Morales Vega 459ac8562b Fix build with gcc 5.4
The Core Guidelines state "A base class destructor should be either
public and virtual, or protected and non-virtual" so, hopefully, no
static analyser will complain.
2024-03-12 17:15:03 +01:00
Martin Hořeňovský 8ac8190e49
v3.5.3 2024-03-01 22:07:10 +01:00
Martin Jeřábek 4d8affc989 less copies and allocations in replaceInPlace 2024-03-01 21:24:45 +01:00
Martin Jeřábek cde3509664 Fix various useful clang-tidy warnings
* bugprone-branch-clone
* bugprone-copy-constructor-init
* bugprone-empty-catch
* bugprone-sizeof-expression
* bugprone-switch-missing-default-case
* bugprone-unused-local-non-trivial-variable
* clang-analyzer-core.uninitialized.Assign
* clang-analyzer-cplusplus.Move
* clang-analyzer-optin.cplusplus.VirtualCall
* modernize-loop-convert
* modernize-raw-string-literal
* modernize-use-equals-default
* modernize-use-override
* modernize-use-using
* performance-avoid-endl
* performance-inefficient-string-concatenation
* performance-inefficient-vector-operation
* performance-noexcept-move-constructor
* performance-unnecessary-value-param (and improve generator example)
* readability-duplicate-include
* readability-inconsistent-declaration-parameter-name
* readability-non-const-parameter
* readability-redundant-casting
* readability-redundant-member-init
* readability-redundant-smartptr-get
* readability-static-accessed-through-instance
* unused variable in amalgamted tests
2024-03-01 21:24:45 +01:00
Martin Jeřábek dca87563bb Evaluate argument of TEST_CASE in static-analysis mode 2024-03-01 21:24:45 +01:00
Martin Jeřábek da303cc668 Evaluate argument of (DYNAMIC_)SECTION in static-analysis mode 2024-03-01 21:24:45 +01:00
Sven fb51116d5b
Avoid useless FDuration cast in benchmark analysis (#2823)
Co-authored-by: Sven Johannsen <s.johannsen@bretgeld-engineering.de>
2024-02-26 23:25:58 +01:00
James Smith 4f3871d53f Compiler compatibility for Visual Studio 2017 (v141) for template friend operator == (#2792).
Make the operator not-friend is a sufficient solution. Closes #2792
2024-02-23 20:45:32 +01:00
Sven Johannsen f476bcb633 fix double promotion in catch_approx.cpp 2024-02-21 15:02:13 +01:00
itacud95 024cfb3542
Link Android's `log` with PRIVATE visibility (#2815)
INTERFACE should be used on dependencies from other than our source files.
PRIVATE should be used the include happens in our source files.

In this case (src/catch2/internal/catch_debug_console.cpp:20) the include
is from our source file.

I encountered a issue with this when building Catch2 for Android in
combination with BUILD_SHARED_LIBS. Changing the visibility to PRIVATE
fixes the issue.
2024-02-20 00:32:12 +01:00
Martin Hořeňovský 4570fca24b
Remove obsolete C++14 define
There is no reason to have code conditional on C++14, because C++14
is the minimum supported language standard for v3.
2024-02-13 00:01:19 +01:00
Martin Hořeňovský 0787132fc8
Add documentation for the current state of decomposer 2024-02-12 13:43:21 +01:00
Martin Hořeňovský dc51386b9f
Support literal-zero detectors using consteval int constructors
This was originally motivated by `REQUIRE((a <=> b) == 0)` no
longer compiling using MSVC. After some investigation, I found
that they changed their implementation of the zero literal
detector from the previous pointer-constructor with deleted
other constructors, into one that uses `consteval` constructor
from int.

This breaks the previous detection logic, because now
`is_foo_comparable<std::strong_ordering, int>` is true, but
actually trying to compare them is a compile-time error...
The solution was to make the decomposition `constexpr` and rely
on a late C++20 DR that makes it so that `consteval` propagates
up through the callstack of `constexpr` functions, until it either
runs out of `constexpr` functions, or succeeds.

However, the default handling of types in decomposition is to
take a reference to them. This reference never becomes dangling,
but because the constexpr evaluation engine cannot prove this,
decomposition paths taking references to objects cannot be
actually evaluated at compilation time. Thankfully we already
did have a value-oriented decomposition path for arithmetic types
(as these are common linkage-less types), so we could just
explicitly spell out the `std::foo_ordering` types as also being
supposed to be decomposed by-value.

Two more fun facts about these changes
 1) The original motivation of the MSVC change was to avoid
    trigering a `Wzero-as-null-pointer-constant` warning. I still
    do not believe this was a good decision.
 2) Current latest version of MSVC does not actually implement the
    aforementioned C++20 DR, so even with this commit, MSVC cannot
    compile `REQUIRE((a <=> b) == 0)`.
2024-02-12 00:52:53 +01:00
Martin Hořeňovský 2a5de4e447
Fix OOB access when computing -# tag for file without extension
It is unlikely that this would ever come in practice, but there
is no reason to fix it.

Related to #2798
2024-02-10 23:27:19 +01:00
Chris Thrasher 1078e7e95b Fix clang-tidy `bugprone-chained-comparison` warnings
This triggers when running clang-tidy's bugprone-* family of checks
in code which uses Catch2 even if Catch2 headers are marked as
SYSTEM headers due to how code expanded from macros is treated as
first party even if the macro comes from a 3rd party library. The
fix is luckily pretty straightforward.

This check is added in clang-tidy-18 due for release later this year.
2024-01-24 22:41:00 -07:00
Martin Hořeňovský 05e10dfccc
v3.5.2 2024-01-15 14:13:53 +01:00
Tim Blechmann 597ce12b65 reporters: silence -Wsubobject-linkage
gcc emits `Wsubobject-linkage`, because the the publicly visible
`TablePrinter` contains `ColumnInfo`, which is part of an anonymous
namespace
2024-01-15 09:57:30 +01:00
Chris Thrasher 05786fa7ec
Remove redundant destructors
Classes will automatically inherit the virtual-ness of their base
class destructors. If the base class already has a virtual
destructor and the derived class needs default destructor semantics
then the derived class can omit defining the destructor in favor of
the compiler automatically defining it.

This has an additional benefit of reenabling move semantics. The
presence of a user-specified destructor automatically disables move
operations.
2024-01-14 23:33:51 +01:00
Martin Hořeňovský d79bfa05c7
More readable config default 2024-01-14 21:25:04 +01:00
Martin Hořeňovský a0ef2115f8
Cleanup types in resample 2024-01-14 20:59:05 +01:00
Martin Hořeňovský 863c662c0e
Fix adding Opts with | to lvalue Parser
This is the recommended way of adding new Opts in our documentation
for using custom main, but we did not compile the code to see if it
works. We now compile the example as part of the BUILD_EXAMPLES
option.

Fixes #2787
2024-01-02 23:27:13 +01:00
Martin Hořeňovský f981c9cbca
v3.5.1 2023-12-31 15:15:04 +01:00
影月 零 c8262e1f40
Handle linking to liblog when [cross] building for Android using meson. (#2784)
* Alter meson for Android cross builds.

* Handle liblog linking on Termux as well as the Android NDK.
2023-12-28 23:40:42 +01:00
Martin Hořeňovský 08bdd43fcd
Merge pull request #2785 from jpalus/optional-reproducible-build
Make compiler flags for reproducible builds optional
2023-12-28 21:20:41 +01:00
Jan Palus 1512dac7e4
Make compiler flags for reproducible builds optional
no change in default behavior: -ffile-prefix-map is still added if
supported by compiler but add option for disabling it as it breaks
generic tools for extracting debuginfo/debugsource from build artifacts
like: https://sourceware.org/git/?p=debugedit.git;a=blob;f=scripts/find-debuginfo.in
2023-12-28 00:41:54 +01:00
Martin Hořeňovský b52d97855d
Move-enable various parts of TextFlow
This removes about 200 pointless copies from printing the help
message (the original motivation for the change), and also nicely
improves performance of the various reporters that depend on
TextFlow.
2023-12-27 21:43:49 +01:00
Martin Hořeňovský eaafd07674
Avoid copying TokenStreams while parsing
The code is now even worse mess than before, due to the ad-hoc
implementation of Result-ish type based on virtual functions in
Clara, but it has dropped the allocations for empty binary down
to 151.
2023-12-27 21:14:12 +01:00
Martin Hořeňovský 5d637d4c6b
Args and TokenStream use StringRefs instead of std::strings
Because TokenStream is copied around a lot, moving it to use
`StringRef` removes _a lot_ of allocations per `Opt` in the parser.
Args are not copied around much, but changing them as well makes it
obvious that they do not participate in the ownership.

The changes add up to removing ~180 allocations for "empty"
invocation of the test binary.
(`./tests/ExtraTests/NoTests --allow-running-no-tests -o /dev/null`
is down to 317 allocs)
2023-12-27 16:24:33 +01:00
Martin Hořeňovský cd3c7ebe87
Use StringRef for Opt's optNames
Removes another ~70 allocations.
2023-12-26 16:03:22 +01:00
Martin Hořeňovský 5d5f42f99b
Enable moving Opts into Parser
This also required keeping the reference type in the fluent interface
for Opts.

Removes another ~40 allocations.
2023-12-26 15:41:07 +01:00
Martin Hořeňovský c57e349d1d
Avoid copying Clara::Parser for every inserted Opt
This prevents the full construction from being O(N^2) in number
of `Opt`s, and also reduces the number of allocations for running
no tests significantly:

`tests/SelfTest`: 7705 -> 6095
`tests/ExtraTests/NoTests` 2215 -> 605
2023-12-26 15:11:48 +01:00
Martin Hořeňovský 822c44a203
Cleanup help string construction in Clara
* Clara::Opt::getHelpColumns returns single item

  It could never return multiple items, but for some reason it
  was wrapping that single item in a vector.

* Use ReusableStringStream in Clara
* Reserve HelpColumns ahead of time
* Use StringRef for descriptions in HelpColumn type

The combination of these changes ends up removing about 7% (~200)
of allocations when Catch2 has to prepare output for `-h`.
2023-12-26 14:57:29 +01:00