Commit Graph

155 Commits

Author SHA1 Message Date
Martin Hořeňovský
3a33315ff8
Fix compilation error when lambdas are used in assertions
This is a partial revert of b7b346c3e5.
2020-03-19 13:32:45 +01:00
Martin Hořeňovský
b7b346c3e5
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-03-19 09:45:41 +01:00
Martin Hořeňovský
849f2848bd
Rework how warning suppression in macros is done
Previously, each warning suppression was self-contained, with its
own pair of `SUPPRESS_X_WARNING` and `UNSUPPRESS_X_WARNING` macros.
This had the obvious advantage of being self-containing, but it
also meant that if we needed to suppress more than one warning
in a single place, then we would manipulate the compiler's warning
state multiple times, even though logically we would only need one
layer.

The new way of suppressing warnings in macros is to push compiler's
warning state with `CATCH_INTERNAL_START_WARNINGS_SUPPRESSION` macro,
then disable whatever macros we need with the
`CATCH_INTERNAL_SUPPRESS_X_WARNINGS` macro, and then return to the
previous state using `CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION`.
2019-10-27 21:07:21 +01:00
Omer Ozarslan
99575b45db Add unscoped info functionality
This adds UNSCOPED_INFO macro, creating a log message that is stored
until the end of next assertion or the end of test case, whichever comes
first. These messages are not scoped locally, unlike messages created by
INFO macro.
2019-03-06 22:04:35 +01:00
Paul Lesur
2bd0722470 fix "code will never be executed" under clang 2019-02-18 19:01:43 +01:00
Martin Hořeňovský
8b01883854 Add support for -fno-exceptions (or equivalent)
This means

* Adding new configuration toggle `CATCH_CONFIG_DISABLE_EXCEPTIONS`
and a best-guess configuration auto-checking for it.
* Adding new set of internal macros, `CATCH_TRY`, `CATCH_CATCH_ALL`
and `CATCH_CATCH_ANON` that can be used in place of regular `try`,
`catch(...)` and `catch(T const&)` respectively, while disappearing
when `CATCH_CONFIG_DISABLE_EXCEPTIONS` is enabled.
* Replacing all uses of `throw` with calls to `Catch::throw_exception`
customization point.
* Providing a default implementation for the above customization point
when `CATCH_CONFIG_DISABLE_EXCEPTIONS` is set.
* Letting users override this implementation with their own.
* Some minor changes and ifdefs all around to support the above
2018-09-03 21:08:27 +02:00
Phil Nash
1cdaa48a0b CAPTURE is now variadic 2018-08-19 22:40:20 +02:00
Martin Hořeňovský
83bfae1a50 Construct StringRef from constant strings in macros directly using UDL
This avoids having to call `strlen` to get the constant string's length
and thus should improve performance.
2018-07-23 14:00:45 +02:00
Martin Hořeňovský
82b8744b8c Direct construct empty StringRef in test macros 2018-07-22 14:13:34 +02:00
Phil Nash
3035120dc7 Some bits of tidy up 2017-12-07 00:02:32 +00:00
Phil Nash
5461242ffe Renamed last usge specific handle method (and made the low level ones private) 2017-11-27 22:23:15 +03:00
Phil Nash
db44964e27 Refactored most handle() calls to more specific/ descriptive calls 2017-11-26 21:28:43 +00:00
Phil Nash
2800adba25 Qualified handleExceptionMatchExpr in Catch::
(was picking it up by ADL before - no need to rely on that!)
2017-11-26 21:28:43 +00:00
Phil Nash
9329d97a43 Always debug-break non-inline 2017-11-23 19:14:26 +00:00
Phil Nash
5323202652 Bake exception guard into assertion handler flow 2017-11-23 16:52:46 +00:00
Martin Hořeňovský
401ad7a189 Remove isTrue, alwaysTrue, alwaysFalse
isTrue and alwaysFalse were replaced by (void)0, 0 inspired by doctest
alwaysTrue was replaced by warning suppression
2017-11-22 16:03:45 +01:00
Phil Nash
3b965aa501 (re)Inlined isTrue() 2017-11-21 13:12:22 +00:00
Martin Hořeňovský
49a1408ff2 Fix compilation of main file with CATCH_CONFIG_FAST_COMPILE 2017-08-30 18:07:29 +02:00
Martin Hořeňovský
053c29a2b8 Add partial implementation of CATCH_CONFIG_DISABLE
* Assertions are defined into (void)(0) no-op
* SECTIONs are defined away (leaving {} as scope)
* TEST_CASEs and TEST_CASE_METHODs are not registered.
* REGISTER_TEST_CASE is defined into (void)(0) no-op
* METHOD_AS_TEST_CASE is defined away
2017-08-27 22:05:25 +02:00
Martin Hořeňovský
e8d3be3621 Workaround raw string literal bug in VS2017 2017-08-27 12:38:59 +02:00
Phil Nash
ece64c3b3a Removed redundant .c_str()s from StringRef usages 2017-08-14 08:54:57 +01:00
Phil Nash
ee9b19efd3 Moved matcher-based capture macros into their own file
- this file excluded from the CATCH_CONFIG_DISABLE_MATCHERS path.
- matchers are always compiled in to the impl file
- _THROWS_WITH macros are still available with matchers disabled - but only the ones that take a string
- tests that use matchers have #ifdefs, so the whole SelfTest project can compile with matchers disable.
2017-08-09 12:10:14 +01:00
Phil Nash
b59e0ed48a Collapsed alternate capture macros now originals are redundant 2017-08-09 11:36:33 +01:00
Phil Nash
8d21b4a916 Removed some unnecessary #includes
- and don't #include "catch_debugger.h" in the header path when CATCH_CONFIG_FAST_COMPILE is defined
2017-08-09 10:51:50 +01:00
Phil Nash
8c95a81448 Removed all (well, most) of the redundant, ResultBuilder-based, code 2017-08-09 09:08:33 +01:00
Phil Nash
201028d6ec Integrated INTERNAL_CATCH_THROWS with new AssertionHandler 2017-08-09 00:52:20 +01:00
Phil Nash
27fd8f80bd Integrated INTERNAL_CATCH_THROWS_STR_MATCHES with new AssertionHandler 2017-08-09 00:44:30 +01:00
Phil Nash
ef4fa56b71 integrated INTERNAL_CATCH_THROWS_MATCHES with new AssertionHandler 2017-08-08 23:41:55 +01:00
Phil Nash
9668410b8e integrated INTERNAL_CHECK_THAT with new AssertionHandler 2017-08-08 23:31:43 +01:00
Phil Nash
2832e23aa9 Restored exceptionGuard functionality under CATCH_CONFIG_FAST_COMPILE 2017-08-08 21:07:30 +01:00
Phil Nash
5f91724368 integrated AssertionHandler into INTERNAL_CATCH_MSG 2017-08-08 20:17:09 +01:00
Phil Nash
8a97beece2 integrated AssertionHandler into INTERNAL_CATCH_THROWS_AS 2017-08-08 19:43:07 +01:00
Phil Nash
f033f4f184 integrated AssertionHandler into INTERNAL_CATCH_NO_THROW 2017-08-08 19:36:18 +01:00
Phil Nash
f247ce5bff First cut of new AssertionHandler/ Decomposer
- integrated into INTERNAL_CATCH_TEST. Needs more work to fully replace existing stuff
2017-08-08 17:53:01 +01:00
Phil Nash
e658bacb04 Refactored how FAST_COMPILE affects internal test macros (less duplication) 2017-08-07 00:09:54 +01:00
Neal Coombes
2212cdfe26 Eliminate some work when results won't be reported. 2017-08-01 22:49:27 +02:00
Martin Hořeňovský
d08e31d89e Fix inverted CATCH_CONFIG_DISABLE_MATCHERS toggle 2017-07-29 08:43:32 +02:00
Martin Hořeňovský
0ca4cfb743 Introduce compile time toggle to remove Matchers from TU
The toggle is `CATCH_CONFIG_DISABLE_MATCHERS` and the only use is
to speed up compilation of small TUs. For large ones it is likely
insignificant, because the speed up is constant relative to
number of tests/assertions in TU.
2017-07-28 21:34:34 +02:00
Martin Hořeňovský
efd79aa0bd Extend exception type in _THROWS_ with const& unconditionally
Potentially breaking change, but most people apparently were using it
wrong and thus it won't be breaking for them.

Closes #955
2017-07-19 21:30:00 +02:00
Martin Hořeňovský
fae0fa4ec1 Merge branch 'dev-second-string-argument-removal' into dev-modernize
It is no longer true that an assertion macro has either 1 or 2 args,
so...
2017-06-26 20:48:41 +02:00
Phil Nash
059a33d555 Fixed indentation 2017-06-26 16:47:40 +01:00
Martin Hořeňovský
0eb101e165 Remove "second argument" from result builder and assertion result
This is not quite complete removal (it doesn't pass approval tests),
but it should be representative of full perf improvements from doing so
2017-06-22 18:13:05 +02:00
Martin Hořeňovský
6583284731 Fix erroneous result disposition for {REQUIRE,CHECK}_THAT
This fixes result disposition being ContinueOnFailure |
ContinueOnFailure for CHECK_THAT (obviously an error) and Normal |
ContinueOnFailure for REQUIRE_THAT (less obviously an error, but worse,
as that signals to the pipeline that assertion failure should both abort
and continue the test with ???? happening).
2017-06-06 15:12:03 +02:00
Martin Hořeňovský
950cae9040 Added new assertion macros: *_THROWS_WITH
It combines `*_THROWS_AS` and `*_THROWS_WITH` macros, so that the
exception type matches expectetations and its contents match a specific
matcher.
2017-06-05 18:40:50 +02:00
Martin Hořeňovský
377c9a746d Cosmetic fixes (whitespace and spelling) 2017-05-27 14:42:54 +02:00
Martin Hořeňovský
a9128d0fac More macros are now variadic
Also added tests for them
2017-05-03 19:10:27 +02:00
Martin Hořeňovský
5ffc8a84cd Fix order of arguments in CATCH_FAIL and nonvariadic INTERNAL_CATCH_MSG
Fixes #896
2017-04-28 18:30:04 +02:00
Phil Nash
d17d94e45d Made INTERNAL_CATCH_TEST variadic so commas in assertions work 2017-04-26 16:10:18 +01:00
Martin Hořeňovský
71df66365e Gutted catch_compiler_capabilities
All C++11 toggles are now removed. What is left is either platform
specific (POSIX_SIGNALS, WINDOWS_SEH), or possibly still needed
(USE_COUNTER).

If current CLion is compatible with `__COUNTER__`, then we should also
force `__COUNTER__` usage.

Changed
* CATCH_AUTO_PTR    -> std::unique_ptr
* CATCH_OVERRIDE    -> override
* CATCH_NULL        -> nullptr
* CATCH_NOEXCEPT    -> noexcept
* CATCH_NOEXCEPT_IS -> noexcept

Removed
* CATCH_CONFIG_CPP11_UNIQUE_PTR
* CATCH_CONFIG_CPP11_SHUFFLE
* CATCH_CONFIG_CPP11_TYPE_TRAITS
* CATCH_CONFIG_CPP11_OVERRIDE
* CATCH_CONFIG_CPP11_LONG_LONG
* CATCH_CONFIG_CPP11_TUPLE
* CATCH_CONFIG_CPP11_IS_ENUM
* CATCH_CONFIG_CPP11_GENERATED_METHODS
* CATCH_CONFIG_CPP11_NOEXCEPT
* CATCH_CONFIG_CPP11_NULLPTR
* CATCH_CONFIG_VARIADIC_MACROS
2017-04-25 12:43:19 +02:00
Martin Hořeňovský
4fe2432e05 Rework of REQUIRE* changes in CATCH_CONFIG_FAST_COMPILE
`ResultBuilder`s destructor now checks for exceptions, preventing false
negatives. The speedup should remain the same give or take a tiny bit.
2017-03-29 21:12:06 +02:00