Commit Graph

4048 Commits

Author SHA1 Message Date
Martin Hořeňovský
12d14a3c63
Add support for multiply calling lambda parsers in Clara
Previously a lambda parser in Clara could only be invoked once,
even if it internally was ok with being invoked multiple times.

With this change, a lambda parser can mark itself as `accept_many`,
in which case it will be invoked multiple times if the appropriate
flag was supplied multiple times by the user.
2021-10-27 20:15:28 +02:00
Martin Hořeňovský
f17725a186
Split void_type into its own header and rename it to void_t 2021-10-27 20:01:13 +02:00
Martin Hořeňovský
ec2d5013fb Make testSharding.py test script executable 2021-10-27 17:24:30 +02:00
Martin Hořeňovský
342ef5ca7e Cleanup the shard integration test script 2021-10-27 17:24:30 +02:00
Martin Hořeňovský
5ac1ffe9ee Improve shardIndex/Count cli argument parsing 2021-10-27 17:24:30 +02:00
Ben Dunkin
3087e19cc7 Allow test sharding for e.g. Bazel test sharding feature
This greatly simplifies running Catch2 tests in single binary
in parallel from external test runners. Instead of having to
shard the tests by tags/test names, an external test runner
can now just ask for test shard 2 (out of X), and execute that
in single process, without having to know what tests are actually
in the shard.

Note that sharding also applies to test listing, and happens after
tests were ordered according to the `--order` feature.
2021-10-27 17:24:30 +02:00
Martin Hořeňovský
6456ee8b01
Return Clara parsing error message by const-ref 2021-10-27 15:10:52 +02:00
Martin Hořeňovský
905bf438ae
Fix bad indentation calculation in the console reporter
The problem came from the console reporter trying to provide a
fancy linebreaking (primarily for things like `SCENARIO` or the
BDD macros), so that new lines start with extra indentation if
the text being line broken starts as "{text}: ".

The console reporter did not properly take into account cases
where the ": " part would already be in a later line, in which
case it would ask for non-sensical level of indentation (larger
than single line length).

We fixed this by also enforcing that the special indentation case
only triggers if the ": " is found early enough in the line, so
that we also avoid degenerate cases like this:
```
blablabla: F
           a
           n
           c
           y
           .
           .
           .
```

Fixes #2309
2021-10-25 15:21:28 +02:00
Martin Hořeňovský
0fdee1c273
Stop declaring compiled Catch2 artifacts as arch independent 2021-10-25 14:46:54 +02:00
Anders Schau Knatten
22750cde0e Disable false positive from clang-tidy
Clang-tidy is smart enough to understand that the conditional is never
updated in the loop body. It will let you get away with it if it can
prove that the conditional is always false, but that is not always
possible.

Here is an example where it's not able to prove it, and thus gives a
false positive. This is a minimal reproduction of an actual case I hit
in production, where `function` is picking the function based on some
`constexpr` logic related to which type argument is currently being
tested.

```
int f();

TEMPLATE_TEST_CASE("reproduction", "", int) {
    const auto function = []() {
        return f;
    }();
    const int error = function();
    REQUIRE(error == 0); // clang-tidy complains: bugprone-infinite-loop
}
```

I did not choose to add this test to the test suite, since we're not
running `clang-tidy` in CI afaik. To run it manually, simply add the
snippet above somewhere and run clang-tidy with
`--checks=bugprone-infinite-loop`. Or see an example at
https://godbolt.org/z/4v8b8WexP.

The reason we get the infinite loop warning in the first place is the
conditional at the end of this `do`-loop. Ideally, this conditional
would just be `while(false)`, but the actual content of the
`REQUIRE`-statement has been included here too in order to not loose
warnings from signed/unsigned comparisons. In short, if you do
`REQUIRE(i < j)`, where `i` is a negative signed integer and `j` is an
unsigned integer, you're supposed to get a warning from
`-Wsign-compare`. Due to the decomposition in Catch2, you lose this
warning, which is why the content of the `REQUIRE` statement has been
added to the conditional to force the compiler to evaluate the actual
comparison as well.

This was discussed on Discord today, and an alternative approach (which
I don't have time to implement) would be to in the decomposition replace
the comparison operators with `cmp_less` and friends. These are C++20
though, and would have to be implemented manually. I am also not sure
it's a good idea to "magically" change the semantics of `<` when it's
used inside a `REQUIRE` macro.

Another alternative approach would be to trigger this warning in a
different way, by including the content of the `REQUIRE` macro in a
different way which doesn't affect the for loop. But I don't have enough
of an overview here to know where would be a good place and how to test
that I didn't break anything.
2021-10-21 22:45:19 +02:00
Martin Hořeňovský
bf5c58adf6
The limit on TEMPLATE* test cases is actually reachable 2021-10-21 15:52:07 +02:00
Alecto Irene Perez
06cf2a4724
Apply PR #2297 to devel branch (#2300)
* Apply PR #2297 to devel branch

It turns out that Issue #2272 partially affected the devel branch. When
building tests with C++20, the compiler emits a warning that top-level
comma expressions in array subscripts are depricated. Warnings are
treated as errors, so this caused the build to fail.

This commit adds localized warning suppression
in accordance with this recommendation here:
https://github.com/catchorg/Catch2/pull/2297#discussion_r720848392

Signed-off-by: Alecto Irene Perez <perez.cs@pm.me>

* Fixed unknown pragma warning on old versions of gcc & clang

This commit fixes an unkwown pragma warning on older versions of GCC
and Clang. These older versions don't have a warning for depricated use
of the comma subscript. Because warning suppression is localized, and
only refers to the comma subscript warning, it doesn't affect compiler
warnings in other parts of the code.

Signed-off-by: Alecto Irene Perez <perez.cs@pm.me>

* More #warning backwards compatibility fixes

Signed-off-by: Alecto Irene Perez <perez.cs@pm.me>
2021-10-21 15:47:21 +02:00
Martin Hořeňovský
4436a60456
Add myself to FUNDING 2021-10-11 10:44:29 +02:00
Martin Hořeňovský
36b4a71ff0
Pick release notes for 2.13.7 2021-10-10 22:23:14 +02:00
Martin Hořeňovský
b406ad52a7
Mark !mayfail tests as skipped in the JUnit reporter
Should fix #2116
2021-10-10 22:21:39 +02:00
Martin Hořeňovský
de67278e14
JUnit reporter uses only 3 decimal places when reporting durations
We used to use whatever precision we ended up having from C++'s
stdlib. However, some relatively popular tools, like Jenkins,
use Maven SureFire XML schema to validate JUnit test reports, and
Maven SureFire schema requires the duration to have at most 3
decimal places.

For compatibility, the JUnit reporter will now respect this
limitation.

Closes #2221
2021-10-10 22:10:48 +02:00
Martin Hořeňovský
1d9696d22d
Cleanup reporting of rng seed in existing reporters 2021-10-09 00:02:30 +02:00
Martin Hořeňovský
ed1f343a41
Provide random-device option for --rng-seed and make it default 2021-10-08 21:35:45 +02:00
Martin Hořeňovský
200a487cf2
Add generateRandomSeed utility to generate randomness seed 2021-10-08 21:35:41 +02:00
Martin Hořeňovský
fce42b62ad
Generate random rng seed if user did not specify one
Closes #2161
2021-10-08 21:35:29 +02:00
Martin Hořeňovský
4e6d306742
Rename Catch::Option to Optional 2021-10-05 20:39:28 +02:00
Martin Hořeňovský
c6c46a168f
Add non-empty assertion to Option's deref op 2021-10-05 19:22:22 +02:00
Martin Hořeňovský
48a889859b
Simplify how ratio symbol is returned when stringifying ratios 2021-10-03 20:23:10 +02:00
Martin Hořeňovský
d65ee04b74
Remove double serialization when stringifying std::optional 2021-10-03 20:19:36 +02:00
Martin Hořeňovský
928e198ef2
Demote some single character strings into plain chars 2021-10-03 10:37:30 +02:00
Martin Hořeňovský
3e9c6fec22
Remove XmlWriter::writeBlankLine
There is no good reason to provide a "add empty line" primitive
for writing XML documents, and the fact that it remains unused
after all the time it was provided only confirms this further.
2021-10-02 14:39:54 +02:00
Martin Hořeňovský
13670f535f
Add more tests for XmlWrite::write* members 2021-10-02 14:39:52 +02:00
Martin Hořeňovský
c6640e4f47
Improve documentation of CATCH_MOVE and CATCH_FORWARD 2021-09-30 20:40:24 +02:00
Martin Hořeňovský
23f0d94b4f
Use CATCH_FORWARD in Detail::make_unique 2021-09-30 20:27:38 +02:00
Martin Hořeňovský
77c7e9803e
Improve documentation on Detail::unique_ptr 2021-09-30 20:17:59 +02:00
Martin Hořeňovský
1d79683ea8
Add [[trivial_abi]] to Detail::unique_ptr when compiled with Clang
This decreases code size and improves performance of passing around
`unique_ptr` instances by value somewhat. It virtually guarantees
problems when combining code compiled with Clang and GCC, but that
was never supported anyway.
2021-09-30 20:11:22 +02:00
Anders Schau Knatten
eb452e9b35 Bring back useful comment
In b7b346c3e5 this conditional was simplified to just
`while( false)` rather than the current one. Then in 3a33315ff8, that
change was reverted. I found it hard to understand this
complicated conditional, but after some digging in history I found this
comment which used to be here. It was removed in b7b346c3e5, but not
restored together with the revert in 3a33315ff8. Let's revive it.
2021-09-29 18:19:31 +02:00
Martin Hořeňovský
2deafc33e9
Demote getCurrentNanosecondsSinceEpoch to internal linkage 2021-09-29 11:26:38 +02:00
Martin Hořeňovský
5250cf6d58
Remove getEstimatedClockResolution from Timer
It used to be part of the experimental benchmarking support, but
since that was replaced with proper benchmarking support with its
own timer facilities, it is now a dead code and useless.
2021-09-29 11:24:18 +02:00
Martin Hořeňovský
426954032f
Rename Contains string matcher builder to ContainsSubstring
The problem with the old name was that it collided with the
range matcher `Contains`, and it was not really possible to
disambiguate them just with argument types.

Closes #2131
2021-09-27 21:28:33 +02:00
Martin Hořeňovský
f02c2678a1
Use StringRef for className in TestCaseInfo 2021-09-27 19:07:45 +02:00
Martin Hořeňovský
21b99d6f58
Add StringRef::compare for three way comparison 2021-09-27 18:41:17 +02:00
Martin Hořeňovský
d42e7a23a0
Change startsWith(char) to take StringRef as argument 2021-09-27 14:55:28 +02:00
Martin Hořeňovský
7bb00a42be
Remove stub of obsolete test 2021-09-27 14:45:39 +02:00
Martin Hořeňovský
fb4153e05e
Multiple tests can have same name as long as their tags differ
This change also changes it so that test case macros using a
class name can have same name **and** tags as long as the
used class name differs.

Closes #1915
Closes #1999
2021-09-25 21:37:03 +02:00
Martin Hořeňovský
e8e28ba401
Remove obsolete documentation page 2021-09-23 23:42:16 +02:00
Bernhard Manfred Gruber
ee1435793e add alpaka and LLAMA to Catch2 users 2021-09-23 12:39:56 +02:00
Martin Hořeňovský
3f8cae8025
Add consistency-checking event listener to SelfTest
This event listener performs basic consistency checks (akin to
matching braces) on events that are passed to the listeners
when the `SelfTest` test binary is run.

The current checks are about nesting events (e.g. `testCaseStarting`
cannot be received before `testRunStarting`, `sectionStarting`
can only be received when a test case is active, etc), and matching
up counts of starting/ended events.

The simplicity means that it could be confused by starting/ended
events matching up but being out of order, e.g.
```
* test case A starting
* test case B ended
* test case B starting
* test case A ended
```
would be accepted, even though it is wrong. However, doing full
order checking would be much more implementation work, for relatively
little benefit, so it is left out for now.
2021-09-15 23:38:43 +02:00
Martin Hořeňovský
2c82f82ee2
Mark first party reporters final
They are not intended to be derived from, so forbidding it
explicitly improves our ability to refactor them later.
2021-09-15 21:29:18 +02:00
Martin Hořeňovský
785436cd74
Make benchmark* and fatalError reporter events pure virtual 2021-09-15 21:17:39 +02:00
Martin Hořeňovský
f314fa1f8c
assertionEnded event in reporters no longer returns bool 2021-09-15 18:57:56 +02:00
Martin Hořeňovský
013edc208b
Refactor noMatchingTestCases and skipTests reporter methods
They now take `StringRef` as the argument, and are virtual only
in the basic interface.

Also cleaned out the various reporters and their overrides
of these members which were often empty or delegating up.
2021-09-15 18:08:31 +02:00
Martin Hořeňovský
10fb93cce8
Add new reporter event called for each test case enter/exit
This means that e.g. for `TEST_CASE` with two sibling `SECTION`s
the event will fire twice, because the `TEST_CASE` will be entered
twice.

Closes #2107 (the event mentioned there already exists, but this
is its counterpart that we also want to provide to users)
2021-09-14 13:19:45 +02:00
Martin Hořeňovský
4dcf8382c7
Default-implement assertion* events in StreamingReporterBase
This means that a reporter deriving from `StreamingReporterBase`
does not have to override them if it isn't interested in the individual
assertions.
2021-09-14 12:41:24 +02:00
Biswapriyo Nath
efd8cc8777 pkgconfig: Add missing entries
This adds prefix and exec_prefix fields
2021-09-11 19:02:21 +02:00