Commit Graph

249 Commits

Author SHA1 Message Date
Gavin S 87d0197cbd
Update catch_reporter_tap.hpp
TAP format requires all results to be reported.
Removed extraneous preferences function (handled by parent)
Incorporated fix from 3d9e7db2e0
Simplified total printing
2020-07-26 14:00:10 +02:00
Martin Hořeňovský 4565b826cf
Modify generator tracking to allow GENERATEs between SECTIONs
This means that code such as

```cpp
TEST_CASE() {
    SECTION("first") { SUCCEED(); }
    auto _ = GENERATE(1, 2);
    SECTION("second") { SUCCEED(); }
}
```

will run and report 3 assertions, 1 from section "first" and 2
from section "second". This also applies for greater and potentially
more confusing nesting, but fundamentally it is up to the user to
avoid overly complex and confusing nestings, just as with `SECTION`s.

The old behaviour of `GENERATE` as first thing in a `TEST_CASE`,
`GENERATE` not followed by a `SECTION`, etc etc should be unchanged.

Closes #1938
2020-07-26 11:35:06 +02:00
Martin Hořeňovský 13917c44b4
--min-duration is overriden by -d no 2020-07-26 10:48:01 +02:00
John Bytheway 80b0d6975c
Add --min-duration option
A test runner already has a --durations option to print durations.
However, this isn't entirely satisfactory.

When there are many tests, this produces output spam which makes it hard
to find the test failure output.  Nevertheless, it is helpful to be
informed of tests which are unusually slow.

Therefore, introduce a new option --min-duration that causes all
durations above a certain threshold to be printed.  This allows slow
tests to be visible without mentioning every test.
2020-07-26 10:47:53 +02:00
George Rhoten a25c1a24af
Fix for macOS on ARM 2020-07-24 22:34:22 +02:00
Ryan Pavlik 7f58840163
Add OverallResultsCases element to XML reporter 2020-07-24 22:30:28 +02:00
Martin Hořeňovský b74996a29c
Devirtualize NameAndLocation query on trackers 2020-07-22 21:23:12 +02:00
Martin Hořeňovský de53773e46
Fix copy paste error in 7-arg TEMPLATE_TEST_CASE_SIG implementation
Closes #1954
2020-07-22 21:18:52 +02:00
Matthias Blankertz 9221a6ff65
Hide std::exception_ptr and friends if exceptions disabled
Some compilers, e.g. the Green Hills C++ compiler, react badly to the
appearance of std::exception_ptr, std::current_exception,
std::rethrow_exception and std::uncaught_exception(s). To allow usage of
Catch2 with these compilers when exceptions are disabled, hide the usage
of std::exception_ptr etc. when compiling with
CATCH_CONFIG_DISABLE_EXCEPTIONS.
2020-07-22 21:18:47 +02:00
Martin Hořeňovský 657ebf5db2
Replace stray tabs with spaces 2020-07-22 20:46:58 +02:00
Martin Hořeňovský 480f3f418b
Improved generator tracking
* Successive executions of the same `GENERATE` macro (e.g. because
of a for loop) no longer lead to multiple nested generators.
* The same line can now contain multiple `GENERATE` macros without
issues.

Fixes #1913
2020-07-22 20:44:22 +02:00
bogdasar1985 3ceaad7d66
fixing UB 2020-07-22 17:17:33 +02:00
Martin Hořeňovský 5c502320e8
Remove obsolete comment in UnorderedEquals vector matcher 2020-07-12 21:28:50 +02:00
Martin Hořeňovský f3fe2dcb11
Add status attribute to JUnit's section reporting
This brings our output inline with GTest's. We do not handle skipped
tests properly, but that should be currently less important than
having the attribute exist with proper value for non-skipped tests.

Thanks @joda-01.

Closes #1899
2020-07-12 21:22:15 +02:00
Natsu 8b5f6e26d3
Fix compilation failure when using libstdc++10 (#1929)
The issue is caused by deleted `std::__detail::begin` declared in `bits/iterator_concepts.h`. This would be found by ADL, and because it is deleted, compilation would fail. This change makes it so that we SFINAE on `begin(std::declval<T>())` and `end(std::declval<T>())` being well-formed.
2020-07-12 21:01:49 +02:00
Billy Robert O'Neal III c24f7e5b34
Fix invalid isspace call detected by PREfast
D:\vcpkg\toolsrc\include\catch2\catch.hpp(11285): warning C6330: 'char' passed as _Param_(1) when 'unsigned char' is required in call to 'isspace'.
D:\vcpkg\toolsrc\include\catch2\catch.hpp(11288): warning C6330: 'char' passed as _Param_(1) when 'unsigned char' is required in call to 'isspace'.

ISO/IEC 9899:2011:
"7.4 Character handling <ctype.h>"/1
[...] In all cases the argument is an int, the value of which shall be
representable as an unsigned char or shall equal the value of the macro
EOF. If the argument has any other value, the behavior is undefined.

This means if isspace was passed a character like ñ it could corrupt
memory without the static_cast to treat it as a positive value after
integral promotion (and C libraries commonly use the int index supplied
as a key into a table which result in out of bounds access if the
resulting int is negative).
2020-07-12 21:00:25 +02:00
Martin Hořeňovský 7dae3efad2
Silence clang-tidy's hicpp-vararg (alias of coreguidelines vararg)
Ideally, clang-tidy would be smart that if one alias of a warning
is suppressed, then the other one is suppressed as well, but as of
right now, it isn't. This means that for now we have to suppress
both aliases of this warning. Opened upstream issue to fix this:
https://bugs.llvm.org/show_bug.cgi?id=45859

Obviously, ideally clang-tidy would also not warn that we are calling
a vararg function when it is an unevaluated magic builtin, but that
also is not happening right now and I opened an issue for it:
https://bugs.llvm.org/show_bug.cgi?id=45860

Closes #1921
2020-07-12 20:59:29 +02:00
Corentin Jabot a71721801e Remove extra semi-colons 2020-07-10 13:40:42 +02:00
Corentin Jabot 2cd5e70012 Silence a -Wsign-conversio warning in Clara under GCC 2020-07-09 12:24:25 +02:00
Martin Hořeňovský 392e44ec21
Minor refactoring of CompactReporter 2020-05-31 22:34:37 +02:00
Martin Hořeňovský 317145514f
Add op+(StringRef, StringRef) -> std::string 2020-05-31 22:30:41 +02:00
Martin Hořeňovský f2b9508081
Remove last vestiges of shared ptr use with IConfig 2020-05-31 15:25:14 +02:00
Martin Hořeňovský 1d1ccf8f3c
Replace all uses of std::unique_ptr with Catch::Detail::unique_ptr
Doing some benchmarking with ClangBuildAnalyzer suggests that
compiling Catch2's `SelfTest` spends 10% of the time instantiating
`std::unique_ptr` for some interface types required for registering
and running tests.

The lesser compilation overhead of `Catch::Detail::unique_ptr` should
significantly reduce that time.

The compiled implementation was also changed to use the custom impl,
to avoid having to convert between using `std::unique_ptr` and
`Catch::Detail::unique_ptr`. This will likely also improve the compile
times of the implementation, but that is less important than improving
compilation times of the user's TUs with tests.
2020-05-31 15:20:24 +02:00
Martin Hořeňovský 41bbaa6d57
Implement a simplified variant of std::unique_ptr<T>
This simplified variant supports only a subset of the functionality
in `std::unique_ptr<T>`. `Catch::Detail::unique_ptr<T>` only supports
single element pointer (no array support) with default deleter.

By removing the support for custom deleters, we also avoid requiring
significant machinery to support EBO, speeding up instantiations of
`unique_ptr<T>` significantly. Catch2 also currently does not need
to support `unique_ptr<T[]>`, so that is not supported either.
2020-05-31 15:08:47 +02:00
Martin Hořeňovský 66ab942903
Refactor StreamEndStop slightly 2020-05-30 15:44:46 +02:00
Martin Hořeňovský 1356788ea8
Avoid using std::result_of when std::invoke_result is available 2020-05-21 22:58:33 +02:00
Martin Hořeňovský 21d284df34
Session now holds Config in unique_ptr instead of shared_ptr 2020-05-20 20:25:51 +02:00
Martin Hořeňovský 668454b36b
Do not share ownership of Config in RunContext 2020-05-20 20:25:49 +02:00
Martin Hořeňovský 458241cc90
Do not use shared_ptr<Config> when listing things 2020-05-20 20:25:48 +02:00
Martin Hořeňovský fa160cf3f2
Keep reporter pointer around in TestGroup 2020-05-20 20:25:45 +02:00
Martin Hořeňovský a17b9f754a
Remove unused function 2020-05-20 20:25:43 +02:00
Martin Hořeňovský c2852c9944
Remove some uses of std::shared_ptr 2020-05-20 20:25:40 +02:00
Martin Hořeňovský 4394d3ae65
Translate exceptions by const reference instead of plain ref 2020-05-20 08:15:27 +02:00
Martin Hořeňovský 4b2f1da02a
Split CATCH_TRANSLATE_EXCEPTION into its own header
As far as I know, only a few users actually use it, but these changes
allow us to avoid including a surprising amount of code in the main
compilation path.
2020-05-20 08:15:11 +02:00
Martin Hořeňovský 0c6fda6e7d
Cleanup benchmark headers a tiny bit 2020-05-20 08:00:24 +02:00
Martin Hořeňovský bad8b7c866
Fix make_shared used instead of make_unique 2020-05-20 07:15:21 +02:00
Martin Hořeňovský 54882dbb11
Don't include <tuple> everywhere in benchmarks 2020-05-20 07:09:15 +02:00
Martin Hořeňovský b4a61cfd29
Remove superfluous overload of operator== 2020-05-18 21:32:08 +02:00
Martin Hořeňovský d86834e5b5
Push down #include <ostream> to .cpp files 2020-05-18 21:31:41 +02:00
Martin Hořeňovský 39e093021c
Remove some superfluous includes 2020-05-18 20:55:21 +02:00
Martin Hořeňovský 29d4b3768c
Add Wsuggest-override to warning flags 2020-05-13 16:09:34 +02:00
Martin Hořeňovský 03ef6b9f9a
Explicitly default smfs when relevant to avoid Wdeprecated-copy-dtor 2020-05-12 23:56:34 +02:00
Martin Hořeňovský 579dcd1a76
Ignore Wdeprecated for Clara 2020-05-12 23:56:24 +02:00
Martin Hořeňovský eb267b424b
Tap reporter changes 2020-05-12 23:56:23 +02:00
Martin Hořeňovský 2528247351
Delete Capturer's smf
As part of `-Wdeprecated-copy-dtor` sweep, I noticed that Capturer's
copies are defaulted. Given that the class would likely break horribly
in the event of actual copy happening, they are now deleted.
2020-05-12 23:56:08 +02:00
Martin Hořeňovský f56832d3ea
Add Catch2::Catch2 alias for Catch2 CMake target 2020-05-11 20:05:10 +02:00
Martin Hořeňovský 601ca1c670
Refactor some uses of virtual -> override 2020-05-11 16:34:55 +02:00
Martin Hořeňovský a39154e115
Do not explicitly default smfs if all of them are defaulted 2020-05-11 00:00:55 +02:00
Martin Hořeňovský 7c622a79d4
Unvirtual bunch off destructors of simple data classes 2020-05-10 23:57:05 +02:00
Martin Hořeňovský 04cbbb8a4b
Replace getLineOfChars with non-templated, runtime version 2020-05-10 23:52:38 +02:00
Martin Hořeňovský f64487bf70
Move LazyExpr's and MessageInfo's implementation to the combined TU
Some of the implementations were inlined instead.
2020-05-10 20:21:04 +02:00
Martin Hořeňovský 27f1756d8e
Split out LazyExpr into its own header
This enables us to avoid `catch_reporter_bases.hpp` being indirectly
dependent on `catch_tostring.hpp`, cutting apart quite a bit indirect
inclusions.
2020-05-10 20:21:02 +02:00
Martin Hořeňovský 824ffe6525
Inline and default LazyExpression's constructor 2020-05-10 20:20:59 +02:00
Martin Hořeňovský d5e08a4beb
Rename catch_assertionhandler -> catch_assertion_handler 2020-05-10 20:20:56 +02:00
Martin Hořeňovský ed967fd7fc
Split MessageInfo into its own header
This is first step towards splitting apart reporter implementation
and `catch_string.hpp`.
2020-05-10 20:20:52 +02:00
Martin Hořeňovský 7030d7740d
Remove some superfluous includes from reporters 2020-05-10 20:20:47 +02:00
Martin Hořeňovský 7efbc83ae0
Introduce combined TUs for compiling small TUs
This should improve the compilation times by decreasing the number
of TUs compiled, without making overly big TUs that would cause
problems with heavy-tailed compilation times.

There is one "combined TU" for the top level part, and each subpart,
except for Reporters, which currently do not have any trivial TUs.
2020-05-10 15:37:29 +02:00
Martin Hořeňovský 9e498278be
Move StringRef header to internals 2020-05-10 10:09:01 +02:00
Martin Hořeňovský 14533f5bb6
Make Colour's op<< hidden friend 2020-05-10 07:32:40 +02:00
Martin Hořeňovský 895d0a0696
Small improvements for StringRef
* `operator[]` is constexpr
* `operator<<` and `operator+=` are hidden friends
2020-05-10 07:22:11 +02:00
Martin Hořeňovský 094d840efe
Cleanup SourceLineInfo implementation
Special member functions are now implicit, which should make them
both noexcept and constexpr. The `operator<<` has been made into
hidden friend as per best practices.
2020-05-10 06:57:02 +02:00
Martin Hořeňovský a595066ff9
Use internal linkage for float stringification helper 2020-05-10 06:54:23 +02:00
Martin Hořeňovský cb25c4a8a3
Reinline some StringMaker impls 2020-05-09 21:26:42 +02:00
Martin Hořeňovský b93cf932fb
Use UDLs to construct StringRefs for decomposed operators directly 2020-05-09 21:07:55 +02:00
Martin Hořeňovský eef6c9b79b
Microopt: stream single char instead of single char string 2020-05-09 21:02:12 +02:00
Martin Hořeňovský b5a287f09f
Make rest of the generators final 2020-05-09 20:56:25 +02:00
Martin Hořeňovský e1a0cce82b
Remove Clara from external folder
As Clara is no longer maintained as a separate project, the
implementation was moved to the internal subfolder of top-level
folder. This removes one folder and avoids potential user confusion.

Also simplified the convenience header checking script accordingly.
2020-05-09 19:40:57 +02:00
Martin Hořeňovský 75b711a360
Fix ODR violation because of name clash in matchers 2020-05-09 18:00:51 +02:00
Martin Hořeňovský db32550898
Remove catch_default_main.hpp
There are two reasons for this:

1) It is highly unlikely that someone has use for this header,
which has no customization points and only provides simplest
possible main, and cannot link the static library which also
provides a default main implementation.
2) It being a header was causing extra complications with
the convenience headers, and our checking script. This would either
require special handling in the checking script, or would break user's
of the main convenience header.

All in all, it is simpler and better in the long term to remove it,
than to fix its problems.
2020-05-09 18:00:49 +02:00
Martin Hořeňovský e78b4f6be7
Remove file list checking from CMake
I do not think we need a safeguard against not including files in
CMake anymore, and as it is, it caused annoying false positive about
the default main implementation.
2020-05-06 21:23:13 +02:00
Martin Hořeňovský 6020f8f27c
Add convenience headers that include all headers in a subpart
The naming scheme is simple, to include all matchers, include header
`catch2/matchers/catch_matchers_all.hpp`. To include **everything**,
include `catch2/catch_all.hpp`.
2020-05-06 11:21:46 +02:00
Martin Hořeňovský 19ecad6f68
Rename CMake/pkg-config target Catch2Main to Catch2WithMain
This describes the reality better, as it also links in the rest
of Catch2.

The on-disk name of the static library remains just `Catch2Main`,
as that is what it is -- single main function -- and on-disk artifacts
cannot describe link dependencies.
2020-05-03 18:54:38 +02:00
Martin Hořeňovský 5b8cccaf6a
Add support for bitwise xor to the decomposer 2020-05-03 07:52:47 +02:00
Martin Hořeňovský 53434a2f32
Support bitand and bitor in REQUIRE/CHECK
This means that bit-flag-like types with conversion to bool can be
asserted on, like so `REQUIRE(var & Flags::AddNewline)`.
2020-05-03 07:45:04 +02:00
schallerr 2a93a65bc2
Support custom allocators in vector Matchers (#1909)
-- Combined with f4fc2dab2c
   during cherry-picking.
2020-05-03 07:40:04 +02:00
Martin Hořeňovský bbbc7a0d7f
Fix CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTION interaction with feature macro 2020-05-01 20:26:40 +02:00
John Else 1bd7cac09f
Use macro to determine whether std::uncaught_exceptions is available
Catch assumes std::uncaught_exceptions is available whenever C++17 is
available, but for macOS versions older than 10.12 this is not the case.

Instead of checking the C++ version, use a macro to check whether the
feature is available.
2020-05-01 14:45:56 +02:00
John Bytheway 26b2c3e7e2
Change random test shuffling technique (refactored)
Previously a random test ordering was obtained by applying std::shuffle
to the tests in declaration order.  This has two problems:

- It depends on the declaration order, so the order in which the tests
  will be run will be platform-specific.
- When trying to debug accidental inter-test dependencies, it is helpful
  to be able to find a minimal subset of tests which exhibits the issue.
  However, any change to the set of tests being run will completely
  change the test ordering, making it difficult or impossible to reduce
  the set of tests being run in any reasonably efficient manner.

Therefore, change the randomization approach to resolve both these
issues.

Generate a random value based on the user-provided RNG seed.  Convert
every test case to an integer by hashing a combination of that value
with the test name.  Sort the test cases by this integer.

The test names and RNG are platform-independent, so this should be
consistent across platforms.  Also, removing one test does not change
the integer value associated with the remaining tests, so they remain in
the same order.

To hash, use the FNV-1a hash, except with the basis being our randomly
selected value rather than the fixed basis set in the algorithm.  Cannot
use std::hash, because it is important that the result be
platform-independent.
2020-05-01 12:32:38 +02:00
Martin Hořeňovský 87a8b61d5a
Fix bug in test spec parser handling of escaping in ORed patterns
It did not clear out all of its internal state when switching from
one pattern to another, so when it should've escaped `,`, it took
its position from its position in the original user-provided string,
rather than its position in the current pattern.

Fixes #1905
2020-05-01 09:56:34 +02:00
Andrew Gaspar ca27b0dcc5
Remove usage of __builtin_constant_p under IBM XL 2020-05-01 09:31:59 +02:00
Moritz Haase 87c8055176
Suppress clang-tidy warning about vararg usage in assertion macros
CATCH_INTERNAL_IGNORE_BUT_WARN() introduced with b7b346c triggers
clang-tidy warning 'cppcoreguidelines-pro-type-vararg' for every usage
of assertion macros like CHECK() and REQUIRE(). Silence it via NOLINT
in the '#if defined(__clang__)' block only, as clang-tidy honors those.
2020-05-01 09:31:48 +02:00
pi1024e 02a998598c
C-header updates 2020-05-01 09:30:50 +02:00
Joel Uckelman beb8c3a99d
Fixed typo in "benchmark name" column width calculation. Closes #1885. 2020-05-01 09:30:17 +02:00
Martin Hořeňovský 5198fd3c9a
Fix compilation error when lambdas are used in assertions
This is a partial revert of b7b346c3e5.
2020-05-01 09:24:26 +02:00
Martin Hořeňovský 95a2e54702
Different approach to proper colouring of filters 2020-04-29 21:28:25 +02:00
Till Hofmann 6badd7d9ed
Switch back to uncolored output after printing filters
After printing the list of filters, switch back from yellow to black
before printing a newline to avoid the remaining output to be colored in
yellow.
2020-04-29 21:28:18 +02:00
Martin Hořeňovský 60cfaa38fb
Make warnings in assertions fire for GCC/Clang again
The old code caused warnings to fire under MSVC, and Clang <3.8.
I could not find a GCC version where it worked, but I assume that it
did at some point.

This new code causes all of MSVC, GCC, Clang, in current versions,
to emit signed/unsigned comparison warning in test like this:

```cpp
TEST_CASE() {
    int32_t i = -1;
    uint32_t j = 1;
    REQUIRE(i != j);
}
```

Where previously only MSVC would emit the warning.

Fixes #1880
2020-04-29 21:27:57 +02:00
khyperia efbfaa1704
Don't cast nanoseconds to integers when writing output 2020-04-29 16:54:46 +02:00
khyperia c4e5b05cfc
include <iterator> in catch_stats.hpp
needed for std::back_inserter on some platforms
2020-04-29 16:54:39 +02:00
Martin Hořeňovský 0fdeb10c65
Cleanup how configuration-dependent test macros are defined 2020-04-29 15:36:40 +02:00
Martin Hořeňovský 783ab5ef87
Move around message macros and implementation 2020-04-29 14:02:53 +02:00
Martin Hořeňovský 8d50f04419
Move around matcher macro implementation 2020-04-26 21:33:55 +02:00
Martin Hořeňovský 804e2df099
Move Benchmarking macros to catch_benchmark.hpp 2020-04-26 19:24:36 +02:00
Martin Hořeňovský 0470794a68
Split TEMPLATE_TEST* macros into their own set of files
These files are not included by the default
`#include <catch2/catch_test_macros.hpp>` path, so that users do
not have to pay for them if they do not use them. Follow up is to
split out the small part of `catch_preprocessor.hpp` used by the
default test macros (AFAIK, it is just `INTERNAL_CATCH_REMOVE_PARENS`
macro), so that it is not included by the default path either.

Also fixes #1892 by providing the missing macros.
2020-04-26 16:25:43 +02:00
Martin Hořeňovský 5150fa4476
Rename catch_capture.hpp to more descriptive catch_test_macro_impl.hpp 2020-04-26 13:32:17 +02:00
Martin Hořeňovský c078373f3f
Rename internal macro for suppression of unused variable warnings 2020-04-25 18:13:17 +02:00
Martin Hořeňovský 517839fb3f
Small cleanup of fatal condition handler 2020-04-25 14:07:50 +02:00
Martin Hořeňovský c5ec936a72
Inline TagAlias constructor
It is trivial enough that the function call is not worth it, and
lets us remove one TU from compilation.
2020-04-24 21:09:10 +02:00
Martin Hořeňovský 8d44c2450c
Add some explanatory comments to ErrnoGuard 2020-04-24 21:04:54 +02:00
Martin Hořeňovský 7c97554565
Remove Obj-C(++) support 2020-04-24 20:42:52 +02:00