Compare commits

..

148 Commits

Author SHA1 Message Date
Jozef Grajciar
87b745da66 v2.10.2 2019-10-24 18:41:25 +02:00
Martin Hořeňovský
7d0b205564 Prevent warning suppression from leaking when registering a listener 2019-10-22 00:10:01 +02:00
Martin Hostettler
8fb1219013 docs: command-line: Add example to specify tests by file name. 2019-10-21 23:51:33 +02:00
Martin Hořeňovský
23c80bcc92 Provide workaround for platforms where INFINITY is double
Fixes #1782
2019-10-21 18:33:26 +02:00
Martin Hořeňovský
a2c8dce85c v2.10.1 2019-10-20 21:03:22 +02:00
Martin Hořeňovský
1e379de9d7 Fix "ldd" -> "lld" typo in docs 2019-10-20 20:57:55 +02:00
Martin Hořeňovský
4eea438b73 Update updateWandbox script to account for the new Wandbox API response 2019-10-20 20:56:20 +02:00
Martin Hořeňovský
407ee0af2f Add a section on slow linking under MinGW to "Known Limitations" docs
Unless someone steps up to fix the long link times with a set of
unobtrusive changes, the recommended solution will remain "use a better
linker".

Related to #1205, #1247, and #1637

Closes #1247
Closes #1637
2019-10-20 19:52:39 +02:00
Jonathan Vander Mey
060a41ec7b Suppress false positive from clang-analyzer
Fixes issue #1230
2019-10-20 17:27:09 +02:00
Martin Hořeňovský
90825a4f7a Add more tests for reading test specs from file
Related to #1770
2019-10-20 15:14:50 +02:00
Martin Hořeňovský
9e8ae7d470 Use scientific notation for the WithinULP matcher
This should now properly handle small numbers which would previously
output something like `[0.00000000000000019, 0.00000000000000019]`,
which does not allow user to read the numbers properly.

Closes #1760
2019-10-20 12:30:21 +02:00
amitherman95
84856844e1 Fixes #1766: Catch terminates when parsing invalid test name 2019-10-19 21:14:06 +02:00
Martin Hořeňovský
01ef7076f5 Allow in-tree builds where Catch2 is just a subproject
Closes #1773
Closes #1774
2019-10-18 18:49:44 +02:00
Jozef Grajciar
ae14a47360 TemplateTests: suppress -Wunused-template warning in template test cases
this warning was introduced by rework to support NTTPs
since we have implementation macro for NTTPs and normal template test cases
warning is going to be suppressed

Fixes #1762
2019-10-18 18:38:39 +02:00
Jozef Grajciar
f2b23db6d1 TemplateTests: fix compilation with ICC
ICC in some cases fails on trailing return type with decltype

Closes #1748
2019-10-18 12:35:09 +02:00
Mertz, Arne
1aa98c76ac add a note how to run selftests using multiconfig generators 2019-10-17 20:23:51 +02:00
data-man
3195c242c2 Remove JSON library from users 2019-10-17 20:20:02 +02:00
Martin Hořeňovský
31906d83ec Add parenthesis to prevent macro expansions of min/max
Closes #1772
2019-10-17 16:40:37 +02:00
Martin Hořeňovský
91fa55303b Add test for including unguarded windows.h
If you do this, you are wrong, but apparently people expect libraries
to work around intrusive lower cased macros. Oh well.
2019-10-17 11:15:42 +02:00
Martin Hořeňovský
7c9f92bc1c v2.10.0 2019-10-13 23:44:18 +02:00
Martin Hořeňovský
a92a7d0229 Rewrite documentation for floating point matchers 2019-10-13 21:31:48 +02:00
Martin Hořeňovský
e4d61e4cd8 Fix baselines 2019-10-13 21:26:51 +02:00
Martin Hořeňovský
9ba48e2c9b Remove superfluous includes in exception matchers 2019-10-13 20:49:36 +02:00
Martin Hořeňovský
2cc0c71856 Add a matcher that checks exception's message
Only works for exceptions that publicly derive from `std::exception`
and the matching is done exactly, including case and whitespace.

Closes #1649
Closes #1728

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
# Changes to be committed:
#	modified:   ../docs/matchers.md
#	modified:   ../include/internal/catch_capture_matchers.h
#	modified:   ../projects/CMakeLists.txt
#	modified:   ../projects/SelfTest/Baselines/compact.sw.approved.txt
#	modified:   ../projects/SelfTest/Baselines/console.std.approved.txt
#	modified:   ../projects/SelfTest/Baselines/console.sw.approved.txt
#	modified:   ../projects/SelfTest/Baselines/junit.sw.approved.txt
#	modified:   ../projects/SelfTest/Baselines/xml.sw.approved.txt
#	modified:   ../projects/SelfTest/UsageTests/Matchers.tests.cpp
#
# Untracked files:
#	./
#	../clang-full/
#	../clang-test/
#	../clang10-build/
#	../coverage-build/
#	../gcc-build/
#	../gcc-full/
#	../include/internal/catch_matchers_exception.cpp
#	../include/internal/catch_matchers_exception.hpp
#	../misc-build/
#	../msvc-sln/
#	../notes.txt
#	../test-install/
#
2019-10-13 20:37:07 +02:00
Martin Hořeňovský
28663fb959 Use the right overload of std::nextafter in tests 2019-10-13 13:36:22 +02:00
Martin Hořeňovský
d2d418a9cb Add a Relative Comparison matcher for floating point numbers
It checks Knuth's _close enough with tolerance_ relationship, that
is `|lhs - rhs| <= epsilon * max(|lhs|, |rhs|)`, rather then the
_very close with tolerance_ relationship that can be written down as
`|lhs - rhs| <= epsilon * min(|lhs|, |rhs|)`.

This is because it is the more common model around the internet, and
as such is likely to be less surprising to the users. In the future
we might want to provide the other model as well.

Closes #1746
2019-10-13 11:56:50 +02:00
Martin Hořeňovský
c8db4e77c4 Add a from_range(Container) overload to the generator helpers 2019-10-09 14:51:36 +02:00
Martin Hořeňovský
1c5749669e Merge pull request #1769 from amitherman95/amitherman-1767
Patch:Failure to pass special chars through input file
2019-10-09 14:16:50 +02:00
Martin Hořeňovský
3109add95c Add tests for the -f/--input-file command line argument 2019-10-09 12:54:13 +02:00
amitherman95
adb4789136 Patch:Failure to apply filters through external file 2019-10-09 11:43:06 +02:00
Martin Hořeňovský
75200e199e Merge pull request #1768 from RT222/master
Simplified benchmark output with --benchmark-no-analysis
2019-10-08 21:07:35 +02:00
Martin Hořeňovský
a5a22cdadb Have the random generators use the global rng instance
This means that if you nest multiple random generators inside one
test case, they will not return the same sequence of numbers.

Idea taken from #1736 by Amit Herman.

Closes #1736
Closes #1734
2019-10-07 21:53:07 +02:00
Martin Hořeňovský
535da5c513 Introduce Catch's own RNG based on the PCG family of RNGs
In the future, we will also want to introduce our own
`uniform_int_distribution` and `uniform_real_distribution` to get
repeatable test runs across different platforms.
2019-10-07 19:56:23 +02:00
RT222
2331249a8d Simplified benchmark output with --benchmark-no-analysis
Removed unused informations from benchmarks output when the --benchmark-no-analysis flag is used, making the results easier to read.
2019-10-07 15:40:00 +02:00
Martin Hořeňovský
319cb9e1da Add a generator that takes an iterator pair 2019-10-06 13:55:10 +02:00
Martin Hořeňovský
b8b765d55e Merge pull request #1765 from kevingranade/patch-1
Add Cataclysm:Dark Days Ahead to project list
2019-10-06 12:41:46 +02:00
Kevin Granade
a0ebd63806 Add Cataclysm:Dark Days Ahead to project list 2019-10-05 20:18:31 -07:00
Martin Hořeňovský
4bd2c3ad6a Fix compilation error with CATCH_CONFIG_GLOBAL_NEXTAFTER
Wrong nesting of namespaces resulted in the `Catch` namespace
being ambigous between `::Catch` and `::{anon}::Catch` namespaces.
This should fix it.

Closes #1761
2019-10-05 21:03:46 +02:00
Martin Hořeňovský
c38a5caa2e Allow full range of target ULP values for the ULPMatcher
Previously it was limited to roughly 2 billion ULPs, rather than
the roughly 2^64 possible ones.
2019-10-05 13:38:22 +02:00
Martin Hořeňovský
ebc5609484 Add test for INF == Approx(1) 2019-10-04 14:19:39 +02:00
Wim Leflere
fcda35f645 update name of Value Generators in doc to match class names 2019-10-04 13:31:37 +02:00
Martin Hořeňovský
02ee130bd0 Special case Approx(inf) to better follow user expectations 2019-10-04 13:28:43 +02:00
Martin Hořeňovský
815f99541d Do not explicitly install conan
Instead, let it be installed as a dependency of `conan-package-tools`
to avoid trouble with the fact that pip is really bad at version
resolution, and that up-to-date version of the `conan` package is not
supported by up-to-date version of the `conan-package-tools` package.
2019-10-03 00:00:17 +02:00
Martin Hořeňovský
da0062f7c1 Merge pull request #1752 from amitherman95/amitherman-1737
Escape characters bug patch(v2.9.2)
2019-09-22 10:48:08 +02:00
Martin Hořeňovský
de42f8a93e Fix escaping of quotes in coverage helper 2019-09-21 23:19:45 +02:00
Martin Hořeňovský
af84f1350e Add documentation for the table generator helper 2019-09-21 01:00:53 +02:00
Martin Hořeňovský
fc2066bf18 Add tests for escaping special characters in CLI 2019-09-21 00:50:17 +02:00
amitherman95
2bcff9dd35 Escape characters bug patch(v2.9.2) 2019-09-21 00:46:58 +02:00
Martin Hořeňovský
3beccfb429 Remove the no longer used is_unique type trait
It was used in checking that types in TEMPLATE_TEST_CASE and friends
were unique, but this was removed for v2.8.0 (#1628). Since there
are no further uses of this trait, the simplest thing to do is to
just remove it.

Fixes #1757
2019-09-20 23:28:19 +02:00
Martin Hořeňovský
af8b2538a6 Ignore leading/trailing whitespace in test/section specs
The leading/trailing whitespace is problematic because of e.g.
`WHEN` macro having preceeding whitespace for alignment, and it is
generally messy.

Credits to Phil who did lot of the original work.

Closes #1708
2019-09-09 14:28:11 +02:00
Martin Hořeňovský
a156440b19 Reinline some StringRef methods with trivial bodies 2019-09-08 21:08:37 +02:00
Martin Hořeňovský
dab0296b64 Add test for past-the-end substr on StringRef 2019-09-08 21:07:21 +02:00
Martin Hořeňovský
9f4c4777a5 Remove (mostly) unused overloads of StringRef operator + 2019-09-08 21:01:33 +02:00
Martin Hořeňovský
293012a002 Inline SourceLineInfo::empty definition 2019-09-08 18:20:49 +02:00
Martin Hořeňovský
e2b3443fe7 Do not blindly access empty StringRefs 2019-09-08 17:44:56 +02:00
Martin Hořeňovský
7b865daccc Make StringRef's operator std::string explicit
This way it is explicit when there is a `StringRef` -> `std::string`
conversion and makes it easier to look for allocations that could
be avoided.

Doing this has already removed one allocation per registered test
case, as there was a completely pointless `StringRef` -> `std::string`
conversion when parsing tags of a test case.
2019-09-08 15:58:10 +02:00
Martin Hořeňovský
14362533bb Check for empty expression properly
The old code was a left-over from the times when the
`capturedExpression` member was a `const char*`, which could always
be indexed. With the change to use `StringRef`, blindly indexing 0th
element is invalid, as it is not indexable part of a StringRef.
2019-09-08 14:35:01 +02:00
Matthias Moulin
a5bb3e3d91 Small updates to include directives (#1726)
Fixed some inconsistencies in include directives.
2019-09-08 14:25:23 +02:00
Martin Hořeňovský
923db16322 Use StringRefs through the enum registration 2019-09-08 14:14:46 +02:00
Martin Hořeňovský
fbbaadb704 Use StringRef literal for unknown enum values instead of string lit 2019-09-08 14:14:14 +02:00
Martin Hořeňovský
dd1f0f1c72 Add test for --filename-as-tags 2019-09-07 20:43:14 +02:00
Martin Hořeňovský
d27d580d0b Add test for --libidentify command line flag 2019-09-07 20:36:12 +02:00
Martin Hořeňovský
6da00c1b64 Split out the rest of string manipulation tests 2019-09-07 20:22:36 +02:00
Martin Hořeňovský
fe967b1f41 Remove the ill-considered StringRef::numberOfCharacters
It never counted characters, only codepoints. If you think these
are interchangeable, you should not touch non-ascii text.
2019-09-07 20:13:22 +02:00
Martin Hořeňovský
f2c2711bdc Add trim for StringRef 2019-09-07 11:31:00 +02:00
Martin Hořeňovský
b77ab74b72 Start adding tests for string manip functions 2019-09-06 18:50:57 +02:00
Martin Hořeňovský
4038ee6bc6 Stop compilation if registering an enum could truncate its value
We probably want to use a bigger type (e.g. `int64_t`) later on,
but the is a mess right now anyway.
2019-09-06 18:36:59 +02:00
Martin Hořeňovský
789f3591ef Do not write singular characters into stream as C-strings 2019-09-06 18:30:16 +02:00
Martin Hořeňovský
6e8d769775 Unify handling of __has_include checks 2019-09-06 13:38:58 +02:00
Martin Hořeňovský
1189a73be2 Do not assume that version placeholders contain ")" 2019-09-06 13:25:39 +02:00
Martin Hořeňovský
071bacad5e Properly linkthrough additions to the configuration docs 2019-09-06 13:24:51 +02:00
Martin Hořeňovský
addf799040 Workaround missing std::nextafter in uClibc
Luckily, the rest of C++11 features seem to be supported...

Closes #1739
2019-09-06 13:08:44 +02:00
Martin Hořeňovský
155274f0df Add disabling the use of Android's logging at compile time
This is done via the new compile time toggle,
`CATCH_CONFIG_ANDROID_LOGWRITE`.

Closes #1743
2019-09-06 12:44:06 +02:00
Benjamin Worpitz
18d597cf10 Allow to use non-copyable and non-movable types in TEMPLATE_LIST_TEST_CASE
The parameter given to `convert` may not be copyable therefore it has to be
captured by const reference. For example an `std::tuple` that contains a
non-copyable type is itself non-copyable.

The NonDefaultConstructible test-case was reduced by one example type
because it did not add any value.
2019-09-06 12:15:09 +02:00
Martin Hořeňovský
6629c11ef8 Optimize in-repo PNGs 2019-09-06 12:12:47 +02:00
Martin Hořeňovský
c6bf56b3d5 Fix Travis builds with clang 5/6
There is some weird broken dependency in their version of Trusty
(14.04 LTE), so we are using Xenial (16.04 LTE) instead.
2019-09-06 12:07:29 +02:00
Martin Hořeňovský
623e348d9e Merge pull request #1744 from ux3d/add-ux3d-to-commercial-users
add UX3D to commercial users
2019-09-06 11:37:55 +02:00
Benjamin Schmithüsen
46f767e602 add UX3D to commercial users 2019-09-06 11:27:33 +02:00
Martin Hořeňovský
ce42deb72f Add Android's log library to Catch2's CMake interface 2019-08-10 20:51:15 +02:00
Martin Hořeňovský
46a70071a7 Use __android_log_write instead of __android_log_print
`print` version of the logging functions supports `printf`-like
formatting, which we do not use and given our current debug print
internals, will never use. This should be slightly more efficient
and expresses the intent better.
2019-08-10 14:51:38 +02:00
Jesse Alas
378cc1a670 Rename template parameter names to avoid name conflict on Solaris.
Closes #1722
2019-08-10 10:55:17 +02:00
Martin Hořeňovský
e2d863b090 Actually run the random generator tests 2019-08-09 11:21:05 +02:00
Martin Hořeňovský
ebe6a07c23 Remove the new tests from approvals
They lead to stringification of file (which is ok) and file line
(not ok) to the approvals, which makes them exceedingly brittle
and not worth approval testing. Instead we just run them as part
of the base test run.
2019-08-09 11:13:28 +02:00
Martin Hořeňovský
edcfd7fc62 Add missed item to v2.9.2 release notes 2019-08-09 10:57:59 +02:00
Martin Hořeňovský
738818ae1d Add a test for the internals 2019-08-09 10:50:53 +02:00
Martin Hořeňovský
2c869e17e4 v2.9.2 2019-08-08 14:05:24 +02:00
Martin Hořeňovský
0ab11aa9b4 (Hopefully) Fix Obj-C++ compilation of matchers
Thanks to bdb for the patch, related to #1661
2019-08-07 20:35:27 +02:00
Martin Hořeňovský
7a6af7ba76 Merge pull request #1717 from ax3l/fix-storageClassFirst
static constexpr: storage class first
2019-08-07 09:23:47 +02:00
Martin Hořeňovský
fa096b26d1 Merge pull request #1715 from sfranzen/fix-compact-reporter
Fix infinite loop in compact reporter printer
2019-08-07 09:12:38 +02:00
Axel Huebl
820b1f12bf static constexpr: storage class first
Seen with PGI compiler for `static constexpr`:
```
warning: storage class is not first
```
2019-08-06 19:17:16 -05:00
Steven Franzen
6070745cab Improve reporting of unmatched filters (#1684)
This PR ultimately does 3 things
* Separately tracks matched tests per each filter part (that is, a set of filters separated by an OR (`,`)), which allows Catch2 to report each of the alternative filters that don't match any tests.
* Fixes `-w NoTests` to return non-zero in the process
* Adds tests for `-w NoTests`.
2019-08-06 20:51:19 +02:00
Steven Franzen
3d9e7db2e0 Fix infinite loop in compact reporter printer
Also simplify some variables with auto deduction.
2019-08-06 20:19:42 +02:00
Martin Hořeňovský
cf55cfd76f Tiny speedup when listing tags
Noticed that the code was originally concatenating strings just to
then append the result to another string. Now it does not create
temporaries and also preallocates the string buffer.
2019-08-05 19:12:29 +02:00
Martin Hořeňovský
3701c2e2e6 Small cleanup of self tests 2019-08-04 13:50:25 +02:00
Martin Hořeňovský
7dc7d77af2 Add a test for Catch version output 2019-08-03 20:16:46 +02:00
Martin Hořeňovský
06bc20cf37 Improve handling of newlines in release scripts
Under WSL, Python in text mode will translate `\n` into `\r\n`, even
though other tools and utilities use `\n` (because WSL is basically
Linux). This leads to the update scripts leaving the files with
Windows newlines even though git and similar expect them to have
Linux newlines.

By instead handling files in binary mode, we can keep the original
newlines. This commits switches parts of the update process to
binary mode, but not all because some of the will require a lot of
work to fix.
2019-08-03 19:59:35 +02:00
Martin Hořeňovský
7a4beed6a6 Make release script update version placeholders in docs 2019-08-03 10:44:57 +02:00
Clare Macrae
67b4ada6b0 Add 'Introduced in Catch 2.3.0.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
119569a67e Add 'Introduced in Catch 2.4.0.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
ab713894cc Add docs for AND_GIVEN macro - see #1360 2019-08-02 19:18:47 +02:00
Clare Macrae
69fc94d6f8 Add 'Introduced in Catch 2.4.1.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
49cd7c96b4 Add 'Introduced in Catch 2.4.2.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
e998d152cc Add 'Introduced in Catch 2.5.0.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
42a5903188 Add 'Introduced in Catch 2.6.0.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
c071f07e1a Add 'Introduced in Catch 2.7.0.' note 2019-08-02 19:18:47 +02:00
Clare Macrae
53776a90cf Add 'Introduced in Catch 2.7.1.' note 2019-08-02 19:18:47 +02:00
Clare Macrae
4511dc0c16 Add 'Introduced in Catch 2.8.0.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
e7c3bdb351 Add 'Introduced in Catch 2.8.0.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
9aab958667 Add section headers, so I can later say when features were introduced 2019-08-02 19:18:47 +02:00
Clare Macrae
8cd58f75ec Add missing struct Template_Fixture_2 so that the example compiles.
Code copied from projects/SelfTest/UsageTests/Class.tests.cpp
2019-08-02 19:18:47 +02:00
Clare Macrae
d5a69cd400 Add 'Introduced in Catch 2.9.0.' text 2019-08-02 19:18:47 +02:00
Clare Macrae
1d13d88833 Helper script to create "Introduced in ..." text - see #1667 2019-08-02 19:18:47 +02:00
Martin Hořeňovský
de0674c116 Add a template for creating new documentation page
Related to #1695
2019-08-02 13:17:22 +02:00
Martin Hořeňovský
3d7282c2bd Add a section on documentation to contributing.md
Related to #1695
2019-08-02 10:58:51 +02:00
Mike Cowan
e5c0e3322d Add Android implementation of writeToDebugConsole that prints to Logcat (#1710) 2019-07-31 23:12:34 +02:00
Martin Hořeňovský
dc8c8e957f Use an up to date conan package version again
Last time it was fixed to a specific version because the `conan`
and the `conan-package-tools` package that `pip install` would
gather were not compatible, let's hope it won't happen again.
2019-07-31 15:59:16 +02:00
Martin Hořeňovský
ba9193370b Add autoconfiguration for RTX
Closes #1693
2019-07-30 11:28:28 +02:00
Czapa10
7b70b11c23 Add PopHead to Open Source projects using Catch 2019-07-30 09:37:05 +02:00
Martin Hořeňovský
ab80277a86 Improve the REQUIRE_THROWS_MATCHES documentation a bit 2019-07-29 20:39:02 +02:00
Joachim Meyer
7e7ab0e28b Fix xml reporter crashing when a benchmark failed. 2019-07-29 15:30:33 +02:00
Martin Hořeňovský
425957dc63 Update vector matcher documentation
As it turns out, there were 2 undocumented vector matchers. I also
improved the documentation of them all.

Closes #1699
2019-07-27 18:41:42 +02:00
Martin Hořeňovský
d017f6d18f Document CATCH_CONFIG_CPP17_BYTE macro
Leftover from #1686
2019-07-26 21:43:46 +02:00
Martin Hořeňovský
91244d30a7 Document CATCH_CONFIG_CPP17_OPTIONAL macro 2019-07-26 21:42:54 +02:00
Martin Hořeňovský
62b3f6c3c2 Merge pull request #1698 from sfranzen/fix-#1634
Fix CTest command issue with square brackets
2019-07-22 13:15:35 +02:00
Benjamin Worpitz
e7c26f09d1 Fix non-default-constructible type lists used in TEMPLATE_LIST_TEST_CASE (#1697)
* Fix non-default-constructible type lists used in TEMPLATE_LIST_TEST_CASE

std::tuple is not default constructible when the first type is not
default-constuctible. Therefore it can not be instantiated.
to circumvent this, we have to use std::declval in the unevaluate decltype
context.
2019-07-22 12:56:33 +02:00
Martin Hořeňovský
a22b7df46c Merge pull request #1700 from claremacrae/patch-3
Fix typo in 2.7.1 release notes
2019-07-22 12:13:29 +02:00
Clare Macrae
032068b889 Fix typo in 2.7.1 release notes
GENERATE_VAR -> GENERATE_REF
2019-07-21 22:04:50 +01:00
Steven Franzen
2aed6233cf Fix CTest command issue with square brackets 2019-07-21 16:29:46 +02:00
Martin Hořeňovský
fb74bb133c Fix coverage report merging
For some time now (I'd guess almost a year 🤷), the coverage
merging on Windows has been failing, because the reports have been
generated in a different folder than expected. Our merge script did
not report failure because it was not checking the returned error
code from OpenCppCoverage, and for some reason, the `codecov` tool
happily returned 0 even though it did not find the file it was
supposed to upload...

The former is also fixed by this commit.
2019-07-20 21:12:17 +02:00
Martin Hořeňovský
0b42ada60d Coverage helper now passes-on test return value
This allows #1684 to proceed forward.
2019-07-20 21:05:31 +02:00
Martin Hořeňovský
c424ca47f9 Revert "Do not resolve symbolic path when sanitizing filepath during approvals"
This reverts commit 52f3abadbb.

Opens #1691
2019-07-19 18:16:21 +02:00
Martin Hořeňovský
52f3abadbb Do not resolve symbolic path when sanitizing filepath during approvals
Fixes #1691
2019-07-18 16:33:57 +02:00
Martin Hořeňovský
53281b471f Prevent compilation of generators that use bool in dangerous manner
Closes #1692
2019-07-18 11:54:18 +02:00
Martin Hořeňovský
03ffc1014c Add a notice that benchmarking supports needs opt-in 2019-07-14 15:49:17 +02:00
Stuart Dootson
87739ad3fe Add std::byte stringification support (#1686)
* Add `std::byte` support

1. Add byte detection in Catch config
2. Add a `std::byte`specialisation for Catch2::Detail::StringMaker
2019-07-13 14:47:56 +02:00
Clare Macrae
0c27554af5 Update Contents in docs #1667 2019-07-06 17:25:55 +02:00
Martin Hořeňovský
11488e63b6 Use _WIN32 macro for detecting MSVC Windows
Previously we used `WIN32`, which sometimes does exist, but according to
https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2019
`_WIN32` is the one that is actually provided by the compiler.

Closes #1676.
2019-07-06 16:55:10 +02:00
Martin Hořeňovský
820271bf24 Remove the weird backronym from readme 2019-07-02 20:43:37 +02:00
Martin Hořeňovský
56d4510138 Default the SelfTest project to C++11
Unlike the previous approach, this will still obey
`-DCMAKE_CXX_STANDARD=X` properly.
2019-07-02 20:42:14 +02:00
Martin Hořeňovský
c0d3a2e08f Merge pull request #1672 from sommd/master
Fix ChunkGenerator with chunk-size 0
2019-07-01 18:07:37 +02:00
Martin Hořeňovský
2c3018a9d5 Merge pull request #1673 from sfranzen/fix-sections
Fix TrackerBase::close children completion check
2019-06-30 09:17:01 +02:00
Martin Hořeňovský
9a6551b22b Add integration test for the children completion check fix 2019-06-30 00:00:41 +02:00
Steven Franzen
800f1b1d3d Fix TrackerBase::close children completion check
Now verifies that all children have completed, instead of only the last.
2019-06-29 18:02:28 +02:00
David Sommerich
9cf5897a11 Fix ChunkGenerator with chunk-size 0
Fixes #1671
2019-06-29 23:48:30 +10:00
Scott Hutchinson
6f32c67ea7 Adding to documentation for --order and --rng-seed 2019-06-21 15:17:55 +02:00
Martin Hořeňovský
7eea3ab245 Actually fix the CMake platform-independence problem 2019-06-17 19:41:17 +02:00
Justin Bassett
80af9ca687 Rollback ctest labels in CatchAddTests.cmake
Parsing --list-tests is broken, as Catch automatically line wraps the
line when it gets too long, stripping any whitespace in the process.
This means that it's impossible to reproduce the exact name of the
test if the test's name is long enough to line-wrap.

Furthermore, overwriting the LABELS property with the discovered labels
breaks users who manually added custom ctest labels.

Rolling back to using --list-test-names-only for now, as it does not
wrap lines even on very long test names.

We may be able parse the output of --list-tags to produce the ctest labels.
However, the straightforward way of doing this is to use CMake's
get_property(TEST ...) and set_property(TEST ... APPEND ...), which don't
work if the test name has spaces or other special characters. We would
need to mangle the test name to a valid CMake identifier to do it that way.
2019-06-17 19:17:32 +02:00
Martin Hořeňovský
33286fdc37 Fix bug with making arch-independent CMake config file
Closes #1660
2019-06-17 19:08:16 +02:00
131 changed files with 5244 additions and 1650 deletions

View File

@@ -9,8 +9,8 @@ common_sources: &all_sources
- llvm-toolchain-trusty
- llvm-toolchain-trusty-3.9
- llvm-toolchain-trusty-4.0
- llvm-toolchain-trusty-5.0
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-5.0
- llvm-toolchain-xenial-6.0
matrix:
include:
@@ -60,6 +60,7 @@ matrix:
env: COMPILER='clang++-4.0'
- os: linux
dist: xenial
compiler: clang
addons:
apt:
@@ -68,6 +69,7 @@ matrix:
env: COMPILER='clang++-5.0'
- os: linux
dist: xenial
compiler: clang
addons:
apt:
@@ -153,6 +155,7 @@ matrix:
env: COMPILER='clang++-4.0' CPP14=1
- os: linux
dist: xenial
compiler: clang
addons:
apt:
@@ -161,6 +164,7 @@ matrix:
env: COMPILER='clang++-5.0' CPP14=1
- os: linux
dist: xenial
compiler: clang
addons:
apt:
@@ -255,6 +259,7 @@ matrix:
env: COMPILER='g++-7' EXAMPLES=1 COVERAGE=1 EXTRAS=1 CPP17=1
- os: linux
dist: xenial
compiler: clang
addons:
apt:
@@ -263,6 +268,7 @@ matrix:
env: COMPILER='clang++-6.0' CPP17=1
- os: linux
dist: xenial
compiler: clang
addons:
apt:
@@ -276,7 +282,7 @@ matrix:
- "3.7"
dist: xenial
install:
- pip install conan==1.10.2 conan-package-tools
- pip install conan-package-tools
env:
- CONAN_GCC_VERSIONS=8
- CONAN_DOCKER_IMAGE=conanio/gcc8

View File

@@ -6,12 +6,16 @@ if(NOT DEFINED PROJECT_NAME)
set(NOT_SUBPROJECT ON)
endif()
project(Catch2 LANGUAGES CXX VERSION 2.9.1)
if (CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
# Catch2's build breaks if done in-tree. You probably should not build
# things in tree anyway, but we can allow projects that include Catch2
# as a subproject to build in-tree as long as it is not in our tree.
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif()
project(Catch2 LANGUAGES CXX VERSION 2.10.2)
# Provide path for scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
@@ -92,6 +96,10 @@ target_include_directories(Catch2
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if (ANDROID)
target_link_libraries(Catch2 INTERFACE log)
endif()
# provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
add_library(Catch2::Catch2 ALIAS Catch2)
@@ -136,9 +144,11 @@ if (NOT_SUBPROJECT)
#
# CMake does not provide a direct customization point for this in
# `write_basic_package_version_file`, but it can be accomplished
# indirectly by temporarily undefining `CMAKE_SIZEOF_VOID_P`.
# indirectly by temporarily redefining `CMAKE_SIZEOF_VOID_P` to an
# empty string. Note that just undefining the variable could be
# insufficient in cases where the variable was already in CMake cache
set(CATCH2_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
set(CMAKE_SIZEOF_VOID_P "")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
COMPATIBILITY

View File

@@ -5,11 +5,11 @@
[![Build Status](https://travis-ci.org/catchorg/Catch2.svg?branch=master)](https://travis-ci.org/catchorg/Catch2)
[![Build status](https://ci.appveyor.com/api/projects/status/github/catchorg/Catch2?svg=true)](https://ci.appveyor.com/project/catchorg/catch2)
[![codecov](https://codecov.io/gh/catchorg/Catch2/branch/master/graph/badge.svg)](https://codecov.io/gh/catchorg/Catch2)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/5icuqPwk9miJLAL1)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/LzYWgcPrcy9yQmed)
[![Join the chat in Discord: https://discord.gg/4CWS9zD](https://img.shields.io/badge/Discord-Chat!-brightgreen.svg)](https://discord.gg/4CWS9zD)
<a href="https://github.com/catchorg/Catch2/releases/download/v2.9.1/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
<a href="https://github.com/catchorg/Catch2/releases/download/v2.10.2/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
## Catch2 is released!
@@ -19,9 +19,8 @@ before moving to Catch2. You might also like to read [this blog post](https://le
## What's the Catch?
Catch2 stands for C++ Automated Test Cases in a Header and is a
multi-paradigm test framework for C++. which also supports Objective-C
(and maybe C).
Catch2 is a multi-paradigm test framework for C++. which also supports
Objective-C (and maybe C).
It is primarily distributed as a single header file, although certain
extensions may require additional headers.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -22,39 +22,6 @@ function(add_command NAME)
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
endfunction()
macro(_add_catch_test_labels LINE)
# convert to list of tags
string(REPLACE "][" "]\\;[" tags ${line})
add_command(
set_tests_properties "${prefix}${test}${suffix}"
PROPERTIES
LABELS "${tags}"
)
endmacro()
macro(_add_catch_test LINE)
set(test ${line})
# use escape commas to handle properly test cases with commans inside the name
string(REPLACE "," "\\," test_name ${test})
# ...and add to script
add_command(
add_test "${prefix}${test}${suffix}"
${TEST_EXECUTOR}
"${TEST_EXECUTABLE}"
"${test_name}"
${extra_args}
)
add_command(
set_tests_properties "${prefix}${test}${suffix}"
PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
${properties}
)
list(APPEND tests "${prefix}${test}${suffix}")
endmacro()
# Run test executable to get list of available tests
if(NOT EXISTS "${TEST_EXECUTABLE}")
message(FATAL_ERROR
@@ -62,7 +29,7 @@ if(NOT EXISTS "${TEST_EXECUTABLE}")
)
endif()
execute_process(
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only
OUTPUT_VARIABLE output
RESULT_VARIABLE result
)
@@ -80,22 +47,30 @@ elseif(${result} LESS 0)
endif()
string(REPLACE "\n" ";" output "${output}")
set(test)
set(tags_regex "(\\[([^\\[]*)\\])+$")
# Parse output
foreach(line ${output})
# lines without leading whitespaces are catch output not tests
if(${line} MATCHES "^[ \t]+")
# strip leading spaces and tabs
string(REGEX REPLACE "^[ \t]+" "" line ${line})
if(${line} MATCHES "${tags_regex}")
_add_catch_test_labels(${line})
else()
_add_catch_test(${line})
endif()
endif()
set(test ${line})
# Escape characters in test case names that would be parsed by Catch2
set(test_name ${test})
foreach(char , [ ])
string(REPLACE ${char} "\\${char}" test_name ${test_name})
endforeach(char)
# ...and add to script
add_command(add_test
"${prefix}${test}${suffix}"
${TEST_EXECUTOR}
"${TEST_EXECUTABLE}"
"${test_name}"
${extra_args}
)
add_command(set_tests_properties
"${prefix}${test}${suffix}"
PROPERTIES
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
${properties}
)
list(APPEND tests "${prefix}${test}${suffix}")
endforeach()
# Create a list of all discovered tests, which users may use to e.g. set

View File

@@ -136,7 +136,7 @@ REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
* **REQUIRE_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)** and
* **CHECK_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)**
Expects that exception of _exception type_ is thrown and it matches provided matcher (see next section for Matchers).
Expects that exception of _exception type_ is thrown and it matches provided matcher (see the [documentation for Matchers](matchers.md#top)).
_Please note that the `THROW` family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function._

View File

@@ -1,6 +1,12 @@
<a id="top"></a>
# Authoring benchmarks
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
_Note that benchmarking support is disabled by default and to enable it,
you need to define `CATCH_CONFIG_ENABLE_BENCHMARKING`. For more details,
see the [compile-time configuration documentation](configuration.md#top)._
Writing benchmarks is not easy. Catch simplifies certain aspects but you'll
always need to take care about various aspects. Understanding a few things about
the way Catch runs your code will be very helpful when writing your benchmarks.

View File

@@ -21,8 +21,8 @@
[Identify framework and version according to the libIdentify standard](#identify-framework-and-version-according-to-the-libidentify-standard)<br>
[Wait for key before continuing](#wait-for-key-before-continuing)<br>
[Specify the number of benchmark samples to collect](#specify-the-number-of-benchmark-samples-to-collect)<br>
[Specify the number of benchmark resamples for bootstrapping](#specify-the-number-of-resamples-for-bootstrapping)<br>
[Specify the confidence interval for bootstrapping](#specify-the-confidence-interval-for-bootstrapping)<br>
[Specify the number of resamples for bootstrapping](#specify-the-number-of-resamples-for-bootstrapping)<br>
[Specify the confidence-interval for bootstrapping](#specify-the-confidence-interval-for-bootstrapping)<br>
[Disable statistical analysis of collected benchmark samples](#disable-statistical-analysis-of-collected-benchmark-samples)<br>
[Usage](#usage)<br>
[Specify the section to run](#specify-the-section-to-run)<br>
@@ -99,6 +99,7 @@ exclude:notThis Matches all tests except, 'notThis'
~*private* Matches all tests except those that contain 'private'
a* ~ab* abc Matches all tests that start with 'a', except those that
start with 'ab', except 'abc', which is included
-# [#somefile] Matches all tests from the file 'somefile.cpp'
</pre>
Names within square brackets are interpreted as tags.
@@ -242,7 +243,7 @@ Test cases are ordered one of three ways:
### decl
Declaration order. The order the tests were originally declared in. Note that ordering between files is not guaranteed and is implementation dependent.
Declaration order (this is the default order if no --order argument is provided). The order the tests were originally declared in. Note that ordering between files is not guaranteed and is implementation dependent.
### lex
Lexicographically sorted. Tests are sorted, alpha-numerically, by name.
@@ -256,7 +257,7 @@ Randomly sorted. Test names are sorted using ```std::random_shuffle()```. By def
Sets a seed for the random number generator using ```std::srand()```.
If a number is provided this is used directly as the seed so the random pattern is repeatable.
Alternatively if the keyword ```time``` is provided then the result of calling ```std::time(0)``` is used and so the pattern becomes unpredictable.
Alternatively if the keyword ```time``` is provided then the result of calling ```std::time(0)``` is used and so the pattern becomes unpredictable. In some cases, you might need to pass the keyword ```time``` in double quotes instead of single quotes.
In either case the actual value for the seed is printed as part of Catch's output so if an issue is discovered that is sensitive to test ordering the ordering can be reproduced - even if it was originally seeded from ```std::time(0)```.
@@ -277,6 +278,8 @@ either before running any tests, after running all tests - or both, depending on
## Specify the number of benchmark samples to collect
<pre>--benchmark-samples &lt;# of samples&gt;</pre>
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
When running benchmarks a number of "samples" is collected. This is the base data for later statistical analysis.
Per sample a clock resolution dependent number of iterations of the user code is run, which is independent of the number of samples. Defaults to 100.
@@ -284,6 +287,8 @@ Per sample a clock resolution dependent number of iterations of the user code is
## Specify the number of resamples for bootstrapping
<pre>--benchmark-resamples &lt;# of resamples&gt;</pre>
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
After the measurements are performed, statistical [bootstrapping] is performed
on the samples. The number of resamples for that bootstrapping is configurable
but defaults to 100000. Due to the bootstrapping it is possible to give
@@ -297,6 +302,8 @@ defaults to 95%).
## Specify the confidence-interval for bootstrapping
<pre>--benchmark-confidence-interval &lt;confidence-interval&gt;</pre>
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
The confidence-interval is used for statistical bootstrapping on the samples to
calculate the upper and lower bounds of mean and standard deviation.
Must be between 0 and 1 and defaults to 0.95.
@@ -305,6 +312,8 @@ Must be between 0 and 1 and defaults to 0.95.
## Disable statistical analysis of collected benchmark samples
<pre>--benchmark-no-analysis</pre>
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
When this flag is specified no bootstrapping or any other statistical analysis is performed.
Instead the user code is only measured and the plain mean from the samples is reported.

View File

@@ -17,3 +17,4 @@ fact then please let us know - either directly, via a PR or
- NASA
- [Inscopix Inc.](https://www.inscopix.com/)
- [Makimo](https://makimo.pl/)
- [UX3D] (https://ux3d.io)

View File

@@ -127,8 +127,12 @@ Catch's selection, by defining either `CATCH_CONFIG_CPP11_TO_STRING` or
## C++17 toggles
CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS // Use std::uncaught_exceptions instead of std::uncaught_exception
CATCH_CONFIG_CPP17_STRING_VIEW // Provide StringMaker specialization for std::string_view
CATCH_CONFIG_CPP17_VARIANT // Override C++17 detection for CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
CATCH_CONFIG_CPP17_STRING_VIEW // Override std::string_view support detection(Catch provides a StringMaker specialization by default)
CATCH_CONFIG_CPP17_VARIANT // Override std::variant support detection (checked by CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER)
CATCH_CONFIG_CPP17_OPTIONAL // Override std::optional support detection (checked by CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER)
CATCH_CONFIG_CPP17_BYTE // Override std::byte support detection (Catch provides a StringMaker specialization by default)
> `CATCH_CONFIG_CPP17_STRING_VIEW` was [introduced](https://github.com/catchorg/Catch2/issues/1376) in Catch 2.4.1.
Catch contains basic compiler/standard detection and attempts to use
some C++17 features whenever appropriate. This automatic detection
@@ -151,6 +155,10 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`.
CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr
CATCH_CONFIG_ENABLE_BENCHMARKING // Enables the integrated benchmarking features (has a significant effect on compilation speed)
CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking
CATCH_CONFIG_ANDROID_LOGWRITE // Use android's logging system for debug output
CATCH_CONFIG_GLOBAL_NEXTAFTER // Use nextafter{,f,l} instead of std::nextafter
> [`CATCH_CONFIG_ANDROID_LOGWRITE`](https://github.com/catchorg/Catch2/issues/1743) and [`CATCH_CONFIG_GLOBAL_NEXTAFTER`](https://github.com/catchorg/Catch2/pull/1739) were introduced in Catch 2.10.0
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
@@ -209,9 +217,14 @@ By default, Catch does not stringify some types from the standard library. This
CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER // Provide StringMaker specialization for std::optional (on C++17)
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS // Defines all of the above
> `CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1380) in Catch 2.4.1.
> `CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1510) in Catch 2.6.0.
## Disabling exceptions
> Introduced in Catch 2.4.0.
By default, Catch2 uses exceptions to signal errors and to abort tests
when an assertion from the `REQUIRE` family of assertions fails. We also
provide an experimental support for disabling exceptions. Catch2 should

View File

@@ -1,6 +1,13 @@
<a id="top"></a>
# Contributing to Catch
**Contents**<br>
[Branches](#branches)<br>
[Directory structure](#directory-structure)<br>
[Testing your changes](#testing-your-changes)<br>
[Documenting your code](#documenting-your-code)<br>
[Code constructs to watch out for](#code-constructs-to-watch-out-for)<br>
So you want to contribute something to Catch? That's great! Whether it's a bug fix, a new feature, support for
additional compilers - or just a fix to the documentation - all contributions are very welcome and very much appreciated.
Of course so are bug reports and other comments and questions.
@@ -63,6 +70,10 @@ locally takes just a few minutes.
$ cd debug-build
$ ctest -j 2 --output-on-failure
```
__Note:__ When running your tests with multi-configuration generators like
Visual Studio, you might get errors "Test not available without configuration."
You then have to pick one configuration (e.g. ` -C Debug`) in the `ctest` call.
If you added new tests, approval tests are very likely to fail. If they
do not, it means that your changes weren't run as part of them. This
_might_ be intentional, but usually is not.
@@ -75,6 +86,59 @@ before you do so, you need to check that the introduced changes are indeed
intentional.
## Documenting your code
If you have added new feature to Catch2, it needs documentation, so that
other people can use it as well. This section collects some technical
information that you will need for updating Catch2's documentation, and
possibly some generic advise as well.
First, the technicalities:
* We introduced version tags to the documentation, which show users in
which version a specific feature was introduced. This means that newly
written documentation should be tagged with a placeholder, that will
be replaced with the actual version upon release. There are 2 styles
of placeholders used through the documentation, you should pick one that
fits your text better (if in doubt, take a look at the existing version
tags for other features).
* `> [Introduced](link-to-issue-or-PR) in Catch X.Y.Z` - this
placeholder is usually used after a section heading
* `> X (Y and Z) was [introduced](link-to-issue-or-PR) in Catch X.Y.Z`
- this placeholder is used when you need to tag a subpart of something,
e.g. list
* Crosslinks to different pages should target the `top` anchor, like this
`[link to contributing](contributing.md#top)`.
* If you have introduced a new document, there is a simple template you
should use. It provides you with the top anchor mentioned above, and also
with a backlink to the top of the documentation:
```markdown
<a id="top"></a>
# Cool feature
Text that explains how to use the cool feature.
---
[Home](Readme.md#top)
```
* For pages with more than 4 subheadings, we provide a table of contents
(ToC) at the top of the page. Because GitHub markdown does not support
automatic generation of ToC, it has to be handled semi-manually. Thus,
if you've added a new subheading to some page, you should add it to the
ToC. This can be done either manually, or by running the
`updateDocumentToC.py` script in the `scripts/` folder.
Now, for the generic tips:
* Usage examples are good
* Don't be afraid to introduce new pages
* Try to be reasonably consistent with the surrounding documentation
## Code constructs to watch out for
This section is a (sadly incomplete) listing of various constructs that

View File

@@ -39,6 +39,11 @@ apart from writing it out for `--list-tests -v high`.
Because it isn't actually used nor documented, and brings complications
to Catch2's internals, description support will be removed.
### SourceLineInfo::empty()
There should be no reason to ever have an empty `SourceLineInfo`, so the
method will be removed.
## Planned changes

View File

@@ -1,6 +1,8 @@
<a id="top"></a>
# Data Generators
> Introduced in Catch 2.6.0.
Data generators (also known as _data driven/parametrized test cases_)
let you reuse the same set of assertions across different input values.
In Catch2, this means that they respect the ordering and nesting
@@ -34,8 +36,8 @@ Catch2's provided generator functionality consists of three parts,
* `GENERATE` macro, that serves to integrate generator expression with
a test case,
* 2 fundamental generators
* `ValueGenerator<T>` -- contains only single element
* `ValuesGenerator<T>` -- contains multiple elements
* `SingleValueGenerator<T>` -- contains only single element
* `FixedValuesGenerator<T>` -- contains multiple elements
* 5 generic generators that modify other generators
* `FilterGenerator<T, Predicate>` -- filters out elements from a generator
for which the predicate returns "false"
@@ -44,16 +46,22 @@ a test case,
* `MapGenerator<T, U, Func>` -- returns the result of applying `Func`
on elements from a different generator
* `ChunkGenerator<T>` -- returns chunks (inside `std::vector`) of n elements from a generator
* 3 specific purpose generators
* 4 specific purpose generators
* `RandomIntegerGenerator<Integral>` -- generates random Integrals from range
* `RandomFloatGenerator<Float>` -- generates random Floats from range
* `RangeGenerator<T>` -- generates all values inside a specific range
* `IteratorGenerator<T>` -- copies and returns values from an iterator range
> `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch 2.7.0.
> `IteratorGenerator<T>` was introduced in Catch 2.10.0.
The generators also have associated helper functions that infer their
type, making their usage much nicer. These are
* `value(T&&)` for `ValueGenerator<T>`
* `values(std::initializer_list<T>)` for `ValuesGenerator<T>`
* `value(T&&)` for `SingleValueGenerator<T>`
* `values(std::initializer_list<T>)` for `FixedValuesGenerator<T>`
* `table<Ts...>(std::initializer_list<std::tuple<Ts...>>)` for `FixedValuesGenerator<std::tuple<Ts...>>`
* `filter(predicate, GeneratorWrapper<T>&&)` for `FilterGenerator<T, Predicate>`
* `take(count, GeneratorWrapper<T>&&)` for `TakeGenerator<T>`
* `repeat(repeats, GeneratorWrapper<T>&&)` for `RepeatGenerator<T>`
@@ -63,7 +71,12 @@ type, making their usage much nicer. These are
* `random(IntegerOrFloat a, IntegerOrFloat b)` for `RandomIntegerGenerator` or `RandomFloatGenerator`
* `range(start, end)` for `RangeGenerator<T>` with a step size of `1`
* `range(start, end, step)` for `RangeGenerator<T>` with a custom step size
* `from_range(InputIterator from, InputIterator to)` for `IteratorGenerator<T>`
* `from_range(Container const&)` for `IteratorGenerator<T>`
> `chunk()`, `random()` and both `range()` functions were introduced in Catch 2.7.0.
> `from_range` has been introduced in Catch 2.10.0
And can be used as shown in the example below to create a generator
that returns 100 odd random number:
@@ -84,7 +97,7 @@ Apart from registering generators with Catch2, the `GENERATE` macro has
one more purpose, and that is to provide simple way of generating trivial
generators, as seen in the first example on this page, where we used it
as `auto i = GENERATE(1, 2, 3);`. This usage converted each of the three
literals into a single `ValueGenerator<int>` and then placed them all in
literals into a single `SingleValueGenerator<int>` and then placed them all in
a special generator that concatenates other generators. It can also be
used with other generators as arguments, such as `auto i = GENERATE(0, 2,
take(100, random(300, 3000)));`. This is useful e.g. if you know that
@@ -96,6 +109,8 @@ scope and thus capturing references is dangerous. If you need to use
variables inside the generator expression, make sure you thought through
the lifetime implications and use `GENERATE_COPY` or `GENERATE_REF`.**
> `GENERATE_COPY` and `GENERATE_REF` were introduced in Catch 2.7.1.
You can also override the inferred type by using `as<type>` as the first
argument to the macro. This can be useful when dealing with string literals,
if you want them to come out as `std::string`:

View File

@@ -45,6 +45,15 @@ the `REQUIRE` family of macros), Catch2 does not know that there are no
more sections in that test case and must run the test case again.
### MinGW/CygWin compilation (linking) is extremely slow
Compiling Catch2 with MinGW can be exceedingly slow, especially during
the linking step. As far as we can tell, this is caused by deficiencies
in its default linker. If you can tell MinGW to instead use lld, via
`-fuse-ld=lld`, the link time should drop down to reasonable length
again.
## Features
This section outlines some missing features, what is their status and their possible workarounds.

View File

@@ -30,6 +30,8 @@ When the last `CHECK` fails in the "Bar" test case, then only one message will b
## Logging without local scope
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch 2.7.0.
`UNSCOPED_INFO` is similar to `INFO` with two key differences:
- Lifetime of an unscoped message is not tied to its own scope.
@@ -104,6 +106,8 @@ This semicolon will be removed with next major version. It is highly advised to
**UNSCOPED_INFO(** _message expression_ **)**
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch 2.7.0.
Similar to `INFO`, but messages are not limited to their own scope: They are removed from the buffer after each assertion, section or test case, whichever comes first.
**WARN(** _message expression_ **)**

View File

@@ -12,11 +12,11 @@ The first argument is the thing (object or value) under test. The second part is
which consists of either a single matcher or one or more matchers combined using `&&`, `||` or `!` operators.
For example, to assert that a string ends with a certain substring:
```c++
using Catch::Matchers::EndsWith; // or Catch::EndsWith
std::string str = getStringFromSomewhere();
REQUIRE_THAT( str, EndsWith( "as a service" ) );
REQUIRE_THAT( str, EndsWith( "as a service" ) );
```
The matcher objects can take multiple arguments, allowing more fine tuning.
@@ -24,19 +24,29 @@ The built-in string matchers, for example, take a second argument specifying whe
case sensitive or not:
```c++
REQUIRE_THAT( str, EndsWith( "as a service", Catch::CaseSensitive::No ) );
REQUIRE_THAT( str, EndsWith( "as a service", Catch::CaseSensitive::No ) );
```
And matchers can be combined:
```c++
REQUIRE_THAT( str,
EndsWith( "as a service" ) ||
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
REQUIRE_THAT( str,
EndsWith( "as a service" ) ||
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
```
## Built in matchers
Catch currently provides some matchers, they are in the `Catch::Matchers` and `Catch` namespaces.
Catch2 provides some matchers by default. They can be found in the
`Catch::Matchers::foo` namespace and are imported into the `Catch`
namespace as well.
There are two parts to each of the built-in matchers, the matcher
type itself and a helper function that provides template argument
deduction when creating templated matchers. As an example, the matcher
for checking that two instances of `std::vector` are identical is
`EqualsMatcher<T>`, but the user is expected to use the `Equals`
helper function instead.
### String matchers
The string matchers are `StartsWith`, `EndsWith`, `Contains`, `Equals` and `Matches`. The first four match a literal (sub)string against a result, while `Matches` takes and matches an ECMAScript regex. Do note that `Matches` matches the string as a whole, meaning that "abc" will not match against "abcd", but "abc.*" will.
@@ -45,13 +55,42 @@ Each of the provided `std::string` matchers also takes an optional second argume
### Vector matchers
The vector matchers are `Contains`, `VectorContains` and `Equals`. `VectorContains` looks for a single element in the matched vector, `Contains` looks for a set (vector) of elements inside the matched vector.
Catch2 currently provides 5 built-in matchers that work on `std::vector`.
These are
* `Contains` which checks whether a specified vector is present in the result
* `VectorContains` which checks whether a specified element is present in the result
* `Equals` which checks whether the result is exactly equal (order matters) to a specific vector
* `UnorderedEquals` which checks whether the result is equal to a specific vector under a permutation
* `Approx` which checks whether the result is "approx-equal" (order matters, but comparison is done via `Approx`) to a specific vector
> Approx matcher was [introduced](https://github.com/catchorg/Catch2/issues/1499) in Catch 2.7.2.
### Floating point matchers
The floating point matchers are `WithinULP` and `WithinAbs`. `WithinAbs` accepts floating point numbers that are within a certain margin of target. `WithinULP` performs an [ULP](https://en.wikipedia.org/wiki/Unit_in_the_last_place)-based comparison of two floating point numbers and accepts them if they are less than certain number of ULPs apart.
Catch2 provides 3 matchers for working with floating point numbers. These
are `WithinAbsMatcher`, `WithinUlpsMatcher` and `WithinRelMatcher`.
Do note that ULP-based checks only make sense when both compared numbers are of the same type and `WithinULP` will use type of its argument as the target type. This means that `WithinULP(1.f, 1)` will expect to compare `float`s, but `WithinULP(1., 1)` will expect to compare `double`s.
The `WithinAbsMatcher` matcher accepts floating point numbers that are
within a certain distance of target. It should be constructed with the
`WithinAbs(double target, double margin)` helper.
The `WithinUlpsMatcher` matcher accepts floating point numbers that are
within a certain number of [ULPs](https://en.wikipedia.org/wiki/Unit_in_the_last_place)
of the target. Because ULP comparisons need to be done differently for
`float`s and for `double`s, there are two overloads of the helpers for
this matcher, `WithinULP(float target, int64_t ULPs)`, and
`WithinULP(double target, int64_t ULPs)`.
The `WithinRelMatcher` matcher accepts floating point numbers that are
_approximately equal_ with the target number with some specific tolerance.
In other words, it checks that `|lhs - rhs| <= epsilon * max(|lhs|, |rhs|)`,
with special casing for `INFINITY` and `NaN`. There are _4_ overloads of
the helpers for this matcher, `WithinRel(double target, double margin)`,
`WithinRel(float target, float margin)`, `WithinRel(double target)`, and
`WithinRel(float target)`. The latter two provide a default epsilon of
machine epsilon * 100.
> `WithinRel` matcher was introduced in Catch 2.10.0
### Generic matchers
Catch also aims to provide a set of generic matchers. Currently this set
@@ -72,13 +111,29 @@ The second argument is an optional description of the predicate, and is
used only during reporting of the result.
### Exception matchers
Catch2 also provides an exception matcher that can be used to verify
that an exception's message exactly matches desired string. The matcher
is `ExceptionMessageMatcher`, and we also provide a helper function
`Message`.
The matched exception must publicly derive from `std::exception` and
the message matching is done _exactly_, including case.
> `ExceptionMessageMatcher` was introduced in Catch 2.10.0
Example use:
```cpp
REQUIRE_THROWS_MATCHES(throwsDerivedException(), DerivedException, Message("DerivedException::what"));
```
## Custom matchers
It's easy to provide your own matchers to extend Catch or just to work with your own types.
You need to provide two things:
You need to provide two things:
1. A matcher class, derived from `Catch::MatcherBase<T>` - where `T` is the type being tested.
The constructor takes and stores any arguments needed (e.g. something to compare against) and you must
override two methods: `match()` and `describe()`.
override two methods: `match()` and `describe()`.
2. A simple builder function. This is what is actually called from the test code and allows overloading.
Here's an example for asserting that an integer falls within a given range
@@ -123,7 +178,7 @@ TEST_CASE("Integers are within a range")
```
Running this test gives the following in the console:
```
/**/TestFile.cpp:123: FAILED:
CHECK_THAT( 100, IsBetween( 1, 10 ) )

View File

@@ -23,6 +23,9 @@ C++11 implementation of Approval Tests, for quick, convenient testing of legacy
### [Azmq](https://github.com/zeromq/azmq)
Boost Asio style bindings for ZeroMQ.
### [Cataclysm: Dark Days Ahead](https://github.com/CleverRaven/Cataclysm-DDA)
Post-apocalyptic survival RPG.
### [ChakraCore](https://github.com/Microsoft/ChakraCore)
The core part of the Chakra JavaScript engine that powers Microsoft Edge.
@@ -50,9 +53,6 @@ Open source Oracle Tuxedo-like XATMI middleware for C and C++.
### [Inja](https://github.com/pantor/inja)
A header-only template engine for modern C++.
### [JSON for Modern C++](https://github.com/nlohmann/json)
A, single-header, JSON parsing library that takes advantage of what C++ has to offer.
### [libcluon](https://github.com/chrberger/libcluon)
A single-header-only library written in C++14 to glue distributed software components (UDP, TCP, shared memory) supporting natively Protobuf, LCM/ZCM, MsgPack, and JSON for dynamic message transformations in-between.
@@ -112,6 +112,9 @@ SpECTRE is a code for multi-scale, multi-physics problems in astrophysics and gr
### [Standardese](https://github.com/foonathan/standardese)
Standardese aims to be a nextgen Doxygen.
### [PopHead](https://github.com/SPC-Some-Polish-Coders/PopHead)
A 2D, Zombie, RPG game which is being made on our own engine.
---
[Home](Readme.md#top)

View File

@@ -59,6 +59,8 @@ TEST_CASE( "SUCCEED showcase" ) {
* `STATIC_REQUIRE`
> [Introduced](https://github.com/catchorg/Catch2/issues/1362) in Catch 2.4.2.
`STATIC_REQUIRE( expr )` is a macro that can be used the same way as a
`static_assert`, but also registers the success with Catch2, so it is
reported as a success at runtime. The whole check can also be deferred
@@ -132,6 +134,8 @@ ANON_TEST_CASE() {
* `DYNAMIC_SECTION`
> Introduced in Catch 2.3.0.
`DYNAMIC_SECTION` is a `SECTION` where the user can use `operator<<` to
create the final name for that section. This can be useful with e.g.
generators, or when creating a `SECTION` dynamically, within a loop.

View File

@@ -2,6 +2,10 @@
# Release notes
**Contents**<br>
[2.10.2](#2102)<br>
[2.10.1](#2101)<br>
[2.10.0](#2100)<br>
[2.9.2](#292)<br>
[2.9.1](#291)<br>
[2.9.0](#290)<br>
[2.8.0](#280)<br>
@@ -26,6 +30,118 @@
[Older versions](#older-versions)<br>
[Even Older versions](#even-older-versions)<br>
## 2.10.2
### Improvements
* Catch2 will now compile on platform where `INFINITY` is double (#1782)
### Fixes
* Warning suppressed during listener registration will no longer leak
## 2.10.1
### Improvements
* Catch2 now guards itself against `min` and `max` macros from `windows.h` (#1772)
* Templated tests will now compile with ICC (#1748)
* `WithinULP` matcher now uses scientific notation for stringification (#1760)
### Fixes
* Templated tests no longer trigger `-Wunused-templates` (#1762)
* Suppressed clang-analyzer false positive in context getter (#1230, #1735)
### Miscellaneous
* CMake no longer prohibits in-tree build when Catch2 is used as a subproject (#1773, #1774)
## 2.10.0
### Fixes
* `TEMPLATE_LIST_TEST_CASE` now properly handles non-copyable and non-movable types (#1729)
* Fixed compilation error on Solaris caused by a system header defining macro `TT` (#1722, #1723)
* `REGISTER_ENUM` will now fail at compilation time if the registered enum is too large
* Removed use of `std::is_same_v` in C++17 mode (#1757)
* Fixed parsing of escaped special characters when reading test specs from a file (#1767, #1769)
### Improvements
* Trailing and leading whitespace in test/section specs are now ignored.
* Writing to Android debug log now uses `__android_log_write` instead of `__android_log_print`
* Android logging support can now be turned on/off at compile time (#1743)
* The toggle is `CATCH_CONFIG_ANDROID_LOGWRITE`
* Added a generator that returns elements of a range
* Use via `from_range(from, to)` or `from_range(container)`
* Added support for CRTs that do not provide `std::nextafter` (#1739)
* They must still provide global `nextafter{f,l,}`
* Enabled via `CATCH_CONFIG_GLOBAL_NEXTAFTER`
* Special cased `Approx(inf)` not to match non-infinite values
* Very strictly speaking this might be a breaking change, but it should match user expectations better
* The output of benchmarking through the Console reporter when `--benchmark-no-analysis` is set is now much simpler (#1768)
* Added a matcher that can be used for checking an exceptions message (#1649, #1728)
* The matcher helper function is called `Message`
* The exception must publicly derive from `std::exception`
* The matching is done exactly, including case and whitespace
* Added a matcher that can be used for checking relative equality of floating point numbers (#1746)
* Unlike `Approx`, it considers both sides when determining the allowed margin
* Special cases `NaN` and `INFINITY` to match user expectations
* The matcher helper function is called `WithinRel`
* The ULP matcher now allows for any possible distance between the two numbers
* The random number generators now use Catch-global instance of RNG (#1734, #1736)
* This means that nested random number generators actually generate different numbers
### Miscellaneous
* In-repo PNGs have been optimized to lower overhead of using Catch2 via git clone
* Catch2 now uses its own implementation of the URBG concept
* In the future we also plan to use our own implementation of the distributions from `<random>` to provide cross-platform repeatability of random results
## 2.9.2
### Fixes
* `ChunkGenerator` can now be used with chunks of size 0 (#1671)
* Nested subsections are now run properly when specific section is run via the `-c` argument (#1670, #1673)
* Catch2 now consistently uses `_WIN32` to detect Windows platform (#1676)
* `TEMPLATE_LIST_TEST_CASE` now support non-default constructible type lists (#1697)
* Fixed a crash in the XMLReporter when a benchmark throws exception during warmup (#1706)
* Fixed a possible infinite loop in CompactReporter (#1715)
* Fixed `-w NoTests` returning 0 even when no tests were matched (#1449, #1683, #1684)
* Fixed matcher compilation under Obj-C++ (#1661)
### Improvements
* `RepeatGenerator` and `FixedValuesGenerator` now fail to compile when used with `bool` (#1692)
* Previously they would fail at runtime.
* Catch2 now supports Android's debug logging for its debug output (#1710)
* Catch2 now detects and configures itself for the RTX platform (#1693)
* You still need to pass `--benchmark-no-analysis` if you are using benchmarking under RTX
* Removed a "storage class is not first" warning when compiling Catch2 with PGI compiler (#1717)
### Miscellaneous
* Documentation now contains indication when a specific feature was introduced (#1695)
* These start with Catch2 v2.3.0, (a bit over a year ago).
* `docs/contributing.md` has been updated to provide contributors guidance on how to add these to newly written documentation
* Various other documentation improvements
* ToC fixes
* Documented `--order` and `--rng-seed` command line options
* Benchmarking documentation now clearly states that it requires opt-in
* Documented `CATCH_CONFIG_CPP17_OPTIONAL` and `CATCH_CONFIG_CPP17_BYTE` macros
* Properly documented built-in vector matchers
* Improved `*_THROWS_MATCHES` documentation a bit
* CMake config file is now arch-independent even if `CMAKE_SIZEOF_VOID_P` is in CMake cache (#1660)
* `CatchAddTests` now properly escapes `[` and `]` in test names (#1634, #1698)
* Reverted `CatchAddTests` adding tags as CTest labels (#1658)
* The script broke when test names were too long
* Overwriting `LABELS` caused trouble for users who set them manually
* CMake does not let users append to `LABELS` if the test name has spaces
## 2.9.1
### Fixes
@@ -88,7 +204,7 @@
### Improvements
* Reporters now print out the filters applied to test cases (#1550, #1585)
* Added `GENERATE_COPY` and `GENERATE_VAR` macros that can use variables inside the generator expression
* Added `GENERATE_COPY` and `GENERATE_REF` macros that can use variables inside the generator expression
* Because of the significant danger of lifetime issues, the default `GENERATE` macro still does not allow variables
* The `map` generator helper now deduces the mapped return type (#1576)

View File

@@ -84,10 +84,13 @@ This macro maps onto ```TEST_CASE``` and works in the same way, except that the
These macros map onto ```SECTION```s except that the section names are the _something_s prefixed by "given: ", "when: " or "then: " respectively.
* **AND_GIVEN(** _something_ **)**
* **AND_WHEN(** _something_ **)**
* **AND_THEN(** _something_ **)**
Similar to ```WHEN``` and ```THEN``` except that the prefixes start with "and ". These are used to chain ```WHEN```s and ```THEN```s together.
Similar to ```GIVEN```, ```WHEN``` and ```THEN``` except that the prefixes start with "and ". These are used to chain ```GIVEN```s, ```WHEN```s and ```THEN```s together.
> `AND_GIVEN` was [introduced](https://github.com/catchorg/Catch2/issues/1360) in Catch 2.4.0.
When any of these macros are used the console reporter recognises them and formats the test case header such that the Givens, Whens and Thens are aligned to aid readability.
@@ -101,6 +104,8 @@ by types, in the form of `TEMPLATE_TEST_CASE`,
* **TEMPLATE_TEST_CASE(** _test name_ , _tags_, _type1_, _type2_, ..., _typen_ **)**
> [Introduced](https://github.com/catchorg/Catch2/issues/1437) in Catch 2.5.0.
_test name_ and _tag_ are exactly the same as they are in `TEST_CASE`,
with the difference that the tag string must be provided (however, it
can be empty). _type1_ through _typen_ is the list of types for which
@@ -151,6 +156,8 @@ TEMPLATE_TEST_CASE( "vectors can be sized and resized", "[vector][template]", in
* **TEMPLATE_PRODUCT_TEST_CASE(** _test name_ , _tags_, (_template-type1_, _template-type2_, ..., _template-typen_), (_template-arg1_, _template-arg2_, ..., _template-argm_) **)**
> [Introduced](https://github.com/catchorg/Catch2/issues/1468) in Catch 2.6.0.
_template-type1_ through _template-typen_ is list of template template
types which should be combined with each of _template-arg1_ through
_template-argm_, resulting in _n * m_ test cases. Inside the test case,
@@ -194,6 +201,8 @@ is very high and should not be encountered in practice._
* **TEMPLATE_LIST_TEST_CASE(** _test name_, _tags_, _type list_ **)**
> [Introduced](https://github.com/catchorg/Catch2/issues/1627) in Catch 2.9.0.
_type list_ is a generic list of types on which test case should be instantiated.
List can be `std::tuple`, `boost::mpl::list`, `boost::mp11::mp_list` or anything with
`template <typename...>` signature.
@@ -212,6 +221,8 @@ TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std
## Signature based parametrised test cases
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch 2.8.0.
In addition to [type parametrised test cases](#type-parametrised-test-cases) Catch2 also supports
signature base parametrised test cases, in form of `TEMPLATE_TEST_CASE_SIG` and `TEMPLATE_PRODUCT_TEST_CASE_SIG`.
These test cases have similar syntax like [type parametrised test cases](#type-parametrised-test-cases), with one

View File

@@ -1,6 +1,8 @@
<a id="top"></a>
# Test fixtures
## Defining test fixtures
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
```c++
@@ -84,6 +86,9 @@ _While there is an upper limit on the number of types you can specify
in single `TEMPLATE_TEST_CASE_METHOD` or `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
the limit is very high and should not be encountered in practice._
## Signature-based parametrised test fixtures
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch 2.8.0.
Catch2 also provides `TEMPLATE_TEST_CASE_METHOD_SIG` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG` to support
fixtures using non-type template parameters. These test cases work similar to `TEMPLATE_TEST_CASE_METHOD` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
@@ -100,6 +105,13 @@ TEMPLATE_TEST_CASE_METHOD_SIG(Nttp_Fixture, "A TEMPLATE_TEST_CASE_METHOD_SIG bas
REQUIRE(Nttp_Fixture<V>::value > 0);
}
template<typename T>
struct Template_Fixture_2 {
Template_Fixture_2() {}
T m_a;
};
template< typename T, size_t V>
struct Template_Foo_2 {
size_t size() { return V; }
@@ -111,6 +123,8 @@ TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG(Template_Fixture_2, "A TEMPLATE_PRODUCT_TE
}
```
## Template fixtures with types specified in template type lists
Catch2 also provides `TEMPLATE_LIST_TEST_CASE_METHOD` to support template fixtures with types specified in
template type lists like `std::tuple`, `boost::mpl::list` or `boost::mp11::mp_list`. This test case works the same as `TEMPLATE_TEST_CASE_METHOD`,
only difference is the source of types. This allows you to reuse the template type list in multiple test cases.

View File

@@ -71,6 +71,8 @@ CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
## Enums
> Introduced in Catch 2.8.0.
Enums that already have a `<<` overload for `std::ostream` will convert to strings as expected.
If you only need to convert enums to strings for test reporting purposes you can provide a `StringMaker` specialisations as any other type.
However, as a convenience, Catch provides the `REGISTER_ENUM` helper macro that will generate the `StringMaker` specialiation for you with minimal code.
@@ -108,6 +110,8 @@ TEST_CASE() {
## Floating point precision
> [Introduced](https://github.com/catchorg/Catch2/issues/1614) in Catch 2.8.0.
Catch provides a built-in `StringMaker` specialization for both `float`
and `double`. By default, it uses what we think is a reasonable precision,
but you can customize it by modifying the `precision` static variable

View File

@@ -10,8 +10,8 @@
#define TWOBLUECUBES_CATCH_HPP_INCLUDED
#define CATCH_VERSION_MAJOR 2
#define CATCH_VERSION_MINOR 9
#define CATCH_VERSION_PATCH 1
#define CATCH_VERSION_MINOR 10
#define CATCH_VERSION_PATCH 2
#ifdef __clang__
# pragma clang system_header

View File

@@ -52,7 +52,8 @@ namespace Detail {
bool Approx::equalityComparisonImpl(const double other) const {
// First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
// Thanks to Richard Harris for his help refining the scaled margin value
return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value)));
return marginComparison(m_value, other, m_margin)
|| marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(std::isinf(m_value)? 0 : m_value)));
}
void Approx::setMargin(double newMargin) {

View File

@@ -45,7 +45,7 @@ namespace Catch {
}
bool AssertionResult::hasExpression() const {
return m_info.capturedExpression[0] != 0;
return !m_info.capturedExpression.empty();
}
bool AssertionResult::hasMessage() const {
@@ -53,16 +53,22 @@ namespace Catch {
}
std::string AssertionResult::getExpression() const {
if( isFalseTest( m_info.resultDisposition ) )
return "!(" + m_info.capturedExpression + ")";
else
return m_info.capturedExpression;
// Possibly overallocating by 3 characters should be basically free
std::string expr; expr.reserve(m_info.capturedExpression.size() + 3);
if (isFalseTest(m_info.resultDisposition)) {
expr += "!(";
}
expr += m_info.capturedExpression;
if (isFalseTest(m_info.resultDisposition)) {
expr += ')';
}
return expr;
}
std::string AssertionResult::getExpressionInMacro() const {
std::string expr;
if( m_info.macroName[0] == 0 )
expr = m_info.capturedExpression;
if( m_info.macroName.empty() )
expr = static_cast<std::string>(m_info.capturedExpression);
else {
expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 );
expr += m_info.macroName;

View File

@@ -10,6 +10,7 @@
#include "catch_capture.hpp"
#include "catch_matchers.h"
#include "catch_matchers_exception.hpp"
#include "catch_matchers_floating.h"
#include "catch_matchers_generic.hpp"
#include "catch_matchers_string.h"

View File

@@ -49,9 +49,15 @@ namespace Catch {
if( !line.empty() && !startsWith( line, '#' ) ) {
if( !startsWith( line, '"' ) )
line = '"' + line + '"';
config.testsOrTags.push_back( line + ',' );
config.testsOrTags.push_back( line );
config.testsOrTags.push_back( "," );
}
}
//Remove comma in the end
if(!config.testsOrTags.empty())
config.testsOrTags.erase( config.testsOrTags.end()-1 );
return ParserResult::ok( ParseResultType::Matched );
};
auto const setTestOrder = [&]( std::string const& order ) {

View File

@@ -15,9 +15,6 @@
namespace Catch {
bool SourceLineInfo::empty() const noexcept {
return file[0] == '\0';
}
bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept {
return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
}

View File

@@ -57,7 +57,7 @@ namespace Catch {
SourceLineInfo( SourceLineInfo&& ) noexcept = default;
SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default;
bool empty() const noexcept;
bool empty() const noexcept { return file[0] == '\0'; }
bool operator == ( SourceLineInfo const& other ) const noexcept;
bool operator < ( SourceLineInfo const& other ) const noexcept;

View File

@@ -70,6 +70,11 @@
# define CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
_Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
_Pragma( "clang diagnostic push" ) \
_Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
_Pragma( "clang diagnostic pop" )
#endif // __clang__
@@ -94,6 +99,7 @@
// Android somehow still does not support std::to_string
#if defined(__ANDROID__)
# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
#endif
////////////////////////////////////////////////////////////////////////////////
@@ -115,7 +121,7 @@
// Required for some versions of Cygwin to declare gettimeofday
// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
# define _BSD_SOURCE
// some versions of cygwin (most) do not support std::to_string. Use the libstd check.
// some versions of cygwin (most) do not support std::to_string. Use the libstd check.
// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
&& !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
@@ -184,41 +190,55 @@
#define CATCH_INTERNAL_CONFIG_COUNTER
#endif
////////////////////////////////////////////////////////////////////////////////
// Check if string_view is available and usable
// The check is split apart to work around v140 (VS2015) preprocessor issue...
#if defined(__has_include)
#if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
# define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
#endif
#endif
////////////////////////////////////////////////////////////////////////////////
// Check if optional is available and usable
#if defined(__has_include)
# if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
# define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
# endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
#endif // __has_include
////////////////////////////////////////////////////////////////////////////////
// Check if variant is available and usable
// RTX is a special version of Windows that is real time.
// This means that it is detected as Windows, but does not provide
// the same set of capabilities as real Windows does.
#if defined(UNDER_RTSS) || defined(RTX64_BUILD)
#define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
#define CATCH_INTERNAL_CONFIG_NO_ASYNC
#define CATCH_CONFIG_COLOUR_NONE
#endif
#if defined(__UCLIBC__)
#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER
#endif
// Various stdlib support checks that require __has_include
#if defined(__has_include)
# if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
# if defined(__clang__) && (__clang_major__ < 8)
// work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
// fix should be in clang 8, workaround in libstdc++ 8.2
# include <ciso646>
# if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
# define CATCH_CONFIG_NO_CPP17_VARIANT
# else
# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
# endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
# else
# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
# endif // defined(__clang__) && (__clang_major__ < 8)
# endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
#endif // __has_include
// Check if string_view is available and usable
#if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
# define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
#endif
// Check if optional is available and usable
# if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
# define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
# endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
// Check if byte is available and usable
# if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
# define CATCH_INTERNAL_CONFIG_CPP17_BYTE
# endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
// Check if variant is available and usable
# if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
# if defined(__clang__) && (__clang_major__ < 8)
// work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
// fix should be in clang 8, workaround in libstdc++ 8.2
# include <ciso646>
# if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
# define CATCH_CONFIG_NO_CPP17_VARIANT
# else
# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
# endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
# else
# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
# endif // defined(__clang__) && (__clang_major__ < 8)
# endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
#endif // defined(__has_include)
#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
@@ -256,6 +276,11 @@
# define CATCH_CONFIG_CPP17_VARIANT
#endif
#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE)
# define CATCH_CONFIG_CPP17_BYTE
#endif
#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
#endif
@@ -272,10 +297,18 @@
# define CATCH_CONFIG_POLYFILL_ISNAN
#endif
#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC)
#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC)
# define CATCH_CONFIG_USE_ASYNC
#endif
#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE)
# define CATCH_CONFIG_ANDROID_LOGWRITE
#endif
#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
# define CATCH_CONFIG_GLOBAL_NEXTAFTER
#endif
#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
@@ -293,6 +326,19 @@
# define CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS
#endif
#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
# undef CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS
#elif defined(__clang__) && (__clang_major__ < 5)
# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
# undef CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS
#endif
#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS
#endif
#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
#define CATCH_TRY if ((true))
#define CATCH_CATCH_ALL if ((false))

View File

@@ -15,11 +15,23 @@ namespace Catch {
: m_data( data ),
m_stream( openStream() )
{
// We need to trim filter specs to avoid trouble with superfluous
// whitespace (esp. important for bdd macros, as those are manually
// aligned with whitespace).
for (auto& elem : m_data.testsOrTags) {
elem = trim(elem);
}
for (auto& elem : m_data.sectionsToRun) {
elem = trim(elem);
}
TestSpecParser parser(ITagAliasRegistry::get());
if (!data.testsOrTags.empty()) {
if (!m_data.testsOrTags.empty()) {
m_hasTestFilters = true;
for( auto const& testOrTags : data.testsOrTags )
parser.parse( testOrTags );
for (auto const& testOrTags : m_data.testsOrTags) {
parser.parse(testOrTags);
}
}
m_testSpec = parser.testSpec();
}
@@ -32,7 +44,7 @@ namespace Catch {
bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; }
bool Config::listTags() const { return m_data.listTags; }
bool Config::listReporters() const { return m_data.listReporters; }
std::string Config::getProcessName() const { return m_data.processName; }
std::string const& Config::getReporterName() const { return m_data.reporterName; }

View File

@@ -7,6 +7,7 @@
*/
#include "catch_context.h"
#include "catch_common.h"
#include "catch_random_number_generator.h"
namespace Catch {
@@ -59,4 +60,11 @@ namespace Catch {
IContext::~IContext() = default;
IMutableContext::~IMutableContext() = default;
Context::~Context() = default;
SimplePcg32& rng() {
static SimplePcg32 s_rng;
return s_rng;
}
}

View File

@@ -46,6 +46,7 @@ namespace Catch {
{
if( !IMutableContext::currentContext )
IMutableContext::createContext();
// NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
return *IMutableContext::currentContext;
}
@@ -55,6 +56,9 @@ namespace Catch {
}
void cleanUpContext();
class SimplePcg32;
SimplePcg32& rng();
}
#endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED

View File

@@ -7,11 +7,21 @@
*/
#include "catch_debug_console.h"
#include "catch_compiler_capabilities.h"
#include "catch_stream.h"
#include "catch_platform.h"
#include "catch_windows_h_proxy.h"
#ifdef CATCH_PLATFORM_WINDOWS
#if defined(CATCH_CONFIG_ANDROID_LOGWRITE)
#include <android/log.h>
namespace Catch {
void writeToDebugConsole( std::string const& text ) {
__android_log_write( ANDROID_LOG_DEBUG, "Catch", text.c_str() );
}
}
#elif defined(CATCH_PLATFORM_WINDOWS)
namespace Catch {
void writeToDebugConsole( std::string const& text ) {

View File

@@ -38,13 +38,13 @@ namespace Catch {
(Catch::ReusableStringStream() << __VA_ARGS__).str()
#define CATCH_INTERNAL_ERROR(...) \
Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__));
Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__))
#define CATCH_ERROR(...) \
Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ));
Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
#define CATCH_RUNTIME_ERROR(...) \
Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ));
Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
#define CATCH_ENFORCE( condition, ... ) \
do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)

View File

@@ -18,13 +18,25 @@ namespace Catch {
namespace Detail {
std::vector<std::string> parseEnums( StringRef enums ) {
namespace {
// Extracts the actual name part of an enum instance
// In other words, it returns the Blue part of Bikeshed::Colour::Blue
StringRef extractInstanceName(StringRef enumInstance) {
// Find last occurence of ":"
size_t name_start = enumInstance.size();
while (name_start > 0 && enumInstance[name_start - 1] != ':') {
--name_start;
}
return enumInstance.substr(name_start, enumInstance.size() - name_start);
}
}
std::vector<StringRef> parseEnums( StringRef enums ) {
auto enumValues = splitStringRef( enums, ',' );
std::vector<std::string> parsed;
std::vector<StringRef> parsed;
parsed.reserve( enumValues.size() );
for( auto const& enumValue : enumValues ) {
auto identifiers = splitStringRef( enumValue, ':' );
parsed.push_back( Catch::trim( identifiers.back() ) );
parsed.push_back(trim(extractInstanceName(enumValue)));
}
return parsed;
}
@@ -36,7 +48,7 @@ namespace Catch {
if( valueToName.first == value )
return valueToName.second;
}
return "{** unexpected enum value **}";
return "{** unexpected enum value **}"_sr;
}
std::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
@@ -54,10 +66,8 @@ namespace Catch {
}
EnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
auto enumInfo = makeEnumInfo( enumName, allValueNames, values );
EnumInfo* raw = enumInfo.get();
m_enumInfos.push_back( std::move( enumInfo ) );
return *raw;
m_enumInfos.push_back(makeEnumInfo(enumName, allValueNames, values));
return *m_enumInfos.back();
}
} // Detail

View File

@@ -26,7 +26,7 @@ namespace Catch {
EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
};
std::vector<std::string> parseEnums( StringRef enums );
std::vector<StringRef> parseEnums( StringRef enums );
} // Detail

View File

@@ -97,7 +97,7 @@ namespace Catch {
// 32kb for the alternate stack seems to be sufficient. However, this value
// is experimentally determined, so that's not guaranteed.
constexpr static std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;
static constexpr std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;
static SignalDefs signalDefs[] = {
{ SIGINT, "SIGINT - Terminal interrupt signal" },

View File

@@ -70,6 +70,9 @@ namespace Generators {
template<typename T>
class FixedValuesGenerator final : public IGenerator<T> {
static_assert(!std::is_same<T, bool>::value,
"FixedValuesGenerator does not support bools because of std::vector<bool>"
"specialization, use SingleValue Generator instead.");
std::vector<T> m_values;
size_t m_idx = 0;
public:

View File

@@ -91,6 +91,9 @@ namespace Generators {
template <typename T>
class RepeatGenerator : public IGenerator<T> {
static_assert(!std::is_same<T, bool>::value,
"RepeatGenerator currently does not support bools"
"because of std::vector<bool> specialization");
GeneratorWrapper<T> m_generator;
mutable std::vector<T> m_returned;
size_t m_target_repeats;
@@ -205,12 +208,14 @@ namespace Generators {
m_chunk_size(size), m_generator(std::move(generator))
{
m_chunk.reserve(m_chunk_size);
m_chunk.push_back(m_generator.get());
for (size_t i = 1; i < m_chunk_size; ++i) {
if (!m_generator.next()) {
Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk"));
}
if (m_chunk_size != 0) {
m_chunk.push_back(m_generator.get());
for (size_t i = 1; i < m_chunk_size; ++i) {
if (!m_generator.next()) {
Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk"));
}
m_chunk.push_back(m_generator.get());
}
}
}
std::vector<T> const& get() const override {

View File

@@ -10,6 +10,7 @@
#include "catch_context.h"
#include "catch_generators.hpp"
#include "catch_interfaces_config.h"
#include "catch_random_number_generator.h"
#include <random>
@@ -18,14 +19,13 @@ namespace Generators {
template <typename Float>
class RandomFloatingGenerator final : public IGenerator<Float> {
// FIXME: What is the right seed?
std::minstd_rand m_rand;
Catch::SimplePcg32& m_rng;
std::uniform_real_distribution<Float> m_dist;
Float m_current_number;
public:
RandomFloatingGenerator(Float a, Float b):
m_rand(getCurrentContext().getConfig()->rngSeed()),
m_rng(rng()),
m_dist(a, b) {
static_cast<void>(next());
}
@@ -34,20 +34,20 @@ public:
return m_current_number;
}
bool next() override {
m_current_number = m_dist(m_rand);
m_current_number = m_dist(m_rng);
return true;
}
};
template <typename Integer>
class RandomIntegerGenerator final : public IGenerator<Integer> {
std::minstd_rand m_rand;
Catch::SimplePcg32& m_rng;
std::uniform_int_distribution<Integer> m_dist;
Integer m_current_number;
public:
RandomIntegerGenerator(Integer a, Integer b):
m_rand(getCurrentContext().getConfig()->rngSeed()),
m_rng(rng()),
m_dist(a, b) {
static_cast<void>(next());
}
@@ -56,7 +56,7 @@ public:
return m_current_number;
}
bool next() override {
m_current_number = m_dist(m_rand);
m_current_number = m_dist(m_rng);
return true;
}
};
@@ -128,6 +128,46 @@ GeneratorWrapper<T> range(T const& start, T const& end) {
}
template <typename T>
class IteratorGenerator final : public IGenerator<T> {
static_assert(!std::is_same<T, bool>::value,
"IteratorGenerator currently does not support bools"
"because of std::vector<bool> specialization");
std::vector<T> m_elems;
size_t m_current = 0;
public:
template <typename InputIterator, typename InputSentinel>
IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) {
if (m_elems.empty()) {
Catch::throw_exception(GeneratorException("IteratorGenerator received no valid values"));
}
}
T const& get() const override {
return m_elems[m_current];
}
bool next() override {
++m_current;
return m_current != m_elems.size();
}
};
template <typename InputIterator,
typename InputSentinel,
typename ResultType = typename std::iterator_traits<InputIterator>::value_type>
GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) {
return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(from, to));
}
template <typename Container,
typename ResultType = typename Container::value_type>
GeneratorWrapper<ResultType> from_range(Container const& cnt) {
return GeneratorWrapper<ResultType>(pf::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end()));
}
} // namespace Generators
} // namespace Catch

View File

@@ -1,4 +1,4 @@
#include "internal/catch_interfaces_config.h"
#include "catch_interfaces_config.h"
namespace Catch {
IConfig::~IConfig() = default;

View File

@@ -17,7 +17,7 @@ namespace Catch {
namespace Detail {
struct EnumInfo {
StringRef m_name;
std::vector<std::pair<int, std::string>> m_values;
std::vector<std::pair<int, StringRef>> m_values;
~EnumInfo();
@@ -32,6 +32,7 @@ namespace Catch {
template<typename E>
Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int");
std::vector<int> intValues;
intValues.reserve( values.size() );
for( auto enumValue : values )

View File

@@ -1,4 +1,4 @@
#include "internal/catch_interfaces_exception.h"
#include "catch_interfaces_exception.h"
namespace Catch {
IExceptionTranslator::~IExceptionTranslator() = default;

View File

@@ -1,4 +1,4 @@
#include "internal/catch_interfaces_registry_hub.h"
#include "catch_interfaces_registry_hub.h"
namespace Catch {
IRegistryHub::~IRegistryHub() = default;

View File

@@ -214,6 +214,8 @@ namespace Catch {
virtual void noMatchingTestCases( std::string const& spec ) = 0;
virtual void reportInvalidArguments(std::string const&) {}
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;

View File

@@ -1,4 +1,4 @@
#include "internal/catch_interfaces_runner.h"
#include "catch_interfaces_runner.h"
namespace Catch {
IRunner::~IRunner() = default;

View File

@@ -1,4 +1,4 @@
#include "internal/catch_interfaces_testcase.h"
#include "catch_interfaces_testcase.h"
namespace Catch {
ITestInvoker::~ITestInvoker() = default;

View File

@@ -28,6 +28,7 @@ namespace Catch {
virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
};
bool isThrowSafe( TestCase const& testCase, IConfig const& config );
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );

View File

@@ -84,9 +84,18 @@ namespace Catch {
}
std::string TagInfo::all() const {
std::string out;
for( auto const& spelling : spellings )
out += "[" + spelling + "]";
size_t size = 0;
for (auto const& spelling : spellings) {
// Add 2 for the brackes
size += spelling.size() + 2;
}
std::string out; out.reserve(size);
for (auto const& spelling : spellings) {
out += '[';
out += spelling;
out += ']';
}
return out;
}

View File

@@ -44,6 +44,15 @@ namespace Matchers {
virtual bool match( ObjectT const& arg ) const = 0;
};
#if defined(__OBJC__)
// Hack to fix Catch GH issue #1661. Could use id for generic Object support.
// use of const for Object pointers is very uncommon and under ARC it causes some kind of signature mismatch that breaks compilation
template<>
struct MatcherMethod<NSString*> {
virtual bool match( NSString* arg ) const = 0;
};
#endif
#ifdef __clang__
# pragma clang diagnostic pop
#endif

View File

@@ -0,0 +1,30 @@
/*
* Created by Martin Hořeňovský on 13/10/2019.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include "catch_matchers_exception.hpp"
namespace Catch {
namespace Matchers {
namespace Exception {
bool ExceptionMessageMatcher::match(std::exception const& ex) const {
return ex.what() == m_message;
}
std::string ExceptionMessageMatcher::describe() const {
return "exception message matches \"" + m_message + "\"";
}
}
Exception::ExceptionMessageMatcher Message(std::string const& message) {
return Exception::ExceptionMessageMatcher(message);
}
// namespace Exception
} // namespace Matchers
} // namespace Catch

View File

@@ -0,0 +1,36 @@
/*
* Created by Martin Hořeňovský on 13/10/2019.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
#include "catch_matchers.h"
namespace Catch {
namespace Matchers {
namespace Exception {
class ExceptionMessageMatcher : public MatcherBase<std::exception> {
std::string m_message;
public:
ExceptionMessageMatcher(std::string const& message):
m_message(message)
{}
bool match(std::exception const& ex) const override;
std::string describe() const override;
};
} // namespace Exception
Exception::ExceptionMessageMatcher Message(std::string const& message);
} // namespace Matchers
} // namespace Catch
#endif // TWOBLUECUBES_CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED

View File

@@ -11,86 +11,120 @@
#include "catch_to_string.hpp"
#include "catch_tostring.h"
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <sstream>
#include <type_traits>
#include <iomanip>
#include <limits>
namespace Catch {
namespace Matchers {
namespace Floating {
enum class FloatingPointKind : uint8_t {
Float,
Double
};
}
}
}
namespace {
int32_t convert(float f) {
static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated");
int32_t i;
std::memcpy(&i, &f, sizeof(f));
return i;
}
int64_t convert(double d) {
static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated");
int64_t i;
std::memcpy(&i, &d, sizeof(d));
return i;
}
template <typename FP>
bool almostEqualUlps(FP lhs, FP rhs, uint64_t maxUlpDiff) {
// Comparison with NaN should always be false.
// This way we can rule it out before getting into the ugly details
if (Catch::isnan(lhs) || Catch::isnan(rhs)) {
return false;
}
auto lc = convert(lhs);
auto rc = convert(rhs);
if ((lc < 0) != (rc < 0)) {
// Potentially we can have +0 and -0
return lhs == rhs;
}
auto ulpDiff = std::abs(lc - rc);
return static_cast<uint64_t>(ulpDiff) <= maxUlpDiff;
}
} //end anonymous namespace
#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
#if defined(__clang__)
#pragma clang diagnostic push
// The long double overload is currently unused
#pragma clang diagnostic ignored "-Wunused-function"
#endif
float nextafter(float x, float y) {
return ::nextafterf(x, y);
}
double nextafter(double x, double y) {
return ::nextafter(x, y);
}
long double nextafter(long double x, long double y) {
return ::nextafterl(x, y);
}
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#endif // ^^^ CATCH_CONFIG_GLOBAL_NEXTAFTER ^^^
namespace {
template <typename T>
struct Converter;
template <>
struct Converter<float> {
static_assert(sizeof(float) == sizeof(int32_t), "Important ULP matcher assumption violated");
Converter(float f) {
std::memcpy(&i, &f, sizeof(f));
}
int32_t i;
};
template <>
struct Converter<double> {
static_assert(sizeof(double) == sizeof(int64_t), "Important ULP matcher assumption violated");
Converter(double d) {
std::memcpy(&i, &d, sizeof(d));
}
int64_t i;
};
template <typename T>
auto convert(T t) -> Converter<T> {
return Converter<T>(t);
}
template <typename FP>
bool almostEqualUlps(FP lhs, FP rhs, int maxUlpDiff) {
// Comparison with NaN should always be false.
// This way we can rule it out before getting into the ugly details
if (Catch::isnan(lhs) || Catch::isnan(rhs)) {
return false;
}
auto lc = convert(lhs);
auto rc = convert(rhs);
if ((lc.i < 0) != (rc.i < 0)) {
// Potentially we can have +0 and -0
return lhs == rhs;
}
auto ulpDiff = std::abs(lc.i - rc.i);
return ulpDiff <= maxUlpDiff;
}
template <typename FP>
FP step(FP start, FP direction, int steps) {
for (int i = 0; i < steps; ++i) {
FP step(FP start, FP direction, uint64_t steps) {
for (uint64_t i = 0; i < steps; ++i) {
#if defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
start = Catch::nextafter(start, direction);
#else
start = std::nextafter(start, direction);
#endif
}
return start;
}
// Performs equivalent check of std::fabs(lhs - rhs) <= margin
// But without the subtraction to allow for INFINITY in comparison
bool marginComparison(double lhs, double rhs, double margin) {
return (lhs + margin >= rhs) && (rhs + margin >= lhs);
}
template <typename FloatingPoint>
void write(std::ostream& out, FloatingPoint num) {
out << std::scientific
<< std::setprecision(std::numeric_limits<FloatingPoint>::max_digits10 - 1)
<< num;
}
} // end anonymous namespace
namespace Catch {
namespace Matchers {
namespace Floating {
enum class FloatingPointKind : uint8_t {
Float,
Double
};
WithinAbsMatcher::WithinAbsMatcher(double target, double margin)
:m_target{ target }, m_margin{ margin } {
CATCH_ENFORCE(margin >= 0, "Invalid margin: " << margin << '.'
@@ -108,10 +142,11 @@ namespace Floating {
}
WithinUlpsMatcher::WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType)
WithinUlpsMatcher::WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType)
:m_target{ target }, m_ulps{ ulps }, m_type{ baseType } {
CATCH_ENFORCE(ulps >= 0, "Invalid ULP setting: " << ulps << '.'
<< " ULPs have to be non-negative.");
CATCH_ENFORCE(m_type == FloatingPointKind::Double
|| m_ulps < (std::numeric_limits<uint32_t>::max)(),
"Provided ULP is impossibly large for a float comparison.");
}
#if defined(__clang__)
@@ -138,38 +173,59 @@ namespace Floating {
std::string WithinUlpsMatcher::describe() const {
std::stringstream ret;
ret << "is within " << m_ulps << " ULPs of " << ::Catch::Detail::stringify(m_target);
ret << "is within " << m_ulps << " ULPs of ";
if (m_type == FloatingPointKind::Float) {
write(ret, static_cast<float>(m_target));
ret << 'f';
} else {
write(ret, m_target);
}
ret << " ([";
ret << std::fixed << std::setprecision(std::numeric_limits<double>::max_digits10);
if (m_type == FloatingPointKind::Double) {
ret << step(m_target, static_cast<double>(-INFINITY), m_ulps)
<< ", "
<< step(m_target, static_cast<double>(INFINITY), m_ulps);
write(ret, step(m_target, static_cast<double>(-INFINITY), m_ulps));
ret << ", ";
write(ret, step(m_target, static_cast<double>( INFINITY), m_ulps));
} else {
ret << step<float>(static_cast<float>(m_target), -INFINITY, m_ulps)
<< ", "
<< step<float>(static_cast<float>(m_target), INFINITY, m_ulps);
// We have to cast INFINITY to float because of MinGW, see #1782
write(ret, step(static_cast<float>(m_target), static_cast<float>(-INFINITY), m_ulps));
ret << ", ";
write(ret, step(static_cast<float>(m_target), static_cast<float>( INFINITY), m_ulps));
}
ret << "])";
return ret.str();
//return "is within " + Catch::to_string(m_ulps) + " ULPs of " + ::Catch::Detail::stringify(m_target) + ((m_type == FloatingPointKind::Float)? "f" : "");
}
WithinRelMatcher::WithinRelMatcher(double target, double epsilon):
m_target(target),
m_epsilon(epsilon){
CATCH_ENFORCE(m_epsilon >= 0., "Relative comparison with epsilon < 0 does not make sense.");
CATCH_ENFORCE(m_epsilon < 1., "Relative comparison with epsilon >= 1 does not make sense.");
}
bool WithinRelMatcher::match(double const& matchee) const {
const auto relMargin = m_epsilon * (std::max)(std::fabs(matchee), std::fabs(m_target));
return marginComparison(matchee, m_target,
std::isinf(relMargin)? 0 : relMargin);
}
std::string WithinRelMatcher::describe() const {
Catch::ReusableStringStream sstr;
sstr << "and " << m_target << " are within " << m_epsilon * 100. << "% of each other";
return sstr.str();
}
}// namespace Floating
Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff) {
Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff) {
return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Double);
}
Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff) {
Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff) {
return Floating::WithinUlpsMatcher(target, maxUlpDiff, Floating::FloatingPointKind::Float);
}
@@ -177,6 +233,23 @@ Floating::WithinAbsMatcher WithinAbs(double target, double margin) {
return Floating::WithinAbsMatcher(target, margin);
}
Floating::WithinRelMatcher WithinRel(double target, double eps) {
return Floating::WithinRelMatcher(target, eps);
}
Floating::WithinRelMatcher WithinRel(double target) {
return Floating::WithinRelMatcher(target, std::numeric_limits<double>::epsilon() * 100);
}
Floating::WithinRelMatcher WithinRel(float target, float eps) {
return Floating::WithinRelMatcher(target, eps);
}
Floating::WithinRelMatcher WithinRel(float target) {
return Floating::WithinRelMatcher(target, std::numeric_limits<float>::epsilon() * 100);
}
} // namespace Matchers
} // namespace Catch

View File

@@ -9,9 +9,6 @@
#include "catch_matchers.h"
#include <type_traits>
#include <cmath>
namespace Catch {
namespace Matchers {
@@ -29,23 +26,43 @@ namespace Matchers {
};
struct WithinUlpsMatcher : MatcherBase<double> {
WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType);
WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType);
bool match(double const& matchee) const override;
std::string describe() const override;
private:
double m_target;
int m_ulps;
uint64_t m_ulps;
FloatingPointKind m_type;
};
// Given IEEE-754 format for floats and doubles, we can assume
// that float -> double promotion is lossless. Given this, we can
// assume that if we do the standard relative comparison of
// |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get
// the same result if we do this for floats, as if we do this for
// doubles that were promoted from floats.
struct WithinRelMatcher : MatcherBase<double> {
WithinRelMatcher(double target, double epsilon);
bool match(double const& matchee) const override;
std::string describe() const override;
private:
double m_target;
double m_epsilon;
};
} // namespace Floating
// The following functions create the actual matcher objects.
// This allows the types to be inferred
Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff);
Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff);
Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff);
Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff);
Floating::WithinAbsMatcher WithinAbs(double target, double margin);
Floating::WithinRelMatcher WithinRel(double target, double eps);
// defaults epsilon to 100*numeric_limits<double>::epsilon()
Floating::WithinRelMatcher WithinRel(double target);
Floating::WithinRelMatcher WithinRel(float target, float eps);
// defaults epsilon to 100*numeric_limits<float>::epsilon()
Floating::WithinRelMatcher WithinRel(float target);
} // namespace Matchers
} // namespace Catch

View File

@@ -113,7 +113,7 @@ namespace Catch {
case ',':
if (start != pos && openings.size() == 0) {
m_messages.emplace_back(macroName, lineInfo, resultType);
m_messages.back().message = trimmed(start, pos);
m_messages.back().message = static_cast<std::string>(trimmed(start, pos));
m_messages.back().message += " := ";
start = pos;
}
@@ -121,7 +121,7 @@ namespace Catch {
}
assert(openings.size() == 0 && "Mismatched openings");
m_messages.emplace_back(macroName, lineInfo, resultType);
m_messages.back().message = trimmed(start, names.size() - 1);
m_messages.back().message = static_cast<std::string>(trimmed(start, names.size() - 1));
m_messages.back().message += " := ";
}
Capturer::~Capturer() {

View File

@@ -116,7 +116,7 @@ namespace Catch {
arcSafeRelease( m_substr );
}
bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return false;
}
@@ -126,7 +126,7 @@ namespace Catch {
struct Equals : StringHolder {
Equals( NSString* substr ) : StringHolder( substr ){}
bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str isEqualToString:m_substr];
}
@@ -139,7 +139,7 @@ namespace Catch {
struct Contains : StringHolder {
Contains( NSString* substr ) : StringHolder( substr ){}
bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location != NSNotFound;
}
@@ -152,7 +152,7 @@ namespace Catch {
struct StartsWith : StringHolder {
StartsWith( NSString* substr ) : StringHolder( substr ){}
bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location == 0;
}
@@ -164,7 +164,7 @@ namespace Catch {
struct EndsWith : StringHolder {
EndsWith( NSString* substr ) : StringHolder( substr ){}
bool match( NSString* const& str ) const override {
bool match( NSString* str ) const override {
return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location == [str length] - [m_substr length];
}

View File

@@ -102,35 +102,49 @@
template<typename...> struct TypeList {};\
template<typename...Ts>\
constexpr auto get_wrapper() noexcept -> TypeList<Ts...> { return {}; }\
template<template<typename...> class...> struct TemplateTypeList{};\
template<template<typename...> class...Cs>\
constexpr auto get_wrapper() noexcept -> TemplateTypeList<Cs...> { return {}; }\
template<typename...>\
struct append;\
template<typename...>\
struct rewrap;\
template<template<typename...> class, typename...>\
struct create;\
template<template<typename...> class, typename>\
struct convert;\
\
template<template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2> \
constexpr auto append(L1<E1...>, L2<E2...>) noexcept -> L1<E1...,E2...> { return {}; }\
template<typename T> \
struct append<T> { using type = T; };\
template< template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2, typename...Rest>\
constexpr auto append(L1<E1...>, L2<E2...>, Rest...) noexcept -> decltype(append(L1<E1...,E2...>{}, Rest{}...)) { return {}; }\
struct append<L1<E1...>, L2<E2...>, Rest...> { using type = typename append<L1<E1...,E2...>, Rest...>::type; };\
template< template<typename...> class L1, typename...E1, typename...Rest>\
constexpr auto append(L1<E1...>, TypeList<mpl_::na>, Rest...) noexcept -> L1<E1...> { return {}; }\
struct append<L1<E1...>, TypeList<mpl_::na>, Rest...> { using type = L1<E1...>; };\
\
template< template<typename...> class Container, template<typename...> class List, typename...elems>\
constexpr auto rewrap(List<elems...>) noexcept -> TypeList<Container<elems...>> { return {}; }\
struct rewrap<TemplateTypeList<Container>, List<elems...>> { using type = TypeList<Container<elems...>>; };\
template< template<typename...> class Container, template<typename...> class List, class...Elems, typename...Elements>\
constexpr auto rewrap(List<Elems...>,Elements...) noexcept -> decltype(append(TypeList<Container<Elems...>>{}, rewrap<Container>(Elements{}...))) { return {}; }\
struct rewrap<TemplateTypeList<Container>, List<Elems...>, Elements...> { using type = typename append<TypeList<Container<Elems...>>, typename rewrap<TemplateTypeList<Container>, Elements...>::type>::type; };\
\
template<template <typename...> class Final, template< typename...> class...Containers, typename...Types>\
constexpr auto create(TypeList<Types...>) noexcept -> decltype(append(Final<>{}, rewrap<Containers>(Types{}...)...)) { return {}; }\
struct create<Final, TemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<TemplateTypeList<Containers>, Types...>::type...>::type; };\
template<template <typename...> class Final, template <typename...> class List, typename...Ts>\
constexpr auto convert(List<Ts...>) noexcept -> decltype(append(Final<>{},TypeList<Ts>{}...)) { return {}; }
struct convert<Final, List<Ts...>> { using type = typename append<Final<>,TypeList<Ts>...>::type; };
#define INTERNAL_CATCH_NTTP_1(signature, ...)\
template<INTERNAL_CATCH_REMOVE_PARENS(signature)> struct Nttp{};\
template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \
template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...> struct NttpTemplateTypeList{};\
template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Cs>\
constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList<Cs...> { return {}; } \
\
template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\
constexpr auto rewrap(List<__VA_ARGS__>) noexcept -> TypeList<Container<__VA_ARGS__>> { return {}; }\
struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>> { using type = TypeList<Container<__VA_ARGS__>>; };\
template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\
constexpr auto rewrap(List<__VA_ARGS__>,Elements...elems) noexcept -> decltype(append(TypeList<Container<__VA_ARGS__>>{}, rewrap<Container>(elems...))) { return {}; }\
struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>, Elements...> { using type = typename append<TypeList<Container<__VA_ARGS__>>, typename rewrap<NttpTemplateTypeList<Container>, Elements...>::type>::type; };\
template<template <typename...> class Final, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Containers, typename...Types>\
constexpr auto create(TypeList<Types...>) noexcept -> decltype(append(Final<>{}, rewrap<Containers>(Types{}...)...)) { return {}; }
struct create<Final, NttpTemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<NttpTemplateTypeList<Containers>, Types...>::type...>::type; };
#define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName)
#define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\

View File

@@ -7,23 +7,67 @@
#include "catch_random_number_generator.h"
#include "catch_context.h"
#include "catch_run_context.h"
#include "catch_interfaces_config.h"
namespace Catch {
std::mt19937& rng() {
static std::mt19937 s_rng;
return s_rng;
namespace {
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4146) // we negate uint32 during the rotate
#endif
// Safe rotr implementation thanks to John Regehr
uint32_t rotate_right(uint32_t val, uint32_t count) {
const uint32_t mask = 31;
count &= mask;
return (val >> count) | (val << (-count & mask));
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}
SimplePcg32::SimplePcg32(result_type seed_) {
seed(seed_);
}
void seedRng( IConfig const& config ) {
if( config.rngSeed() != 0 ) {
std::srand( config.rngSeed() );
rng().seed( config.rngSeed() );
void SimplePcg32::seed(result_type seed_) {
m_state = 0;
(*this)();
m_state += seed_;
(*this)();
}
void SimplePcg32::discard(uint64_t skip) {
// We could implement this to run in O(log n) steps, but this
// should suffice for our use case.
for (uint64_t s = 0; s < skip; ++s) {
static_cast<void>((*this)());
}
}
unsigned int rngSeed() {
return getCurrentContext().getConfig()->rngSeed();
SimplePcg32::result_type SimplePcg32::operator()() {
// prepare the output value
const uint32_t xorshifted = static_cast<uint32_t>(((m_state >> 18u) ^ m_state) >> 27u);
const auto output = rotate_right(xorshifted, m_state >> 59u);
// advance state
m_state = m_state * 6364136223846793005ULL + s_inc;
return output;
}
bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs) {
return lhs.m_state == rhs.m_state;
}
bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs) {
return lhs.m_state != rhs.m_state;
}
}

View File

@@ -7,17 +7,52 @@
#ifndef TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED
#define TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED
#include <algorithm>
#include <random>
#include <cstdint>
namespace Catch {
struct IConfig;
// This is a simple implementation of C++11 Uniform Random Number
// Generator. It does not provide all operators, because Catch2
// does not use it, but it should behave as expected inside stdlib's
// distributions.
// The implementation is based on the PCG family (http://pcg-random.org)
class SimplePcg32 {
using state_type = std::uint64_t;
public:
using result_type = std::uint32_t;
static constexpr result_type (min)() {
return 0;
}
static constexpr result_type (max)() {
return static_cast<result_type>(-1);
}
std::mt19937& rng();
void seedRng( IConfig const& config );
unsigned int rngSeed();
// Provide some default initial state for the default constructor
SimplePcg32():SimplePcg32(0xed743cc4U) {}
}
explicit SimplePcg32(result_type seed_);
void seed(result_type seed_);
void discard(uint64_t skip);
result_type operator()();
private:
friend bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
friend bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
// In theory we also need operator<< and operator>>
// In practice we do not use them, so we will skip them for now
std::uint64_t m_state;
// This part of the state determines which "stream" of the numbers
// is chosen -- we take it as a constant for Catch2, so we only
// need to deal with seeding the main state.
// Picked by reading 8 bytes from `/dev/random` :-)
static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL;
};
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED

View File

@@ -63,9 +63,9 @@ namespace Catch {
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
#define CATCH_REGISTER_LISTENER( listenerType ) \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
#else // CATCH_CONFIG_DISABLE
#define CATCH_REGISTER_REPORTER(name, reporterType)

View File

@@ -230,7 +230,7 @@ namespace Catch {
m_unfinishedSections.push_back(endInfo);
}
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
void RunContext::benchmarkPreparing(std::string const& name) {
m_reporter->benchmarkPreparing(name);
@@ -279,7 +279,7 @@ namespace Catch {
// Don't rebuild the result -- the stringification itself can cause more fatal errors
// Instead, fake a result data.
AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } );
tempResult.message = message;
tempResult.message = static_cast<std::string>(message);
AssertionResult result(m_lastAssertionInfo, tempResult);
assertionEnded(result);
@@ -442,7 +442,7 @@ namespace Catch {
m_lastAssertionInfo = info;
AssertionResultData data( resultType, LazyExpression( false ) );
data.message = message;
data.message = static_cast<std::string>(message);
AssertionResult assertionResult{ m_lastAssertionInfo, data };
assertionEnded( assertionResult );
if( !assertionResult.isOk() )
@@ -506,4 +506,16 @@ namespace Catch {
else
CATCH_INTERNAL_ERROR("No result capture instance");
}
void seedRng(IConfig const& config) {
if (config.rngSeed() != 0) {
std::srand(config.rngSeed());
rng().seed(config.rngSeed());
}
}
unsigned int rngSeed() {
return getCurrentContext().getConfig()->rngSeed();
}
}

View File

@@ -151,6 +151,8 @@ namespace Catch {
bool m_includeSuccessfulResults;
};
void seedRng(IConfig const& config);
unsigned int rngSeed();
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED

View File

@@ -25,6 +25,8 @@
#include <cstdlib>
#include <iomanip>
#include <set>
#include <iterator>
namespace Catch {
@@ -58,46 +60,61 @@ namespace Catch {
return ret;
}
Catch::Totals runTests(std::shared_ptr<Config> const& config) {
auto reporter = makeReporter(config);
RunContext context(config, std::move(reporter));
Totals totals;
context.testGroupStarting(config->name(), 1, 1);
TestSpec testSpec = config->testSpec();
auto const& allTestCases = getAllTestCasesSorted(*config);
for (auto const& testCase : allTestCases) {
bool matching = (!testSpec.hasFilters() && !testCase.isHidden()) ||
(testSpec.hasFilters() && matchTest(testCase, testSpec, *config));
if (!context.aborting() && matching)
totals += context.runTest(testCase);
else
context.reporter().skipTest(testCase);
class TestGroup {
public:
explicit TestGroup(std::shared_ptr<Config> const& config)
: m_config{config}
, m_context{config, makeReporter(config)}
{
auto const& allTestCases = getAllTestCasesSorted(*m_config);
m_matches = m_config->testSpec().matchesByFilter(allTestCases, *m_config);
auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
if (m_matches.empty() && invalidArgs.empty()) {
for (auto const& test : allTestCases)
if (!test.isHidden())
m_tests.emplace(&test);
} else {
for (auto const& match : m_matches)
m_tests.insert(match.tests.begin(), match.tests.end());
}
}
if (config->warnAboutNoTests() && totals.testCases.total() == 0) {
ReusableStringStream testConfig;
bool first = true;
for (const auto& input : config->getTestsOrTags()) {
if (!first) { testConfig << ' '; }
first = false;
testConfig << input;
Totals execute() {
auto const& invalidArgs = m_config->testSpec().getInvalidArgs();
Totals totals;
m_context.testGroupStarting(m_config->name(), 1, 1);
for (auto const& testCase : m_tests) {
if (!m_context.aborting())
totals += m_context.runTest(*testCase);
else
m_context.reporter().skipTest(*testCase);
}
context.reporter().noMatchingTestCases(testConfig.str());
totals.error = -1;
for (auto const& match : m_matches) {
if (match.tests.empty()) {
m_context.reporter().noMatchingTestCases(match.name);
totals.error = -1;
}
}
if (!invalidArgs.empty()) {
for (auto const& invalidArg: invalidArgs)
m_context.reporter().reportInvalidArguments(invalidArg);
}
m_context.testGroupEnded(m_config->name(), totals, 1, 1);
return totals;
}
context.testGroupEnded(config->name(), totals, 1, 1);
return totals;
}
private:
using Tests = std::set<TestCase const*>;
std::shared_ptr<Config> m_config;
RunContext m_context;
Tests m_tests;
TestSpec::Matches m_matches;
};
void applyFilenamesAsTags(Catch::IConfig const& config) {
auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config));
@@ -166,7 +183,7 @@ namespace Catch {
}
void Session::libIdentify() {
Catch::cout()
<< std::left << std::setw(16) << "description: " << "A Catch test executable\n"
<< std::left << std::setw(16) << "description: " << "A Catch2 test executable\n"
<< std::left << std::setw(16) << "category: " << "testframework\n"
<< std::left << std::setw(16) << "framework: " << "Catch Test\n"
<< std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
@@ -197,7 +214,7 @@ namespace Catch {
return 0;
}
#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE)
#if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
int Session::applyCommandLine( int argc, wchar_t const * const * argv ) {
char **utf8Argv = new char *[ argc ];
@@ -274,7 +291,12 @@ namespace Catch {
if( Option<std::size_t> listed = list( m_config ) )
return static_cast<int>( *listed );
auto totals = runTests( m_config );
TestGroup tests { m_config };
auto const totals = tests.execute();
if( m_config->warnAboutNoTests() && totals.error == -1 )
return 2;
// Note that on unices only the lower 8 bits are usually used, clamping
// the return value to 255 prevents false negative when some multiple
// of 256 tests has failed

View File

@@ -26,7 +26,7 @@ namespace Catch {
void libIdentify();
int applyCommandLine( int argc, char const * const * argv );
#if defined(CATCH_CONFIG_WCHAR) && defined(WIN32) && defined(UNICODE)
#if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
int applyCommandLine( int argc, wchar_t const * const * argv );
#endif

View File

@@ -53,6 +53,18 @@ namespace Catch {
return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
}
StringRef trim(StringRef ref) {
const auto is_ws = [](char c) {
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
};
size_t real_begin = 0;
while (real_begin < ref.size() && is_ws(ref[real_begin])) { ++real_begin; }
size_t real_end = ref.size();
while (real_end > real_begin && is_ws(ref[real_end - 1])) { --real_end; }
return ref.substr(real_begin, real_end - real_begin);
}
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
bool replaced = false;
std::size_t i = str.find( replaceThis );

View File

@@ -22,7 +22,10 @@ namespace Catch {
bool contains( std::string const& s, std::string const& infix );
void toLowerInPlace( std::string& s );
std::string toLower( std::string const& s );
//! Returns a new string without whitespace at the start/end
std::string trim( std::string const& str );
//! Returns a substring of the original ref without whitespace. Beware lifetimes!
StringRef trim(StringRef ref);
// !!! Be aware, returns refs into original string - make sure original string outlives them
std::vector<StringRef> splitStringRef( StringRef str, char delimiter );

View File

@@ -17,21 +17,11 @@
#include <cstring>
#include <cstdint>
namespace {
const uint32_t byte_2_lead = 0xC0;
const uint32_t byte_3_lead = 0xE0;
const uint32_t byte_4_lead = 0xF0;
}
namespace Catch {
StringRef::StringRef( char const* rawChars ) noexcept
: StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
{}
StringRef::operator std::string() const {
return std::string( m_start, m_size );
}
void StringRef::swap( StringRef& other ) noexcept {
std::swap( m_start, other.m_start );
std::swap( m_size, other.m_size );
@@ -78,40 +68,6 @@ namespace Catch {
return !operator==( other );
}
auto StringRef::operator[](size_type index) const noexcept -> char {
return m_start[index];
}
auto StringRef::numberOfCharacters() const noexcept -> size_type {
size_type noChars = m_size;
// Make adjustments for uft encodings
for( size_type i=0; i < m_size; ++i ) {
char c = m_start[i];
if( ( c & byte_2_lead ) == byte_2_lead ) {
noChars--;
if (( c & byte_3_lead ) == byte_3_lead )
noChars--;
if( ( c & byte_4_lead ) == byte_4_lead )
noChars--;
}
}
return noChars;
}
auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string {
std::string str;
str.reserve( lhs.size() + rhs.size() );
str += lhs;
str += rhs;
return str;
}
auto operator + ( StringRef const& lhs, const char* rhs ) -> std::string {
return std::string( lhs ) + std::string( rhs );
}
auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string {
return std::string( lhs ) + std::string( rhs );
}
auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& {
return os.write(str.currentData(), str.size());
}

View File

@@ -10,6 +10,7 @@
#include <cstddef>
#include <string>
#include <iosfwd>
#include <cassert>
namespace Catch {
@@ -23,6 +24,7 @@ namespace Catch {
class StringRef {
public:
using size_type = std::size_t;
using const_iterator = const char*;
private:
friend struct StringRefTestAccess;
@@ -78,7 +80,9 @@ namespace Catch {
return *this;
}
operator std::string() const;
explicit operator std::string() const {
return std::string(m_start, m_size);
}
void swap( StringRef& other ) noexcept;
@@ -86,7 +90,10 @@ namespace Catch {
auto operator == ( StringRef const& other ) const noexcept -> bool;
auto operator != ( StringRef const& other ) const noexcept -> bool;
auto operator[] ( size_type index ) const noexcept -> char;
auto operator[] ( size_type index ) const noexcept -> char {
assert(index < m_size);
return m_start[index];
}
public: // named queries
auto empty() const noexcept -> bool {
@@ -96,7 +103,6 @@ namespace Catch {
return m_size;
}
auto numberOfCharacters() const noexcept -> size_type;
auto c_str() const -> char const*;
public: // substrings and searches
@@ -106,15 +112,15 @@ namespace Catch {
// Note that the pointer can change when if the StringRef is a substring
auto currentData() const noexcept -> char const*;
public: // iterators
const_iterator begin() const { return m_start; }
const_iterator end() const { return m_start + m_size; }
private: // ownership queries - may not be consistent between calls
auto isOwned() const noexcept -> bool;
auto isSubstring() const noexcept -> bool;
};
auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string;
auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string;
auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string;
auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;

View File

@@ -59,8 +59,7 @@ namespace Catch {
std::vector<std::string> tags;
std::string desc, tag;
bool inTag = false;
std::string _descOrTags = nameAndTags.tags;
for (char c : _descOrTags) {
for (char c : nameAndTags.tags) {
if( !inTag ) {
if( c == '[' )
inTag = true;
@@ -93,7 +92,7 @@ namespace Catch {
tags.push_back( "." );
}
TestCaseInfo info( nameAndTags.name, _className, desc, tags, _lineInfo );
TestCaseInfo info( static_cast<std::string>(nameAndTags.name), _className, desc, tags, _lineInfo );
return TestCase( _testCase, std::move(info) );
}

View File

@@ -11,6 +11,7 @@
#include "catch_enforce.h"
#include "catch_interfaces_registry_hub.h"
#include "catch_random_number_generator.h"
#include "catch_run_context.h"
#include "catch_string_manip.h"
#include "catch_test_case_info.h"
@@ -36,8 +37,13 @@ namespace Catch {
}
return sorted;
}
bool isThrowSafe( TestCase const& testCase, IConfig const& config ) {
return !testCase.throws() || config.allowThrows();
}
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() );
return testSpec.matches( testCase ) && isThrowSafe( testCase, config );
}
void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
@@ -100,7 +106,7 @@ namespace Catch {
}
std::string extractClassName( StringRef const& classOrQualifiedMethodName ) {
std::string className = classOrQualifiedMethodName;
std::string className(classOrQualifiedMethodName);
if( startsWith( className, '&' ) )
{
std::size_t lastColons = className.rfind( "::" );

View File

@@ -23,6 +23,8 @@ namespace Catch {
struct IConfig;
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases );
bool isThrowSafe( TestCase const& testCase, IConfig const& config );
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions );

View File

@@ -8,6 +8,7 @@
#include "catch_test_case_tracker.h"
#include "catch_enforce.h"
#include "catch_string_manip.h"
#include <algorithm>
#include <cassert>
@@ -139,7 +140,7 @@ namespace TestCaseTracking {
m_runState = CompletedSuccessfully;
break;
case ExecutingChildren:
if( m_children.empty() || m_children.back()->isComplete() )
if( std::all_of(m_children.begin(), m_children.end(), [](ITrackerPtr const& t){ return t->isComplete(); }) )
m_runState = CompletedSuccessfully;
break;
@@ -174,7 +175,8 @@ namespace TestCaseTracking {
}
SectionTracker::SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
: TrackerBase( nameAndLocation, ctx, parent )
: TrackerBase( nameAndLocation, ctx, parent ),
m_trimmed_name(trim(nameAndLocation.name))
{
if( parent ) {
while( !parent->isSectionTracker() )
@@ -188,12 +190,11 @@ namespace TestCaseTracking {
bool SectionTracker::isComplete() const {
bool complete = true;
if ((m_filters.empty() || m_filters[0] == "") ||
std::find(m_filters.begin(), m_filters.end(),
m_nameAndLocation.name) != m_filters.end())
if ((m_filters.empty() || m_filters[0] == "")
|| std::find(m_filters.begin(), m_filters.end(), m_trimmed_name) != m_filters.end()) {
complete = TrackerBase::isComplete();
}
return complete;
}
bool SectionTracker::isSectionTracker() const { return true; }
@@ -217,12 +218,13 @@ namespace TestCaseTracking {
}
void SectionTracker::tryOpen() {
if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) )
if( !isComplete() )
open();
}
void SectionTracker::addInitialFilters( std::vector<std::string> const& filters ) {
if( !filters.empty() ) {
m_filters.reserve( m_filters.size() + filters.size() + 2 );
m_filters.push_back(""); // Root - should never be consulted
m_filters.push_back(""); // Test Case - not a section filter
m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
@@ -230,7 +232,7 @@ namespace TestCaseTracking {
}
void SectionTracker::addNextFilters( std::vector<std::string> const& filters ) {
if( filters.size() > 1 )
m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() );
m_filters.insert( m_filters.end(), filters.begin()+1, filters.end() );
}
} // namespace TestCaseTracking

View File

@@ -133,6 +133,7 @@ namespace TestCaseTracking {
class SectionTracker : public TrackerBase {
std::vector<std::string> m_filters;
std::string m_trimmed_name;
public:
SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );

View File

@@ -12,7 +12,6 @@
#include "catch_interfaces_testcase.h"
#include "catch_compiler_capabilities.h"
#include "catch_stringref.h"
#include "catch_type_traits.hpp"
#include "catch_preprocessor.hpp"
#include "catch_meta.hpp"
@@ -143,6 +142,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
namespace {\
namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
@@ -166,6 +166,7 @@ struct AutoReg : NonCopyable {
}\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
@@ -187,6 +188,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> static void TestFuncName(); \
namespace {\
namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
@@ -204,7 +206,7 @@ struct AutoReg : NonCopyable {
} \
}; \
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
using TestInit = decltype(create<TestName, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>(TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>{})); \
using TestInit = typename create<TestName, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type; \
TestInit t; \
t.reg_tests(); \
return 0; \
@@ -213,6 +215,7 @@ struct AutoReg : NonCopyable {
} \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \
static void TestFuncName()
@@ -234,6 +237,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> static void TestFunc(); \
namespace {\
namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
@@ -247,13 +251,14 @@ struct AutoReg : NonCopyable {
} \
};\
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
using TestInit = decltype(convert<TestName>(TmplList {})); \
using TestInit = typename convert<TestName, TmplList>::type; \
TestInit t; \
t.reg_tests(); \
return 0; \
}(); \
}}\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \
static void TestFunc()
@@ -264,6 +269,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
namespace {\
namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
INTERNAL_CATCH_TYPE_GEN\
@@ -287,6 +293,7 @@ struct AutoReg : NonCopyable {
}\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS\
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS\
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS\
INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
@@ -308,6 +315,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \
struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
void test();\
@@ -328,7 +336,7 @@ struct AutoReg : NonCopyable {
}\
};\
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
using TestInit = decltype(create<TestNameClass, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>(TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>{}));\
using TestInit = typename create<TestNameClass, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type;\
TestInit t;\
t.reg_tests();\
return 0;\
@@ -337,6 +345,7 @@ struct AutoReg : NonCopyable {
}\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \
void TestName<TestType>::test()
@@ -358,6 +367,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \
struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
void test();\
@@ -374,13 +384,14 @@ struct AutoReg : NonCopyable {
}\
};\
static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
using TestInit = decltype(convert<TestNameClass>(TmplList {}));\
using TestInit = typename convert<TestNameClass, TmplList>::type;\
TestInit t;\
t.reg_tests();\
return 0;\
}(); \
}}\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \
void TestName<TestType>::test()

View File

@@ -7,6 +7,7 @@
#include "catch_test_spec.h"
#include "catch_string_manip.h"
#include "catch_interfaces_config.h"
#include <algorithm>
#include <string>
@@ -15,45 +16,84 @@
namespace Catch {
TestSpec::Pattern::~Pattern() = default;
TestSpec::NamePattern::~NamePattern() = default;
TestSpec::TagPattern::~TagPattern() = default;
TestSpec::ExcludedPattern::~ExcludedPattern() = default;
TestSpec::NamePattern::NamePattern( std::string const& name )
: m_wildcardPattern( toLower( name ), CaseSensitive::No )
TestSpec::Pattern::Pattern( std::string const& name )
: m_name( name )
{}
bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const {
return m_wildcardPattern.matches( toLower( testCase.name ) );
TestSpec::Pattern::~Pattern() = default;
std::string const& TestSpec::Pattern::name() const {
return m_name;
}
TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
TestSpec::NamePattern::NamePattern( std::string const& name, std::string const& filterString )
: Pattern( filterString )
, m_wildcardPattern( toLower( name ), CaseSensitive::No )
{}
bool TestSpec::NamePattern::matches( TestCaseInfo const& testCase ) const {
return m_wildcardPattern.matches( testCase.name );
}
TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString )
: Pattern( filterString )
, m_tag( toLower( tag ) )
{}
bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
return std::find(begin(testCase.lcaseTags),
end(testCase.lcaseTags),
m_tag) != end(testCase.lcaseTags);
}
TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern )
: Pattern( underlyingPattern->name() )
, m_underlyingPattern( underlyingPattern )
{}
bool TestSpec::ExcludedPattern::matches( TestCaseInfo const& testCase ) const {
return !m_underlyingPattern->matches( testCase );
}
bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const {
// All patterns in a filter must match for the filter to be a match
for( auto const& pattern : m_patterns ) {
if( !pattern->matches( testCase ) )
return false;
}
return true;
return std::all_of( m_patterns.begin(), m_patterns.end(), [&]( PatternPtr const& p ){ return p->matches( testCase ); } );
}
std::string TestSpec::Filter::name() const {
std::string name;
for( auto const& p : m_patterns )
name += p->name();
return name;
}
bool TestSpec::hasFilters() const {
return !m_filters.empty();
}
bool TestSpec::matches( TestCaseInfo const& testCase ) const {
// A TestSpec matches if any filter matches
for( auto const& filter : m_filters )
if( filter.matches( testCase ) )
return true;
return false;
return std::any_of( m_filters.begin(), m_filters.end(), [&]( Filter const& f ){ return f.matches( testCase ); } );
}
TestSpec::Matches TestSpec::matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const
{
Matches matches( m_filters.size() );
std::transform( m_filters.begin(), m_filters.end(), matches.begin(), [&]( Filter const& filter ){
std::vector<TestCase const*> currentMatches;
for( auto const& test : testCases )
if( isThrowSafe( test, config ) && filter.matches( test ) )
currentMatches.emplace_back( &test );
return FilterMatch{ filter.name(), currentMatches };
} );
return matches;
}
const TestSpec::vectorStrings& TestSpec::getInvalidArgs() const{
return (m_invalidArgs);
}
}

View File

@@ -22,17 +22,23 @@
namespace Catch {
struct IConfig;
class TestSpec {
struct Pattern {
class Pattern {
public:
explicit Pattern( std::string const& name );
virtual ~Pattern();
virtual bool matches( TestCaseInfo const& testCase ) const = 0;
std::string const& name() const;
private:
std::string const m_name;
};
using PatternPtr = std::shared_ptr<Pattern>;
class NamePattern : public Pattern {
public:
NamePattern( std::string const& name );
virtual ~NamePattern();
explicit NamePattern( std::string const& name, std::string const& filterString );
bool matches( TestCaseInfo const& testCase ) const override;
private:
WildcardPattern m_wildcardPattern;
@@ -40,8 +46,7 @@ namespace Catch {
class TagPattern : public Pattern {
public:
TagPattern( std::string const& tag );
virtual ~TagPattern();
explicit TagPattern( std::string const& tag, std::string const& filterString );
bool matches( TestCaseInfo const& testCase ) const override;
private:
std::string m_tag;
@@ -49,8 +54,7 @@ namespace Catch {
class ExcludedPattern : public Pattern {
public:
ExcludedPattern( PatternPtr const& underlyingPattern );
virtual ~ExcludedPattern();
explicit ExcludedPattern( PatternPtr const& underlyingPattern );
bool matches( TestCaseInfo const& testCase ) const override;
private:
PatternPtr m_underlyingPattern;
@@ -60,15 +64,25 @@ namespace Catch {
std::vector<PatternPtr> m_patterns;
bool matches( TestCaseInfo const& testCase ) const;
std::string name() const;
};
public:
struct FilterMatch {
std::string name;
std::vector<TestCase const*> tests;
};
using Matches = std::vector<FilterMatch>;
using vectorStrings = std::vector<std::string>;
bool hasFilters() const;
bool matches( TestCaseInfo const& testCase ) const;
Matches matchesByFilter( std::vector<TestCase> const& testCases, IConfig const& config ) const;
const vectorStrings & getInvalidArgs() const;
private:
std::vector<Filter> m_filters;
std::vector<std::string> m_invalidArgs;
friend class TestSpecParser;
};
}

View File

@@ -7,6 +7,7 @@
#include "catch_test_spec_parser.h"
namespace Catch {
TestSpecParser::TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {}
@@ -14,64 +15,136 @@ namespace Catch {
TestSpecParser& TestSpecParser::parse( std::string const& arg ) {
m_mode = None;
m_exclusion = false;
m_start = std::string::npos;
m_arg = m_tagAliases->expandAliases( arg );
m_escapeChars.clear();
m_substring.reserve(m_arg.size());
m_patternName.reserve(m_arg.size());
m_realPatternPos = 0;
for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
visitChar( m_arg[m_pos] );
if( m_mode == Name )
addPattern<TestSpec::NamePattern>();
//if visitChar fails
if( !visitChar( m_arg[m_pos] ) ){
m_testSpec.m_invalidArgs.push_back(arg);
break;
}
endMode();
return *this;
}
TestSpec TestSpecParser::testSpec() {
addFilter();
return m_testSpec;
}
bool TestSpecParser::visitChar( char c ) {
if( (m_mode != EscapedName) && (c == '\\') ) {
escape();
addCharToPattern(c);
return true;
}else if((m_mode != EscapedName) && (c == ',') ) {
return separate();
}
void TestSpecParser::visitChar( char c ) {
if( m_mode == None ) {
switch( c ) {
case ' ': return;
case '~': m_exclusion = true; return;
case '[': return startNewMode( Tag, ++m_pos );
case '"': return startNewMode( QuotedName, ++m_pos );
case '\\': return escape();
default: startNewMode( Name, m_pos ); break;
}
switch( m_mode ) {
case None:
if( processNoneChar( c ) )
return true;
break;
case Name:
processNameChar( c );
break;
case EscapedName:
endMode();
addCharToPattern(c);
return true;
default:
case Tag:
case QuotedName:
if( processOtherChar( c ) )
return true;
break;
}
if( m_mode == Name ) {
if( c == ',' ) {
addPattern<TestSpec::NamePattern>();
addFilter();
}
else if( c == '[' ) {
if( subString() == "exclude:" )
m_exclusion = true;
else
addPattern<TestSpec::NamePattern>();
startNewMode( Tag, ++m_pos );
}
else if( c == '\\' )
escape();
m_substring += c;
if( !isControlChar( c ) ) {
m_patternName += c;
m_realPatternPos++;
}
else if( m_mode == EscapedName )
m_mode = Name;
else if( m_mode == QuotedName && c == '"' )
addPattern<TestSpec::NamePattern>();
else if( m_mode == Tag && c == ']' )
addPattern<TestSpec::TagPattern>();
return true;
}
void TestSpecParser::startNewMode( Mode mode, std::size_t start ) {
// Two of the processing methods return true to signal the caller to return
// without adding the given character to the current pattern strings
bool TestSpecParser::processNoneChar( char c ) {
switch( c ) {
case ' ':
return true;
case '~':
m_exclusion = true;
return false;
case '[':
startNewMode( Tag );
return false;
case '"':
startNewMode( QuotedName );
return false;
default:
startNewMode( Name );
return false;
}
}
void TestSpecParser::processNameChar( char c ) {
if( c == '[' ) {
if( m_substring == "exclude:" )
m_exclusion = true;
else
endMode();
startNewMode( Tag );
}
}
bool TestSpecParser::processOtherChar( char c ) {
if( !isControlChar( c ) )
return false;
m_substring += c;
endMode();
return true;
}
void TestSpecParser::startNewMode( Mode mode ) {
m_mode = mode;
m_start = start;
}
void TestSpecParser::endMode() {
switch( m_mode ) {
case Name:
case QuotedName:
return addPattern<TestSpec::NamePattern>();
case Tag:
return addPattern<TestSpec::TagPattern>();
case EscapedName:
revertBackToLastMode();
return;
case None:
default:
return startNewMode( None );
}
}
void TestSpecParser::escape() {
if( m_mode == None )
m_start = m_pos;
saveLastMode();
m_mode = EscapedName;
m_escapeChars.push_back( m_pos );
m_escapeChars.push_back(m_realPatternPos);
}
bool TestSpecParser::isControlChar( char c ) const {
switch( m_mode ) {
default:
return false;
case None:
return c == '~';
case Name:
return c == '[';
case EscapedName:
return true;
case QuotedName:
return c == '"';
case Tag:
return c == '[' || c == ']';
}
}
std::string TestSpecParser::subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
void TestSpecParser::addFilter() {
if( !m_currentFilter.m_patterns.empty() ) {
@@ -80,6 +153,28 @@ namespace Catch {
}
}
void TestSpecParser::saveLastMode() {
lastMode = m_mode;
}
void TestSpecParser::revertBackToLastMode() {
m_mode = lastMode;
}
bool TestSpecParser::separate() {
if( (m_mode==QuotedName) || (m_mode==Tag) ){
//invalid argument, signal failure to previous scope.
m_mode = None;
m_pos = m_arg.size();
m_substring.clear();
m_patternName.clear();
return false;
}
endMode();
addFilter();
return true; //success
}
TestSpec parseTestSpec( std::string const& arg ) {
return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
}

View File

@@ -22,9 +22,13 @@ namespace Catch {
class TestSpecParser {
enum Mode{ None, Name, QuotedName, Tag, EscapedName };
Mode m_mode = None;
Mode lastMode = None;
bool m_exclusion = false;
std::size_t m_start = std::string::npos, m_pos = 0;
std::size_t m_pos = 0;
std::size_t m_realPatternPos = 0;
std::string m_arg;
std::string m_substring;
std::string m_patternName;
std::vector<std::size_t> m_escapeChars;
TestSpec::Filter m_currentFilter;
TestSpec m_testSpec;
@@ -37,32 +41,47 @@ namespace Catch {
TestSpec testSpec();
private:
void visitChar( char c );
void startNewMode( Mode mode, std::size_t start );
bool visitChar( char c );
void startNewMode( Mode mode );
bool processNoneChar( char c );
void processNameChar( char c );
bool processOtherChar( char c );
void endMode();
void escape();
std::string subString() const;
bool isControlChar( char c ) const;
void saveLastMode();
void revertBackToLastMode();
void addFilter();
bool separate();
template<typename T>
void addPattern() {
std::string token = subString();
std::string token = m_patternName;
for( std::size_t i = 0; i < m_escapeChars.size(); ++i )
token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
token = token.substr( 0, m_escapeChars[i] - i ) + token.substr( m_escapeChars[i] -i +1 );
m_escapeChars.clear();
if( startsWith( token, "exclude:" ) ) {
m_exclusion = true;
token = token.substr( 8 );
}
if( !token.empty() ) {
TestSpec::PatternPtr pattern = std::make_shared<T>( token );
TestSpec::PatternPtr pattern = std::make_shared<T>( token, m_substring );
if( m_exclusion )
pattern = std::make_shared<TestSpec::ExcludedPattern>( pattern );
m_currentFilter.m_patterns.push_back( pattern );
}
m_substring.clear();
m_patternName.clear();
m_exclusion = false;
m_mode = None;
}
void addFilter();
inline void addCharToPattern(char c) {
m_substring += c;
m_patternName += c;
m_realPatternPos++;
}
};
TestSpec parseTestSpec( std::string const& arg );
@@ -72,4 +91,4 @@ namespace Catch {
#pragma clang diagnostic pop
#endif
#endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
#endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED

View File

@@ -170,6 +170,12 @@ std::string StringMaker<wchar_t *>::convert(wchar_t * str) {
}
#endif
#if defined(CATCH_CONFIG_CPP17_BYTE)
#include <cstddef>
std::string StringMaker<std::byte>::convert(std::byte value) {
return ::Catch::Detail::stringify(std::to_integer<unsigned long long>(value));
}
#endif // defined(CATCH_CONFIG_CPP17_BYTE)
std::string StringMaker<int>::convert(int value) {
return ::Catch::Detail::stringify(static_cast<long long>(value));

View File

@@ -44,9 +44,9 @@ namespace Catch {
template<typename T>
class IsStreamInsertable {
template<typename SS, typename TT>
template<typename Stream, typename U>
static auto test(int)
-> decltype(std::declval<SS&>() << std::declval<TT>(), std::true_type());
-> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type());
template<typename, typename>
static auto test(...)->std::false_type;
@@ -210,6 +210,12 @@ namespace Catch {
}
};
#if defined(CATCH_CONFIG_CPP17_BYTE)
template<>
struct StringMaker<std::byte> {
static std::string convert(std::byte value);
};
#endif // defined(CATCH_CONFIG_CPP17_BYTE)
template<>
struct StringMaker<int> {
static std::string convert(int value);
@@ -648,7 +654,7 @@ namespace Catch { \
template<> struct StringMaker<enumName> { \
static std::string convert( enumName value ) { \
static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \
return enumInfo.lookup( static_cast<int>( value ) ); \
return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \
} \
}; \
}

View File

@@ -1,40 +0,0 @@
/*
* Created by Jozef on 12/11/2018.
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED
#include <type_traits>
namespace Catch{
#ifdef CATCH_CPP17_OR_GREATER
template <typename...>
inline constexpr auto is_unique = std::true_type{};
template <typename T, typename... Rest>
inline constexpr auto is_unique<T, Rest...> = std::bool_constant<
(!std::is_same_v<T, Rest> && ...) && is_unique<Rest...>
>{};
#else
template <typename...>
struct is_unique : std::true_type{};
template <typename T0, typename T1, typename... Rest>
struct is_unique<T0, T1, Rest...> : std::integral_constant
<bool,
!std::is_same<T0, T1>::value
&& is_unique<T0, Rest...>::value
&& is_unique<T1, Rest...>::value
>{};
#endif
}
#endif // TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED

View File

@@ -37,7 +37,7 @@ namespace Catch {
}
Version const& libraryVersion() {
static Version version( 2, 9, 1, "", 0 );
static Version version( 2, 10, 2, "", 0 );
return version;
}

View File

@@ -9,14 +9,12 @@
#include "catch_enforce.h"
#include "catch_string_manip.h"
#include <sstream>
namespace Catch {
WildcardPattern::WildcardPattern( std::string const& pattern,
CaseSensitive::Choice caseSensitivity )
: m_caseSensitivity( caseSensitivity ),
m_pattern( adjustCase( pattern ) )
m_pattern( normaliseString( pattern ) )
{
if( startsWith( m_pattern, '*' ) ) {
m_pattern = m_pattern.substr( 1 );
@@ -31,19 +29,19 @@ namespace Catch {
bool WildcardPattern::matches( std::string const& str ) const {
switch( m_wildcard ) {
case NoWildcard:
return m_pattern == adjustCase( str );
return m_pattern == normaliseString( str );
case WildcardAtStart:
return endsWith( adjustCase( str ), m_pattern );
return endsWith( normaliseString( str ), m_pattern );
case WildcardAtEnd:
return startsWith( adjustCase( str ), m_pattern );
return startsWith( normaliseString( str ), m_pattern );
case WildcardAtBothEnds:
return contains( adjustCase( str ), m_pattern );
return contains( normaliseString( str ), m_pattern );
default:
CATCH_INTERNAL_ERROR( "Unknown enum" );
}
}
std::string WildcardPattern::adjustCase( std::string const& str ) const {
return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
std::string WildcardPattern::normaliseString( std::string const& str ) const {
return trim( m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str );
}
}

View File

@@ -28,7 +28,7 @@ namespace Catch
virtual bool matches( std::string const& str ) const;
private:
std::string adjustCase( std::string const& str ) const;
std::string normaliseString( std::string const& str ) const;
CaseSensitive::Choice m_caseSensitivity;
WildcardPosition m_wildcard = NoWildcard;
std::string m_pattern;

View File

@@ -51,6 +51,8 @@ namespace Catch {
void noMatchingTestCases(std::string const&) override {}
void reportInvalidArguments(std::string const&) override {}
void testRunStarting(TestRunInfo const& _testRunInfo) override {
currentTestRunInfo = _testRunInfo;
}
@@ -277,4 +279,4 @@ namespace Catch {
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
#endif // TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED

View File

@@ -8,7 +8,7 @@
#include "catch_reporter_compact.h"
#include "../internal/catch_reporter_registrars.hpp"
#include "internal/catch_console_colour.h"
#include "../internal/catch_console_colour.h"
namespace {
@@ -209,24 +209,25 @@ private:
if (itMessage == messages.end())
return;
// using messages.end() directly yields (or auto) compilation error:
std::vector<MessageInfo>::const_iterator itEnd = messages.end();
const std::size_t N = static_cast<std::size_t>(std::distance(itMessage, itEnd));
const auto itEnd = messages.cend();
const auto N = static_cast<std::size_t>(std::distance(itMessage, itEnd));
{
Colour colourGuard(colour);
stream << " with " << pluralise(N, "message") << ':';
}
for (; itMessage != itEnd; ) {
while (itMessage != itEnd) {
// If this assertion is a warning ignore any INFO messages
if (printInfoMessages || itMessage->type != ResultWas::Info) {
stream << " '" << itMessage->message << '\'';
if (++itMessage != itEnd) {
printMessage();
if (itMessage != itEnd) {
Colour colourGuard(dimColour());
stream << " and";
}
continue;
}
++itMessage;
}
}

View File

@@ -9,7 +9,7 @@
#include "catch_reporter_console.h"
#include "../internal/catch_reporter_registrars.hpp"
#include "internal/catch_console_colour.h"
#include "../internal/catch_console_colour.h"
#include "../internal/catch_version.h"
#include "../internal/catch_text.h"
#include "../internal/catch_stringref.h"
@@ -268,7 +268,7 @@ public:
}
friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& {
return os << duration.value() << " " << duration.unitsAsString();
return os << duration.value() << ' ' << duration.unitsAsString();
}
};
} // end anon namespace
@@ -300,9 +300,9 @@ public:
headerCols += Column(info.name).width(static_cast<std::size_t>(info.width - 2));
headerCols += spacer;
}
m_os << headerCols << "\n";
m_os << headerCols << '\n';
m_os << Catch::getLineOfChars<'-'>() << "\n";
m_os << Catch::getLineOfChars<'-'>() << '\n';
}
}
void close() {
@@ -321,30 +321,29 @@ public:
friend TablePrinter& operator << (TablePrinter& tp, ColumnBreak) {
auto colStr = tp.m_oss.str();
// This takes account of utf8 encodings
auto strSize = Catch::StringRef(colStr).numberOfCharacters();
const auto strSize = colStr.size();
tp.m_oss.str("");
tp.open();
if (tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size() - 1)) {
tp.m_currentColumn = -1;
tp.m_os << "\n";
tp.m_os << '\n';
}
tp.m_currentColumn++;
auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
auto padding = (strSize + 2 < static_cast<std::size_t>(colInfo.width))
? std::string(colInfo.width - (strSize + 2), ' ')
auto padding = (strSize + 1 < static_cast<std::size_t>(colInfo.width))
? std::string(colInfo.width - (strSize + 1), ' ')
: std::string();
if (colInfo.justification == ColumnInfo::Left)
tp.m_os << colStr << padding << " ";
tp.m_os << colStr << padding << ' ';
else
tp.m_os << padding << colStr << " ";
tp.m_os << padding << colStr << ' ';
return tp;
}
friend TablePrinter& operator << (TablePrinter& tp, RowBreak) {
if (tp.m_currentColumn > 0) {
tp.m_os << "\n";
tp.m_os << '\n';
tp.m_currentColumn = -1;
}
return tp;
@@ -354,12 +353,26 @@ public:
ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
: StreamingReporterBase(config),
m_tablePrinter(new TablePrinter(config.stream(),
{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 32, ColumnInfo::Left },
{ "samples mean std dev", 14, ColumnInfo::Right },
{ "iterations low mean low std dev", 14, ColumnInfo::Right },
{ "estimated high mean high std dev", 14, ColumnInfo::Right }
})) {}
[&config]() -> std::vector<ColumnInfo> {
if (config.fullConfig()->benchmarkNoAnalysis())
{
return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
{ " samples", 14, ColumnInfo::Right },
{ " iterations", 14, ColumnInfo::Right },
{ " mean", 14, ColumnInfo::Right }
};
}
else
{
return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 32, ColumnInfo::Left },
{ "samples mean std dev", 14, ColumnInfo::Right },
{ "iterations low mean low std dev", 14, ColumnInfo::Right },
{ "estimated high mean high std dev", 14, ColumnInfo::Right }
};
}
}())) {}
ConsoleReporter::~ConsoleReporter() = default;
std::string ConsoleReporter::getDescription() {
@@ -370,6 +383,10 @@ void ConsoleReporter::noMatchingTestCases(std::string const& spec) {
stream << "No test cases matched '" << spec << '\'' << std::endl;
}
void ConsoleReporter::reportInvalidArguments(std::string const&arg){
stream << "Invalid Filter: " << arg << std::endl;
}
void ConsoleReporter::assertionStarting(AssertionInfo const&) {}
bool ConsoleReporter::assertionEnded(AssertionStats const& _assertionStats) {
@@ -432,24 +449,32 @@ void ConsoleReporter::benchmarkPreparing(std::string const& name) {
}
void ConsoleReporter::benchmarkStarting(BenchmarkInfo const& info) {
(*m_tablePrinter) << info.samples << ColumnBreak()
<< info.iterations << ColumnBreak()
<< Duration(info.estimatedDuration) << ColumnBreak();
(*m_tablePrinter) << info.samples << ColumnBreak()
<< info.iterations << ColumnBreak();
if (!m_config->benchmarkNoAnalysis())
(*m_tablePrinter) << Duration(info.estimatedDuration) << ColumnBreak();
}
void ConsoleReporter::benchmarkEnded(BenchmarkStats<> const& stats) {
(*m_tablePrinter) << ColumnBreak()
<< Duration(stats.mean.point.count()) << ColumnBreak()
<< Duration(stats.mean.lower_bound.count()) << ColumnBreak()
<< Duration(stats.mean.upper_bound.count()) << ColumnBreak() << ColumnBreak()
<< Duration(stats.standardDeviation.point.count()) << ColumnBreak()
<< Duration(stats.standardDeviation.lower_bound.count()) << ColumnBreak()
<< Duration(stats.standardDeviation.upper_bound.count()) << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak();
if (m_config->benchmarkNoAnalysis())
{
(*m_tablePrinter) << Duration(stats.mean.point.count()) << ColumnBreak();
}
else
{
(*m_tablePrinter) << ColumnBreak()
<< Duration(stats.mean.point.count()) << ColumnBreak()
<< Duration(stats.mean.lower_bound.count()) << ColumnBreak()
<< Duration(stats.mean.upper_bound.count()) << ColumnBreak() << ColumnBreak()
<< Duration(stats.standardDeviation.point.count()) << ColumnBreak()
<< Duration(stats.standardDeviation.lower_bound.count()) << ColumnBreak()
<< Duration(stats.standardDeviation.upper_bound.count()) << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak() << ColumnBreak();
}
}
void ConsoleReporter::benchmarkFailed(std::string const& error) {
Colour colour(Colour::Red);
(*m_tablePrinter)
<< "Benchmark failed (" << error << ")"
<< "Benchmark failed (" << error << ')'
<< ColumnBreak() << RowBreak();
}
#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
@@ -531,11 +556,10 @@ void ConsoleReporter::printTestCaseAndSectionHeader() {
SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
if (!lineInfo.empty()) {
stream << getLineOfChars<'-'>() << '\n';
Colour colourGuard(Colour::FileName);
stream << lineInfo << '\n';
}
stream << getLineOfChars<'-'>() << '\n';
Colour colourGuard(Colour::FileName);
stream << lineInfo << '\n';
stream << getLineOfChars<'.'>() << '\n' << std::endl;
}
@@ -674,4 +698,4 @@ CATCH_REGISTER_REPORTER("console", ConsoleReporter)
#if defined(__clang__)
# pragma clang diagnostic pop
#endif
#endif

View File

@@ -32,6 +32,8 @@ namespace Catch {
void noMatchingTestCases(std::string const& spec) override;
void reportInvalidArguments(std::string const&arg) override;
void assertionStarting(AssertionInfo const&) override;
bool assertionEnded(AssertionStats const& _assertionStats) override;
@@ -84,4 +86,4 @@ namespace Catch {
#pragma warning(pop)
#endif
#endif // TWOBLUECUBES_CATCH_REPORTER_CONSOLE_H_INCLUDED
#endif // TWOBLUECUBES_CATCH_REPORTER_CONSOLE_H_INCLUDED

View File

@@ -41,6 +41,13 @@ namespace Catch {
}
m_reporter->noMatchingTestCases( spec );
}
void ListeningReporter::reportInvalidArguments(std::string const&arg){
for ( auto const& listener : m_listeners ) {
listener->reportInvalidArguments( arg );
}
m_reporter->reportInvalidArguments( arg );
}
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
void ListeningReporter::benchmarkPreparing( std::string const& name ) {
@@ -154,4 +161,4 @@ namespace Catch {
return true;
}
} // end namespace Catch
} // end namespace Catch

View File

@@ -28,7 +28,9 @@ namespace Catch {
ReporterPreferences getPreferences() const override;
void noMatchingTestCases( std::string const& spec ) override;
void reportInvalidArguments(std::string const&arg) override;
static std::set<Verbosity> getSupportedVerbosities();
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
@@ -58,4 +60,4 @@ namespace Catch {
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_MULTI_REPORTER_H_INCLUDED
#endif // TWOBLUECUBES_CATCH_MULTI_REPORTER_H_INCLUDED

View File

@@ -183,8 +183,7 @@ namespace Catch {
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
if( !lineInfo.empty() )
os << lineInfo << "\n";
os << lineInfo << "\n";
os << getLineOfChars<'.'>() << "\n\n";
}

View File

@@ -220,10 +220,13 @@ namespace Catch {
}
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
void XmlReporter::benchmarkStarting(BenchmarkInfo const &info) {
void XmlReporter::benchmarkPreparing(std::string const& name) {
m_xml.startElement("BenchmarkResults")
.writeAttribute("name", info.name)
.writeAttribute("samples", info.samples)
.writeAttribute("name", name);
}
void XmlReporter::benchmarkStarting(BenchmarkInfo const &info) {
m_xml.writeAttribute("samples", info.samples)
.writeAttribute("resamples", info.resamples)
.writeAttribute("iterations", info.iterations)
.writeAttribute("clockResolution", static_cast<uint64_t>(info.clockResolution))

View File

@@ -51,6 +51,7 @@ namespace Catch {
void testRunEnded(TestRunStats const& testRunStats) override;
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
void benchmarkPreparing(std::string const& name) override;
void benchmarkStarting(BenchmarkInfo const&) override;
void benchmarkEnded(BenchmarkStats<> const&) override;
void benchmarkFailed(std::string const&) override;

View File

@@ -4,6 +4,6 @@ import glob
import subprocess
if __name__ == '__main__':
cov_files = list(glob.glob('cov-report*.bin'))
cov_files = list(glob.glob('projects/cov-report*.bin'))
base_cmd = ['OpenCppCoverage', '--quiet', '--export_type=cobertura:cobertura.xml'] + ['--input_coverage={}'.format(f) for f in cov_files]
subprocess.call(base_cmd)
subprocess.check_call(base_cmd)

View File

@@ -29,7 +29,8 @@ std::string escape_arg(const std::string& arg) {
escaped.append(num_backslashes * 2, '\\');
break;
} else if (*it == '"') {
escaped.append(num_backslashes * 2 + 1, '\\');
escaped.append((num_backslashes + 1) * 2, '\\');
escaped.push_back('"');
escaped.push_back(*it);
} else {
escaped.append(num_backslashes, '\\');
@@ -89,27 +90,30 @@ std::string windowsify_path(std::string path) {
return path;
}
void exec_cmd(std::string const& cmd, int log_num, std::string const& path) {
int exec_cmd(std::string const& cmd, int log_num, std::string const& path) {
std::array<char, 128> buffer;
#if defined(_WIN32)
// cmd has already been escaped outside this function.
auto real_cmd = "OpenCppCoverage --export_type binary:cov-report" + std::to_string(log_num)
+ ".bin --quiet " + "--sources " + escape_arg(path) + " --cover_children -- " + cmd;
std::cout << "=== Marker ===: Cmd: " << real_cmd << '\n';
std::shared_ptr<FILE> pipe(_popen(real_cmd.c_str(), "r"), _pclose);
#else // Just for testing, in the real world we will always work under WIN32
(void)log_num; (void)path;
std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose);
#endif
auto pipe = _popen(real_cmd.c_str(), "r");
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (!feof(pipe.get())) {
if (fgets(buffer.data(), 128, pipe.get()) != nullptr) {
while (!feof(pipe)) {
if (fgets(buffer.data(), 128, pipe) != nullptr) {
std::cout << buffer.data();
}
}
auto ret = _pclose(pipe);
if (ret == -1) {
throw std::runtime_error("underlying error in pclose()");
}
return ret;
}
// argv should be:
@@ -124,7 +128,7 @@ int main(int argc, char** argv) {
assert(sep - begin(args) == 2 && "Structure differs from expected!");
auto num = parse_log_file_arg(args[1]);
auto cmdline = std::accumulate(++sep, end(args), std::string{}, [] (const std::string& lhs, const std::string& rhs) {
return lhs + ' ' + escape_arg(rhs);
});

View File

@@ -17,11 +17,14 @@ endif(MSVC) #Temporary workaround
set(TEST_SOURCES
${SELF_TEST_DIR}/TestMain.cpp
${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/InternalBenchmark.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/RandomNumberGeneration.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp
${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp
${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp
@@ -36,6 +39,7 @@ set(TEST_SOURCES
${SELF_TEST_DIR}/UsageTests/Generators.tests.cpp
${SELF_TEST_DIR}/UsageTests/Message.tests.cpp
${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp
${SELF_TEST_DIR}/UsageTests/ToStringByte.tests.cpp
${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp
${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp
${SELF_TEST_DIR}/UsageTests/ToStringOptional.tests.cpp
@@ -147,6 +151,7 @@ set(INTERNAL_HEADERS
${HEADER_DIR}/internal/catch_leak_detector.h
${HEADER_DIR}/internal/catch_list.h
${HEADER_DIR}/internal/catch_matchers.h
${HEADER_DIR}/internal/catch_matchers_exception.hpp
${HEADER_DIR}/internal/catch_matchers_floating.h
${HEADER_DIR}/internal/catch_matchers_generic.hpp
${HEADER_DIR}/internal/catch_matchers_string.h
@@ -189,7 +194,6 @@ set(INTERNAL_HEADERS
${HEADER_DIR}/internal/catch_to_string.hpp
${HEADER_DIR}/internal/catch_tostring.h
${HEADER_DIR}/internal/catch_totals.h
${HEADER_DIR}/internal/catch_type_traits.hpp
${HEADER_DIR}/internal/catch_uncaught_exceptions.h
${HEADER_DIR}/internal/catch_user_interfaces.h
${HEADER_DIR}/internal/catch_version.h
@@ -226,6 +230,7 @@ set(IMPL_SOURCES
${HEADER_DIR}/internal/catch_list.cpp
${HEADER_DIR}/internal/catch_leak_detector.cpp
${HEADER_DIR}/internal/catch_matchers.cpp
${HEADER_DIR}/internal/catch_matchers_exception.cpp
${HEADER_DIR}/internal/catch_matchers_floating.cpp
${HEADER_DIR}/internal/catch_matchers_generic.cpp
${HEADER_DIR}/internal/catch_matchers_string.cpp
@@ -308,6 +313,32 @@ include(CTest)
add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS})
target_include_directories(SelfTest PRIVATE ${HEADER_DIR})
# It took CMake until 3.8 to abandon the doomed approach of enumerating
# required features so we just list C++11 features to support older ones.
target_compile_features(SelfTest
PRIVATE
cxx_alignas
cxx_alignof
cxx_attributes
cxx_auto_type
cxx_constexpr
cxx_defaulted_functions
cxx_deleted_functions
cxx_final
cxx_lambdas
cxx_noexcept
cxx_override
cxx_range_for
cxx_rvalue_references
cxx_static_assert
cxx_strong_enums
cxx_trailing_return_types
cxx_unicode_literals
cxx_user_literals
cxx_variadic_macros
)
if (CATCH_ENABLE_COVERAGE)
set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE)
find_package(codecov)
@@ -366,8 +397,19 @@ set_tests_properties(ListTestNamesOnly PROPERTIES
add_test(NAME NoAssertions COMMAND $<TARGET_FILE:SelfTest> -w NoAssertions)
set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case")
add_test(NAME NoTest COMMAND $<TARGET_FILE:SelfTest> -w NoTests "___nonexistent_test___")
set_tests_properties(NoTest PROPERTIES PASS_REGULAR_EXPRESSION "No test cases matched")
add_test(NAME NoTest COMMAND $<TARGET_FILE:SelfTest> Tracker, "___nonexistent_test___")
set_tests_properties(NoTest PROPERTIES
PASS_REGULAR_EXPRESSION "No test cases matched '___nonexistent_test___'"
FAIL_REGULAR_EXPRESSION "No tests ran"
)
add_test(NAME WarnAboutNoTests COMMAND ${CMAKE_COMMAND} -P ${CATCH_DIR}/projects/SelfTest/WarnAboutNoTests.cmake $<TARGET_FILE:SelfTest>)
add_test(NAME UnmatchedOutputFilter COMMAND $<TARGET_FILE:SelfTest> [this-tag-does-not-exist] -w NoTests)
set_tests_properties(UnmatchedOutputFilter
PROPERTIES
PASS_REGULAR_EXPRESSION "No test cases matched '\\[this-tag-does-not-exist\\]'"
)
add_test(NAME FilteredSection-1 COMMAND $<TARGET_FILE:SelfTest> \#1394 -c RunSection)
set_tests_properties(FilteredSection-1 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran")
@@ -378,6 +420,36 @@ set_tests_properties(FilteredSection-2 PROPERTIES FAIL_REGULAR_EXPRESSION "No te
add_test(NAME ApprovalTests COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/scripts/approvalTests.py $<TARGET_FILE:SelfTest>)
set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed")
add_test(NAME RegressionCheck-1670 COMMAND $<TARGET_FILE:SelfTest> "#1670 regression check" -c A -r compact)
set_tests_properties(RegressionCheck-1670 PROPERTIES PASS_REGULAR_EXPRESSION "Passed 1 test case with 2 assertions.")
add_test(NAME VersionCheck COMMAND $<TARGET_FILE:SelfTest> -h)
set_tests_properties(VersionCheck PROPERTIES PASS_REGULAR_EXPRESSION "Catch v${PROJECT_VERSION}")
add_test(NAME LibIdentityTest COMMAND $<TARGET_FILE:SelfTest> --libidentify)
set_tests_properties(LibIdentityTest PROPERTIES PASS_REGULAR_EXPRESSION "description: A Catch2 test executable")
add_test(NAME FilenameAsTagsTest COMMAND $<TARGET_FILE:SelfTest> -\# --list-tags)
set_tests_properties(FilenameAsTagsTest PROPERTIES PASS_REGULAR_EXPRESSION "\\[#Approx.tests\\]")
add_test(NAME EscapeSpecialCharactersInTestNames COMMAND $<TARGET_FILE:SelfTest> "Test with special\\, characters \"in name")
set_tests_properties(EscapeSpecialCharactersInTestNames PROPERTIES PASS_REGULAR_EXPRESSION "1 assertion in 1 test case")
add_test(NAME TestsInFile::SimpleSpecs COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/plain-old-tests.input")
set_tests_properties(TestsInFile::SimpleSpecs PROPERTIES PASS_REGULAR_EXPRESSION "6 assertions in 2 test cases")
add_test(NAME TestsInFile::EscapeSpecialCharacters COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/special-characters-in-file.input")
set_tests_properties(TestsInFile::EscapeSpecialCharacters PROPERTIES PASS_REGULAR_EXPRESSION "1 assertion in 1 test case")
# CTest does not allow us to create an AND of required regular expressions,
# so we have to split the test into 2 parts and look for parts of the expected
# output separately.
add_test(NAME TestsInFile::InvalidTestNames-1 COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/invalid-test-names.input")
set_tests_properties(TestsInFile::InvalidTestNames-1 PROPERTIES PASS_REGULAR_EXPRESSION "Invalid Filter: \"Test with special, characters in \\\\\" name\"")
add_test(NAME TestsInFile::InvalidTestNames-2 COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/invalid-test-names.input")
set_tests_properties(TestsInFile::InvalidTestNames-2 PROPERTIES PASS_REGULAR_EXPRESSION "No tests ran")
if (CATCH_USE_VALGRIND)
add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest>)

View File

@@ -126,6 +126,16 @@ set_tests_properties(
PASS_REGULAR_EXPRESSION "benchmark name samples iterations estimated"
)
# This test touches windows.h, so it should only be compiled under msvc
if (MSVC)
# This test fails if it does not compile and succeeds otherwise
add_executable(WindowsHeader ${TESTS_DIR}/X90-WindowsHeaderInclusion.cpp)
set_property( TARGET WindowsHeader PROPERTY CXX_STANDARD 11 )
set_property( TARGET WindowsHeader PROPERTY CXX_STANDARD_REQUIRED ON )
set_property( TARGET WindowsHeader PROPERTY CXX_EXTENSIONS OFF )
target_include_directories( WindowsHeader PRIVATE ${SINGLE_INCLUDE_PATH} )
add_test(NAME WindowsHeader COMMAND WindowsHeader -r compact)
endif()
set( EXTRA_TEST_BINARIES
PrefixedMacros
@@ -145,3 +155,4 @@ foreach( test ${EXTRA_TEST_BINARIES} )
target_include_directories( ${test} PRIVATE ${SINGLE_INCLUDE_PATH} )
endforeach()

Some files were not shown because too many files have changed in this diff Show More