Commit Graph

859 Commits

Author SHA1 Message Date
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
Martin Hořeňovský
2295d2c8cc
Store Opt/Arg hint and description as StringRef
There is no good reason for these to be std::strings, as these
are just (optional) constants for nice user output. This ends up
reducing the allocations significantly.

When measuring allocations when running no tests, the changes are
`tests/SelfTest` 9213 -> 7705
`tests/ExtraTests/NoTests` 3723 -> 2215
2023-12-26 14:40:45 +01:00
Martin Hořeňovský
2b69a3e216
Remove superfluous catch_session.hpp include in catch_sharding.hpp 2023-12-26 14:02:19 +01:00
Martin Hořeňovský
9aadc3a53d
Cleanup includes in sources
Mainly just removes some unused includes, but sometimes the include
is replaced by a smaller header instead.
2023-12-23 11:23:32 +01:00
Martin Hořeňovský
64ade68ca2
Remove superfluous duration_casts from benchmarking 2023-12-21 18:40:00 +01:00
Martin Hořeňovský
680064d391
Don't store right end of the interval in uniform_integer_distribution 2023-12-21 18:39:18 +01:00
Martin Hořeňovský
53d0d913a4
v3.5.0 2023-12-11 00:55:40 +01:00
Martin Hořeňovský
b7d70ddcd6
Ensure we always read 32 bit seed from std::random_device 2023-12-10 21:37:12 +01:00
Martin Hořeňovský
a6f22c5169
Remove static instance of std::random_device in Benchmark::analyse_samples 2023-12-10 21:22:43 +01:00
Martin Hořeňovský
1887d42e3d
Use our PCG32 RNG instead of mt19937 in Benchmark::analyse_samples 2023-12-10 21:18:23 +01:00
Martin Hořeňovský
1774dbfd53
Make it clearer that the JSON reporter is WIP 2023-12-10 21:04:56 +01:00
Martin Hořeňovský
cb07ff9a7e
Fix uniform_floating_point_distribution for unit ranges 2023-12-10 19:53:46 +01:00
Martin Hořeňovský
ae4fe16b81
Make the user-facing random Generators reproducible
Thanks to the new distributions, this is almost trivial change.
2023-12-10 19:53:44 +01:00
Martin Hořeňovský
28c66fdc5a
Make uniform_floating_point_distribution reproducible
By moving to use our `uniform_integer_distribution`, which is
reproducible across different platforms, instead of the stdlib
one which is not, we can provide reproducible results for `float`s
and `double`s. Still no reproducibility for `long double`s, because
those are too different across different platforms.
2023-12-10 19:53:41 +01:00
Martin Hořeňovský
ed9d672b5c
Add uniform_integer_distribution 2023-12-10 19:53:39 +01:00
Martin Hořeňovský
04a829b0e1
Add helpers for implementing uniform integer distribution
* Utility for extended mult n x n bits -> 2n bits
* Utility to adapt output from URBG to target (unsigned) integral
  type
* Utility to reorder signed values into unsigned type while keeping
  the order.
2023-12-10 19:53:36 +01:00
Martin Hořeňovský
ab1b079e4d
Add uniform_floating_point_distribution 2023-12-10 18:44:12 +01:00
Martin Hořeňovský
d139b4ff7c
Add implementation of helpers for uniform float distribution
Specifically we add
 * `gamma(a, b)`, which returns the magnitude of largest 1-ULP
   step in range [a, b].
 * `count_equidistant_float(a, b, distance)`, which returns the
   number of equi-distant floats in range [a, b].
2023-12-10 18:44:10 +01:00
Martin Hořeňovský
bfd9f0f5a6
Move nextafter polyfill to polyfills.hpp 2023-12-10 18:44:06 +01:00
SupSuper
4a7be16c8c Fix compilation on Xbox platforms
Xbox does not support getenv
2023-12-02 22:03:48 +01:00
Martin Hořeňovský
32d9ae24bc
JSONWriter deals in StringRefs instead of std::strings
Together with liberal use of `_sr` UDL to compile-time convert
string literals into StringRefs, this will reduce the number of
allocation and remove most of the strcpy calls inherent in
converting string lits into `std::string`s.
2023-11-17 09:54:03 +01:00
Sergei Iskakov
de7ba4e889 fn need to be in parenthesis
Otherwise intel c++ 19.1 cause an error
"expression preceding parentheses of apparent call must have (pointer-to-) function type CATCH2"
2023-11-16 12:33:35 +01:00
Martin Hořeňovský
733b901dd2
Fix special character escaping in JsonWriter 2023-11-14 23:35:22 +01:00
Beartama
7bf136b501
Add JSON reporter (#2706)
Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2023-11-14 22:52:15 +01:00
Martin Hořeňovský
caffe79a31
Fix missing include in catch_message.hpp
Because the issue comes from the expansions of `UNSCOPED_INFO`,
surrogate TUs could not catch this bug, and in common usage, the
include transitively comes from `catch_test_macros.hpp`.

Fixes #2758
2023-11-04 00:33:18 +01:00
Martin Hořeňovský
6ebc013b8c
Fix UDL definitions for C++23
Technically, the declaration should not have a space between
the quotes and the underscore, because `_foo` is a reserved
identifier, but `""_foo` is not. In general it works, but newer
Clang versions warn about this, because WG21 wants to deprecate
and later remove this form completely.
2023-10-28 21:35:03 +02:00
Christian Tacke
0fb817e41f fix some bugprone-macro-parentheses warnings
When using the public headers of catch2 in another project
that uses clang-tidy with some checks enabled, then some
warnings in catch2's headers are also reported.

This fixes a bunch of bugprone-macro-parentheses warnings.

See: https://clang.llvm.org/extra/clang-tidy/checks/bugprone/macro-parentheses.html
2023-09-25 10:56:45 +02:00
Martin Hořeňovský
92672591c1
Make jackknife TU-local to stats.cpp 2023-09-16 21:29:47 +02:00
Martin Hořeňovský
56fcd584c1
Make directCompare TU-local to stats.cpp 2023-09-16 21:18:44 +02:00
Jonathan Allen Grant
aafe09bc1c
Update meson.build to fix #2722 (#2742) 2023-09-13 10:06:14 +02:00
Martin Hořeňovský
47a2c96938
Reduce the number of templates in Benchmarking
The basic idea was to reduce the number of things dependent on the `Clock`
type. To that end, I replaced `Duration<Clock>` with `IDuration` typedef
for `std::nanoseconds`, and `FloatDuration<Clock>` with `FDuration`
typedef for `Duration<double, std::nano>`. We can generally assume that
any clock's duration can be expressed in nanoseconds, as long as we insert
`duration_cast`s into the right places.

Note that we cannot remove all dependence on `Clock` as a template
arguments, because functions that actually measure the elapsed time have
to use the Clock.

We also changed some template function arguments to pass plain function
pointers, so that the actual implementation can be placed into a cpp file.
2023-09-08 10:04:31 +02:00
Martin Hořeňovský
fb96279aed
Remove superfluous stdlib includes from catch_benchmark.hpp 2023-09-08 10:04:24 +02:00
Martin Hořeňovský
e14a08d734
Remove unused typedef from Benchmark::Environment 2023-09-08 10:04:22 +02:00
Martin Hořeňovský
9bba07cb87
Replace vector iterator args in benchmarks with ptr args 2023-09-08 10:04:19 +02:00
Martin Jeřábek
3a5cde55b7 implement stringify for std::nullopt_t 2023-08-30 16:21:02 +02:00
Martin Hořeňovský
f24d39e42b
Support C arrays and ADL ranges in from_range generator
Closes #2737
2023-08-29 15:38:13 +02:00
Martin Hořeňovský
e09de7222c
Small cleanup in XML reporter 2023-08-14 12:41:52 +02:00
Martin Hořeňovský
a64ff326bf
Change 'estimated' to 'est run time' in console reporter output 2023-08-14 10:22:59 +02:00
Martin Hořeňovský
ad56463477
Flush stream after benchmarkStarting in ConsoleReporter
This means that the user will see the estimation of full benchmark
running time when it is available, unlike now when it often only
ends up flushed after the benchmark is fully finished.

This means that the user will almost immediately see the start
of table like this

```
benchmark name                       samples       iterations    estimated
                                     mean          low mean      high mean
                                     std dev       low std dev   high std dev
-------------------------------------------------------------------------------
Fill vector generated                          100            54     3.0834 ms
```

This presents significant improvement in user experience especially
for long running benchmarks.
2023-08-13 23:09:02 +02:00
Martin Hořeňovský
d7304f0c41
Constify section hints in static-analysis mode
This prevents a `misc-const-correctness` in clang-tidy
2023-08-10 21:02:18 +02:00
rosstang
cd60a0301c
Assert Info reset need to also reset result disposition to normal to handle uncaught exception correctly (#2723)
* AssertionEnd does not reset the assertion info yet. That is done after populateReaction. And reset assertion info would also reset the result disposition to normal, so that any uncaught exception would be reported as failure

* Approving test output changes due to added unit tests

* Unit tests to throw std::runtime_error instead of std::exception

* Add a unit test to test incomplete assertion handler

---------

Co-authored-by: Ross <ross.tang@gfo-x.com>
2023-08-07 22:07:31 +02:00
Martin Hořeňovský
b593be2116
Always default empty destructors 2023-08-05 18:21:38 +02:00
Vitalii Trubchaninov
ed4acded38 Don't define tryTranslators function if exception are disabled
"-Wunused-function -Wall" produces if this function is defined when exceptions are disabled
2023-08-04 15:28:55 +02:00
Riom
4acc51828f
Introduce CATCH_CONFIG_PREFIX_MESSAGES to only prefix a few logging related macros. (#2544)
* Add missing include for VxWorks build.

std::min is defined in algorithm provides std::min. It appears to be transitively included for most platforms. For VxWorks however this explicit include is required.

* Add option CATCH_CONFIG_PREFIX_MESSAGES to selectively prefix message macros only.

In contrast to CATCH_CONFIG_PREFIX_ALL, this will only prefix the following macros:
I.e. INFO, UNSCOPED_INFO, WARN and CATCH_CAPTURE

This is mainly useful for codebases that use INFO or WARN for their own logging macros.
2023-07-19 17:04:43 +02:00
Martin Hořeňovský
6e79e682b7
v3.4.0 2023-07-13 13:37:30 +02:00
Martin Hořeňovský
bf5aa7b383
Experimental static analysis support in TEST_CASE and SECTION
Closes #2681
2023-05-29 21:45:28 +02:00
Martin Hořeňovský
dba9197ec7
Add new config option: STATIC_ANALYSIS_SUPPORT 2023-05-29 00:55:20 +02:00
Martin Hořeňovský
f60c15364b
Add macro for suppressing Wshadow 2023-05-28 21:07:31 +02:00
Martin Hořeňovský
73b93ce6bc
Include catch_user_config.hpp in all catch_config_* files 2023-05-28 21:04:16 +02:00
Cristian Morales Vega
535205e2ac Suppress -Wunused-result warning in gcc
See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425.
2023-05-23 23:31:55 +02:00
Martin Hořeňovský
a153fce724
Improve error messages for TEST_CASE tag parsing errors
Also removes a duplicated test case checking for empty tag error.

Related to #2650
2023-05-20 21:13:48 +02:00
ThePhD
05d7eb5a00
🛠 Add <exception> header where strictly necessary 2023-05-16 12:18:57 -04:00
Martin Hořeňovský
598895d048
Fix Wredundant-decls
Closes #2682
2023-05-12 09:51:13 +02:00
Martin Hořeňovský
0dc82e08df
Move CATCH_INTERNAL_STRINGIFY macro into its own header 2023-05-07 20:58:54 +02:00
Martin Hořeňovský
8ca504cbc9
Move AssertionResult when passing it inside RunContext 2023-05-06 23:58:48 +02:00
Martin Hořeňovský
c57b5cdf43
Move-enable Catch::optional
This avoids copies in couple places through Catch2, e.g. reporter
spec handling, and moving around `AssertionResult` in `RunContext`.
2023-05-06 15:22:02 +02:00
Martin Hořeňovský
d84777c9cb
Fix assertionStarting events being sent after the expr is evaluated
Closes #2678
2023-05-06 11:48:41 +02:00
Martin Hořeňovský
51fdbedd13
Internal linkage for outlier_variance 2023-05-01 13:21:47 +02:00
Martin Hořeňovský
10f0a58643
Some template instantiation reductions 2023-05-01 13:21:45 +02:00
Martin Hořeňovský
fe64c28925
Reduce compilation costs of benchmarks
We replaced some simple std::algorithm usage by loops, and reduced
header inclusion.
2023-05-01 13:21:41 +02:00
Martin Hořeňovský
7d07efc92b
Clean up iterator usage in benchmarks
Specifically we turned `mean`, `classify_outliers`, `jackknife`,
into concrete functions that take only `const_iterator` from vecs,
instead of generic iterators over anything.

I also changed `resample` to take `const_iterator` instead of
plain `iterator`, and similar for `standard_deviation`, and
`analyse_samples`.
2023-05-01 13:21:36 +02:00
Martin Hořeňovský
f3c678c0ab
Constexprify constants in estimate_clock.hpp 2023-05-01 13:21:33 +02:00
Vertexwahn
46539b6d9b Fix spelling 2023-04-29 12:55:51 +02:00
Holger Kaelberer
10596b2278 Fix unreachable-code-return warnings 2023-04-20 14:53:03 +02:00
Martin Hořeňovský
9a2a4eadc0
Bump xml-format-version in XML reporter 2023-04-10 21:59:50 +02:00
Martin Hořeňovský
fb806da76f
Add lineinfo to XML reporter output for INFO/WARN
Closes #1251
2023-04-10 16:32:07 +02:00
Martin Hořeňovský
9f08097f55
Cleanup internal includes by splitting out some event structs
* Split out BenchmarkInfo and BenchmarkStats to their own header
* Outline BenchmarkStats<> declaration to separate header
* Split out TestRunInfo into its own header

These changes let us remove the large `interfaces_reporter.hpp`
include from `benchmark.hpp`, and replace it with
`interfaces_capture.hpp` in `run_context.hpp`.

I also cleaned out `interfaces_repoter.hpp` from reporter headers
that depend on `reporter_common_base.hpp`. This will not change
anything in the actual inclusion set, but makes it logically
more consistent.
2023-03-31 19:31:51 +02:00
Martin Hořeňovský
1f881ab464
Split ITestInvoker into its own header 2023-03-23 16:50:11 +01:00
Martin Hořeňovský
c487b27d9d
Reduce misc includes all around 2023-03-23 16:50:07 +01:00
Martin Hořeňovský
3230760db2
Cleanup in translating exceptions to messages 2023-03-23 12:26:44 +01:00
Martin Hořeňovský
b3ebce715e
Cleanup benchmarking includes 2023-03-23 11:59:40 +01:00
Martin Hořeňovský
d0f70fdfd6
Unify IReporterRegistry and ReporterRegistry
To keep the compilation firewall effect, the implementations
are hidden behind a PIMPL. In this case it is probably not
worth it, but we can inline it later if needed.
2023-03-22 23:58:44 +01:00
Martin Hořeňovský
4f4ad8ada9
Sprinkle some constexpr around 2023-03-22 19:12:32 +01:00