1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-06-17 10:46:08 -04:00
Commit Graph

114 Commits

Author SHA1 Message Date
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
f5cee49c71 Add test for iterators with const T as the value_type 2024-11-11 06:49:11 +01:00
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 .
2024-10-14 21:02:03 +02:00
f7cd0ba051 TEST_CASE_PERSISTENT_FIXTURE: A new fixture macro for allowing persistent fixtures throughout a TEST_CASE ()
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 

---------

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2024-08-05 17:01:41 +02:00
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
05fb437cbb Fix & extend tests for comparing const instances of zero lit types 2024-04-08 13:15:35 +02:00
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
88f4ec3cc5 Ignore C++98 related compiler warnings
Catch2 has long since required a standard newer than C++98 so we
can safely ignore any warnings related to such old standards.
2024-03-12 22:56:37 +01:00
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
c3fd4eb17e Update outdated tests for stringifying characters
Previously the tests relied purely on output changes in approvals.
Now the stringification output is checked directly as part of the
unit tests.
2024-03-01 15:09:11 +01:00
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
9a1e73568c Add test showing literals and complex generators in one GENERATE 2023-12-10 18:32:45 +01:00
79d39a1954 Fix tests for C++23's multi-arg index operator
Closes 
2023-10-28 21:49:58 +02:00
9c541ca72e Add test for multiple streaming parts in UNSCOPED_INFO 2023-09-17 10:44:31 +02:00
3a5cde55b7 implement stringify for std::nullopt_t 2023-08-30 16:21:02 +02:00
cd60a0301c Assert Info reset need to also reset result disposition to normal to handle uncaught exception correctly ()
* 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
0631b607ee Test & document SKIP in generator constructor
Closes 
2023-05-31 15:12:43 +02:00
dff7513b28 Static analysis cleanup in tests 2023-05-29 21:45:30 +02:00
46539b6d9b Fix spelling 2023-04-29 12:55:51 +02:00
10596b2278 Fix unreachable-code-return warnings 2023-04-20 14:53:03 +02:00
0a0ebf5003 Support elements without op!= in VectorEquals
Closes 
2023-03-05 00:11:38 +01:00
6fbb3f0723 Add IsNaN matcher 2023-02-26 00:14:32 +01:00
e8ba329b6c Add support for iterator+sentinel pairs in Contains matcher 2023-02-10 23:25:45 +01:00
cefa8fcf32 Enable use of UnorderedRangeEquals with iterator+sentinel pairs 2023-02-06 15:34:38 +01:00
772fa3f790 Add Catch::Detail::is_permutation that supports sentinels
Also split out helpers for testing matcher ranges (types whose
begin/end/empty/etc require ADL lookup, types whose iteration
uses iterator + sentinel pair, etc) into their own file.
2023-02-06 15:29:01 +01:00
f3c0a3cd09 Fix RangeEquals matcher to handle iterator + sentinel ranges
Also added tests for types that require ADL lookup for their
`begin` and `end`.
2023-02-03 18:22:41 +01:00
8359a6b244 Stop exceptions in generator constructors from aborting the binary
Fixes 
2023-01-22 16:04:16 +01:00
efca9a0f18 Added ElementsAre and UnorderedElementsAre ()
Co-authored-by: Garz4 <fancygarz4@gmail.com>
Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2023-01-22 00:33:04 +01:00
d548be26e3 Add new SKIP macro for skipping tests at runtime ()
* Add new SKIP macro for skipping tests at runtime

This adds a new `SKIP` macro for dynamically skipping tests at runtime.
The "skipped" status of a test case is treated as a first-class citizen,
like "succeeded" or "failed", and is reported with a new color on the
console.

* Don't show "skipped assertions" in console/compact reporters

Also extend skip tests to cover a few more use cases.

* Return exit code 4 if all test cases are skipped

* Use LightGrey for the skip colour

This isn't great, but is better than the deep blue that was borderline
invisible on dark backgrounds. The fix is to redo the colouring
a bit, including introducing light-blue that is actually visible.

* Add support for explicit skips in all reporters

* --allow-running-no-tests also allows all tests to be skipped

* Add docs for SKIP macro, deprecate IEventListener::skipTest

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2023-01-12 15:01:47 +01:00
9c0533a905 Add MessageMatches matcher for exception () 2022-12-12 00:40:47 +01:00
28e651f152 Move SFINAE in decomposer into return type
This is needed so that we can use conjunction and other logical
type traits to workaround issue with older GCC versions (8 and
below), when they run into types that have ambiguous constructor
from `0`, see e.g. .

However, using conjunction and friends in the SFINAE constraint
in the template parameter breaks for C++20 and up, due to the new
comparison operator rewriting rules. With C++20, when the compiler
see `a == b`, it also tries `b == a` and collects overload set
for both of these expressions.

In Catch2, this means that e.g. `REQUIRE( 1 == 2 )` would lead
the compiler to check overloads for both `ExprLhs<int> == int`
and `int == ExprLhs<int>`. Since the overload set and SFINAE
constraints assume that `ExprLhs<T>` is always on the left side,
when the compiler tries to resolve the template parameters, all
hell breaks loose and the compilation fails.

By moving the SFINAE constraints to the return type, the compiler
can discard the switched expression without having to resolve
the complex SFINAE constraints, and thus everything works the
way it is supposed to.

Fixes 
2022-12-09 00:40:01 +01:00
a20200be7e Revert "Fix old GCC + types with ambiguous constructor from 0"
This reverts commit 291c502f66.

The issue is that it breaks under C++20 for some reason.
2022-11-22 15:23:03 +01:00
291c502f66 Fix old GCC + types with ambiguous constructor from 0
Closes 
2022-11-20 17:07:32 +01:00
ec59cd8736 Support decomposing types that only compare with literal 0
This is primarily done to support new `std::*_ordering` types,
but the refactoring also supports any other type with this
property.

The compilation overhead is surprisingly low. Testing it with
clang on a Linux machine, compiling our SelfTest project takes
only 2-3% longer with these changes than it takes otherwise.

Closes 
2022-11-04 19:24:44 +01:00
b3dbd83da2 Add test for comparing pointers to NULL with != 2022-11-04 19:24:39 +01:00
f1084fb309 Fix references to license file
The license file was renamed with 6a502cc2f5
2022-10-28 11:30:15 +02:00
77f7c0104d Fix fibonacci impl in benchmark tests
The previous implementation was always 1 number ahead. Fixing this
is not important at all, but it was bugging me.
2022-10-18 10:44:18 +02:00
9c9f35068e Normalize C++ namespace in JUnit's reporter classname field
Closes 
2022-07-17 19:15:20 +02:00
1bd233866c Add AllTrue, AnyTrue, NoneTrue matchers 2022-07-16 16:16:05 +02:00
caf1264588 Fixes for matcher testing helpers when testing bools 2022-07-16 16:16:05 +02:00
ff9506cedd Only test SEH handling with MSVC
MinGW doesn't support `__try` and friends at all, while Clang
only supports it partially, and the test would require some
changes to make it work there. Since this is only a test, we can
afford to keep it MSVC-only.

Closes 
2022-06-06 00:29:01 +02:00
fc3d11b1d1 Add Wfloat-equal to default-enabled warnings
This is kinda messy, because there is no good way to signal to
the compiler that some code uses direct comparison of floating
point numbers intentionally, so instead we have to use diagnostic
pragmas.

We also have to over-suppress the test files, because Clang (and
possibly GCC) still issue warnings from template instantiation
even if the instantion site is under warning suppression, so the
template definition has to be under warning suppression as well.

Closes 
2022-05-14 15:47:20 +02:00
1ef65d60f1 Tiny fixup in Misc.tests.cpp 2022-05-11 22:56:30 +02:00
e2d07d35f4 Add -Wmissing-prototypes to common warnings 2022-05-03 13:54:05 +02:00
198713e5dc Cleanup of unused functions
The cleanup also found out that custom translation for std-derived
exceptions test wasn't running properly, and fixed that.
We cannot enable the warning globally, because the tests contain
some functions that are unused by design -- e.g. when checking
stringification priority of StringMaker vs range fallback and so
on.
2022-05-02 21:32:24 +02:00
291b35b389 Added --skip-benchmarks command-line option. ()
Closes 

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2022-04-23 23:14:49 +02:00
cf6dd937ab Add test for FatalConditionHandler and stack unwinding
Signed-off-by: Kochetkov, Yuriy <yuriyx.kochetkov@intel.com>
2022-03-24 15:49:02 +01:00
81f612c96c Refactor MatchersRanges test utils ()
- do not hardcode content of containers
- prefix members with m_
- add const and non-const iterators to `with_mocked_iterator_access`
- remove `m_touched` as it wasn't filled properly and isn't used anyway
2022-03-09 23:13:37 +01:00
1d4b42ad7b Minor whitespace fix 2022-02-21 20:04:43 +01:00
f83332d89b Use the new licence header in SelfTest's cpp files 2022-01-29 00:03:43 +01:00