Commit Graph
213 Commits
Author SHA1 Message Date
Martin Hořeňovský c49faa62dd Let users of amalgamated distribution override the default main
Closes #2324
2021-12-02 13:49:16 +01:00
Martin Hořeňovský b9baae6d93 Cleanup StringRef impl a bit 2021-11-23 23:16:46 +01:00
Martin Hořeňovský 8cb8f0b08b Sweep out some Wsign-conversion warnings 2021-11-23 23:16:08 +01:00
Martin Hořeňovský 9200b4078b Move reporter_registrars.hpp to reporters/ 2021-11-10 23:52:59 +01:00
Martin Hořeňovský 6603f1d972 Use case in names of default reporters 2021-11-10 23:32:01 +01:00
Martin Hořeňovský 8780425385 Make reporter lookup case insensitive, registration case preserving
Previously registration was case preserving, but lookup used
lowercased reporter name, so a reporter whose name contained
upper case character could not be requested by the user.
2021-11-09 11:50:03 +01:00
Martin Hořeňovský 7800fe9708 Lift toLower(char) to header 2021-11-09 11:44:54 +01:00
Martin Hořeňovský 912df7df35 Fix quadratic runtime when linebreaking strings without newlines
The problem was that every line would iterate from current line
start position to the end of the string, looking for a newline
to break on, leading to accidentally quadratic runtime. With this
change, the code only ever searches up to the current line's
length and not more.

Credit to @jorgenpt for the fix suggestion.

Closes #2315
2021-11-04 00:23:56 +01:00
Martin Hořeňovský 70c4ec78fb Improve comments and names in TextFlow::Column 2021-11-01 19:14:37 +01:00
Martin Hořeňovský 455ae0c561 Typedef Column::iterator as Column::const_iterator not vice versa 2021-10-31 13:01:41 +01:00
Martin Hořeňovský 2520ad4b6e Return const_iterator from Column::begin/end const
This is what should normally happen, even if it does not change
anything given that `Column::const_iterator` is currently a typedef
for `Column::iterator`.
2021-10-31 12:59:00 +01:00
Martin Hořeňovský e539e1cb52 Move strings in Clara's result type 2021-10-29 23:04:24 +02:00
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ý 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
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ý 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ý 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ý 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ý 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ý f314fa1f8c assertionEnded event in reporters no longer returns bool 2021-09-15 18:57:56 +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ý 12bca890b7 Use StringRefs in SectionTracker's filter bookkeeping 2021-09-09 11:04:34 +02:00
Martin Hořeňovský b3a84c7983 Use StringRef in pluralise implementation
This means that it can no longer be safely made ahead of time,
but nothing in our existing code used it like that. Normally it
is constructed and used in the same expression, which is now
more efficient.
2021-09-08 00:24:40 +02:00
Martin Hořeňovský e5938007f7 Completely remove the testGroup events
This was done because they were 1:1 mapping to testRun events, and
I could not think of a reasonable way to make them their own thing.
2021-09-07 20:00:22 +02:00
Martin Hořeňovský 07018e2fba Force __cdecl calling convention for wmain
Fixes #2219
2021-08-26 23:13:27 +02:00
Martin Hořeňovský 7f3297f7e8 Sweep out unused <utility> includes 2021-08-19 21:44:17 +02:00
Martin Hořeňovský 4113a12c69 Fix Wreserved-identifier for UDLs in Catch2
See #578
2021-08-19 19:15:46 +02:00
Martin Hořeňovský edad4d0af7 Prefer _t over ::type form for std type traits 2021-08-19 00:21:13 +02:00
Martin Hořeňovský d2ee7100d2 Replace uses of std::move and std::forward with macros
This improves the SelfTest build times by about 3% (measured
with Clang 10 on random Linux box I had lying around).
2021-08-16 16:22:19 +02:00
Martin Hořeňovský 03ce304102 Add std::move/std::forward replacement macros
Using the `CATCH_MOVE` and `CATCH_FORWARD` macros instead of the
`std::move` and `std::forward<T>` utility functions can improve
compilation times and debug build's performance, and thus will
be preferred going forward.
2021-08-16 16:22:16 +02:00
Martin Hořeňovský 3579c055c8 Use Detail::make_unique<T> in more places 2021-08-11 22:51:59 +02:00
Martin Hořeňovský 3ec63324a8 Replace owning naked IStream pointers with unique_ptrs 2021-08-11 22:51:57 +02:00
Martin Hořeňovský 1b1f3a88bc Don't debug log empty strings 2021-08-06 11:38:54 +02:00
Martin Hořeňovský 02ab64da2e Cleanup ExceptionTranslatorRegistry::translateActiveException 2021-08-06 00:56:09 +02:00