mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-12 00:15:39 +02:00
Compare commits
385 Commits
v3.0.0-pre
...
v3.0.0-pre
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f4af9f6926 | ||
![]() |
57c9c935ee | ||
![]() |
98a6c69e1e | ||
![]() |
d3199c42c2 | ||
![]() |
eeee4a49af | ||
![]() |
0d1bdea69f | ||
![]() |
3ab981fa21 | ||
![]() |
54e89e8364 | ||
![]() |
88b28ab592 | ||
![]() |
ef3374ed81 | ||
![]() |
f2f585b478 | ||
![]() |
b5547f2ef6 | ||
![]() |
93882f7fab | ||
![]() |
4752545a69 | ||
![]() |
fae0be25b3 | ||
![]() |
899554bff2 | ||
![]() |
b4efa4751a | ||
![]() |
22547a3c5f | ||
![]() |
8baf9c05a3 | ||
![]() |
ccd67b293d | ||
![]() |
6b55f5d780 | ||
![]() |
c9c3b74805 | ||
![]() |
8711b63a0a | ||
![]() |
72a09de236 | ||
![]() |
f0a89b7345 | ||
![]() |
f00b6e2019 | ||
![]() |
45577a1f4c | ||
![]() |
cbb6764fb1 | ||
![]() |
156e6fdfa9 | ||
![]() |
187bf6db2b | ||
![]() |
cde26de803 | ||
![]() |
3cc0c033e4 | ||
![]() |
840acedf62 | ||
![]() |
9f2dca5384 | ||
![]() |
602e484f02 | ||
![]() |
08939cc8bb | ||
![]() |
3bfe900bbc | ||
![]() |
d30d0c01a7 | ||
![]() |
dcf9479c85 | ||
![]() |
c49faa62dd | ||
![]() |
c097609115 | ||
![]() |
9d6fffb922 | ||
![]() |
153965a655 | ||
![]() |
0ac9f44985 | ||
![]() |
b9baae6d93 | ||
![]() |
c95072408f | ||
![]() |
8cb8f0b08b | ||
![]() |
9952f29f01 | ||
![]() |
2db1cf3404 | ||
![]() |
fabe614ba8 | ||
![]() |
acdb85c398 | ||
![]() |
726fdd7f8e | ||
![]() |
0ccb1c30c6 | ||
![]() |
dd12ce8141 | ||
![]() |
d32e89eb84 | ||
![]() |
ce6aca81ad | ||
![]() |
61489e863e | ||
![]() |
2287d225e5 | ||
![]() |
4eb00afe69 | ||
![]() |
e86f84b8ef | ||
![]() |
d012735c6e | ||
![]() |
67caef6f45 | ||
![]() |
f41d761674 | ||
![]() |
edc2f6e8a3 | ||
![]() |
b2ac27423a | ||
![]() |
a754cb9062 | ||
![]() |
5f38cc39fa | ||
![]() |
b892ab133c | ||
![]() |
0c9fe16537 | ||
![]() |
d02ea5adee | ||
![]() |
9b4e69333f | ||
![]() |
4d9bfb2951 | ||
![]() |
c4df47c246 | ||
![]() |
9200b4078b | ||
![]() |
6603f1d972 | ||
![]() |
62d8913d67 | ||
![]() |
8780425385 | ||
![]() |
7800fe9708 | ||
![]() |
141e384c60 | ||
![]() |
f1239b2045 | ||
![]() |
912df7df35 | ||
![]() |
931f41b4d6 | ||
![]() |
70c4ec78fb | ||
![]() |
455ae0c561 | ||
![]() |
2520ad4b6e | ||
![]() |
e539e1cb52 | ||
![]() |
3c5c86a4e4 | ||
![]() |
514206df36 | ||
![]() |
becab0cf74 | ||
![]() |
12d14a3c63 | ||
![]() |
f17725a186 | ||
![]() |
ec2d5013fb | ||
![]() |
342ef5ca7e | ||
![]() |
5ac1ffe9ee | ||
![]() |
3087e19cc7 | ||
![]() |
6456ee8b01 | ||
![]() |
905bf438ae | ||
![]() |
0fdee1c273 | ||
![]() |
22750cde0e | ||
![]() |
bf5c58adf6 | ||
![]() |
06cf2a4724 | ||
![]() |
4436a60456 | ||
![]() |
36b4a71ff0 | ||
![]() |
b406ad52a7 | ||
![]() |
de67278e14 | ||
![]() |
1d9696d22d | ||
![]() |
ed1f343a41 | ||
![]() |
200a487cf2 | ||
![]() |
fce42b62ad | ||
![]() |
4e6d306742 | ||
![]() |
c6c46a168f | ||
![]() |
48a889859b | ||
![]() |
d65ee04b74 | ||
![]() |
928e198ef2 | ||
![]() |
3e9c6fec22 | ||
![]() |
13670f535f | ||
![]() |
c6640e4f47 | ||
![]() |
23f0d94b4f | ||
![]() |
77c7e9803e | ||
![]() |
1d79683ea8 | ||
![]() |
eb452e9b35 | ||
![]() |
2deafc33e9 | ||
![]() |
5250cf6d58 | ||
![]() |
426954032f | ||
![]() |
f02c2678a1 | ||
![]() |
21b99d6f58 | ||
![]() |
d42e7a23a0 | ||
![]() |
7bb00a42be | ||
![]() |
fb4153e05e | ||
![]() |
e8e28ba401 | ||
![]() |
ee1435793e | ||
![]() |
3f8cae8025 | ||
![]() |
2c82f82ee2 | ||
![]() |
785436cd74 | ||
![]() |
f314fa1f8c | ||
![]() |
013edc208b | ||
![]() |
10fb93cce8 | ||
![]() |
4dcf8382c7 | ||
![]() |
efd8cc8777 | ||
![]() |
12bca890b7 | ||
![]() |
317db82396 | ||
![]() |
cf5ccaa9df | ||
![]() |
b3a84c7983 | ||
![]() |
c0f866c7cf | ||
![]() |
29caae5ce5 | ||
![]() |
ea49210eae | ||
![]() |
e4719fb51c | ||
![]() |
290c1b60e6 | ||
![]() |
e5938007f7 | ||
![]() |
ab3fe0053d | ||
![]() |
432d03d1aa | ||
![]() |
9ac9fb164e | ||
![]() |
07018e2fba | ||
![]() |
ff0a5227ca | ||
![]() |
54edab53bf | ||
![]() |
0a8516aeea | ||
![]() |
928ecbaccf | ||
![]() |
1cbbc5d2cb | ||
![]() |
7f3297f7e8 | ||
![]() |
7ff54ebc06 | ||
![]() |
ca8546efc6 | ||
![]() |
4113a12c69 | ||
![]() |
edad4d0af7 | ||
![]() |
88c27ffaf2 | ||
![]() |
d2ee7100d2 | ||
![]() |
03ce304102 | ||
![]() |
7040f03b54 | ||
![]() |
1554251f97 | ||
![]() |
2b54f1e7a6 | ||
![]() |
2c84854b90 | ||
![]() |
3579c055c8 | ||
![]() |
3ec63324a8 | ||
![]() |
7d0770adf2 | ||
![]() |
74db06199b | ||
![]() |
52a3144145 | ||
![]() |
a62974eb6a | ||
![]() |
a0d84654dd | ||
![]() |
557e5118f1 | ||
![]() |
0a3f511cfe | ||
![]() |
9ef510b769 | ||
![]() |
1b1f3a88bc | ||
![]() |
02ab64da2e | ||
![]() |
77df08b44d | ||
![]() |
79c2daa4a0 | ||
![]() |
1e0dc61d16 | ||
![]() |
02e5951f11 | ||
![]() |
1ecc79bb56 | ||
![]() |
73cae40a90 | ||
![]() |
6c4c961207 | ||
![]() |
340a61af50 | ||
![]() |
3d1cf95b32 | ||
![]() |
6f21a3609c | ||
![]() |
bf61a418cb | ||
![]() |
849002aec0 | ||
![]() |
4eb9af51af | ||
![]() |
78e4fbdb12 | ||
![]() |
a7533707ff | ||
![]() |
28a33497be | ||
![]() |
70f5392210 | ||
![]() |
61461dfd1d | ||
![]() |
c064322a9d | ||
![]() |
a14d67cace | ||
![]() |
4ce8a23edd | ||
![]() |
c1b59b7071 | ||
![]() |
c77ba5314a | ||
![]() |
65c9a1d31a | ||
![]() |
fa31d58934 | ||
![]() |
9ac8cad2d1 | ||
![]() |
c71f42cc29 | ||
![]() |
e6da4e10ae | ||
![]() |
816f69416b | ||
![]() |
aee31d0620 | ||
![]() |
c9371865d4 | ||
![]() |
5741de9ccd | ||
![]() |
0e2895934c | ||
![]() |
a01073d871 | ||
![]() |
02839ba934 | ||
![]() |
8d6a1c27ef | ||
![]() |
41ad0fda11 | ||
![]() |
d9f72868b2 | ||
![]() |
c7241bb76e | ||
![]() |
1d04427fcd | ||
![]() |
aba114d6fe | ||
![]() |
0221148ac3 | ||
![]() |
9f091cbe9d | ||
![]() |
4c1e896d47 | ||
![]() |
2c04850f88 | ||
![]() |
c9027375a3 | ||
![]() |
2ae28fc852 | ||
![]() |
f9ec34ce01 | ||
![]() |
96790b1d23 | ||
![]() |
86f86c4c23 | ||
![]() |
023b5306b4 | ||
![]() |
9137e591fa | ||
![]() |
f50a06affa | ||
![]() |
4cc247cc70 | ||
![]() |
8ee422d6bf | ||
![]() |
0c0f73a48d | ||
![]() |
61e16416a9 | ||
![]() |
074017f5ad | ||
![]() |
0a89e7f0c4 | ||
![]() |
28f6698ec8 | ||
![]() |
b36f8daaad | ||
![]() |
d86cb5f95d | ||
![]() |
5eb7aa4f90 | ||
![]() |
35cba5486d | ||
![]() |
eb911aa995 | ||
![]() |
313071e8fe | ||
![]() |
f9bb2668e4 | ||
![]() |
baf0cd0be4 | ||
![]() |
c0d0a50bdb | ||
![]() |
cbcab2dbcd | ||
![]() |
ea44e73961 | ||
![]() |
d61fe3ecc3 | ||
![]() |
b325c6d81e | ||
![]() |
d4a3cd9992 | ||
![]() |
342dd3445c | ||
![]() |
23760327ae | ||
![]() |
48f220b68a | ||
![]() |
031a57e7b7 | ||
![]() |
cdf4748d1c | ||
![]() |
520b6dace9 | ||
![]() |
2cb5210caf | ||
![]() |
2dc5a5f402 | ||
![]() |
04166514fe | ||
![]() |
e8cdfdca87 | ||
![]() |
a5abec9cb5 | ||
![]() |
f1d7a10e06 | ||
![]() |
e50e10ef8f | ||
![]() |
2c269eb633 | ||
![]() |
4b5812e932 | ||
![]() |
9f44bd57f1 | ||
![]() |
6734c0aa64 | ||
![]() |
037ddbc75c | ||
![]() |
6d803cba5d | ||
![]() |
551946c45b | ||
![]() |
653764d53b | ||
![]() |
3afea8128a | ||
![]() |
749d953712 | ||
![]() |
4b50b13970 | ||
![]() |
1ee0940427 | ||
![]() |
29050daec0 | ||
![]() |
e5e9afad16 | ||
![]() |
8b27041fbe | ||
![]() |
c12170ff69 | ||
![]() |
3eade52fc0 | ||
![]() |
2dbe63a6ba | ||
![]() |
477540760a | ||
![]() |
b435e391c4 | ||
![]() |
971b1fc32a | ||
![]() |
6798c139a6 | ||
![]() |
7111b2a8e2 | ||
![]() |
5509ceff60 | ||
![]() |
74f2f4ba5e | ||
![]() |
ba81505168 | ||
![]() |
f5b413aa58 | ||
![]() |
4e8832fc88 | ||
![]() |
bdd1e5c613 | ||
![]() |
1d269211bd | ||
![]() |
0acb371b92 | ||
![]() |
045feff834 | ||
![]() |
965afc4b2e | ||
![]() |
77643ce2e5 | ||
![]() |
552af8920d | ||
![]() |
ce54ec185f | ||
![]() |
c787b1edc9 | ||
![]() |
a091853f4a | ||
![]() |
be813faaa0 | ||
![]() |
4b51d0dd3b | ||
![]() |
6350851f9a | ||
![]() |
21c97f2fad | ||
![]() |
5b1a6ae00a | ||
![]() |
b9fe8a208f | ||
![]() |
c19b8ec5d7 | ||
![]() |
230f23e6ee | ||
![]() |
88504e5332 | ||
![]() |
4da0c18526 | ||
![]() |
1d746a15ac | ||
![]() |
19cbdebb0e | ||
![]() |
f30a9e3feb | ||
![]() |
e7740316e3 | ||
![]() |
72525a3053 | ||
![]() |
1982c0d5ee | ||
![]() |
0442229dc9 | ||
![]() |
130bf835b5 | ||
![]() |
c3e8ae642f | ||
![]() |
3bd5fd6bc5 | ||
![]() |
f36e059453 | ||
![]() |
677adf8ade | ||
![]() |
bfe5553416 | ||
![]() |
c673db7a4e | ||
![]() |
b10a19545b | ||
![]() |
e5ccb79bf8 | ||
![]() |
3610eb81b1 | ||
![]() |
bd1e76cc3a | ||
![]() |
166c520598 | ||
![]() |
a29deeb129 | ||
![]() |
1cef51b69b | ||
![]() |
79c1bf9301 | ||
![]() |
4f14922aa3 | ||
![]() |
0fa133a0c5 | ||
![]() |
447b39cae0 | ||
![]() |
851a0e907e | ||
![]() |
93312b369e | ||
![]() |
d913837a5d | ||
![]() |
a9941d4231 | ||
![]() |
39e13bf530 | ||
![]() |
fefa001bb6 | ||
![]() |
135103bacf | ||
![]() |
2baa472bcc | ||
![]() |
f97436a1f7 | ||
![]() |
dd5652933a | ||
![]() |
3a15433d52 | ||
![]() |
67a9561fb5 | ||
![]() |
2f31f9037d | ||
![]() |
33bcdc6bf5 | ||
![]() |
74b397e6b8 | ||
![]() |
730ec39a74 | ||
![]() |
71328bae90 | ||
![]() |
ed9ef85a34 | ||
![]() |
e4474021ff | ||
![]() |
79a5cd795c | ||
![]() |
b8ae2878b4 | ||
![]() |
dc3c22f9ec | ||
![]() |
735f46ed6d | ||
![]() |
39aabede62 | ||
![]() |
d7ced69db2 | ||
![]() |
f797ae7a8f | ||
![]() |
40b9df567f | ||
![]() |
c6352c3e1f | ||
![]() |
4035beb988 | ||
![]() |
8c3970465d | ||
![]() |
f57689f888 | ||
![]() |
967b82231c | ||
![]() |
7b9bf633be | ||
![]() |
4c8454b5ec | ||
![]() |
8878f90323 | ||
![]() |
0c7f96ba63 | ||
![]() |
923bcc5d6f | ||
![]() |
b6a3e2e26b | ||
![]() |
6ffac61719 | ||
![]() |
4b2bc8757c | ||
![]() |
faffc29253 | ||
![]() |
4ea18d6d17 | ||
![]() |
c44d9cc718 |
@@ -26,8 +26,8 @@ class BuilderSettings(object):
|
||||
""" Set Catch2 repository to be used on upload.
|
||||
The upload server address could be customized by env var
|
||||
CONAN_UPLOAD. If not defined, the method will check the branch name.
|
||||
Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted.
|
||||
The master branch will be pushed to testing channel, because it does
|
||||
Only devel or CONAN_STABLE_BRANCH_PATTERN will be accepted.
|
||||
The devel branch will be pushed to testing channel, because it does
|
||||
not match the stable pattern. Otherwise it will upload to stable
|
||||
channel.
|
||||
"""
|
||||
|
@@ -1,19 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.2.0)
|
||||
project(test_package CXX)
|
||||
|
||||
# We set it only for the convenience of calling the executable
|
||||
# in the package test function
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
|
||||
conan_basic_setup()
|
||||
|
||||
find_package(Catch2 REQUIRED CONFIG)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||
# Note: Conan 1.21 doesn't support granular target generation yet.
|
||||
# The Main library would be included into the unified target.
|
||||
# It's controlled by the `with_main` option in the recipe.
|
||||
target_link_libraries(${PROJECT_NAME} Catch2::Catch2)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} Catch2::Catch2WithMain)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
|
||||
|
@@ -6,7 +6,7 @@ import os
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "cmake_find_package_multi"
|
||||
generators = "cmake_find_package_multi", "cmake"
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
@@ -14,6 +14,7 @@ class TestPackageConan(ConanFile):
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
assert os.path.isfile(os.path.join(self.deps_cpp_info["catch2"].rootpath, "licenses", "LICENSE.txt"))
|
||||
assert os.path.isfile(os.path.join(
|
||||
self.deps_cpp_info["catch2"].rootpath, "licenses", "LICENSE.txt"))
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
self.run("%s -s" % bin_path, run_environment=True)
|
||||
|
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
@@ -1 +1,2 @@
|
||||
github: "horenmar"
|
||||
custom: "https://www.paypal.me/horenmar"
|
||||
|
86
.github/workflows/linux-other-builds.yml
vendored
Normal file
86
.github/workflows/linux-other-builds.yml
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
# The builds in this file are more complex (e.g. they need custom CMake
|
||||
# configuration) and thus are unsuitable to the simple build matrix
|
||||
# approach used in simple-builds
|
||||
name: Linux builds (complex)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.build_description}}, ${{matrix.cxx}}, C++${{matrix.std}} ${{matrix.build_type}}
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
# We add builds one by one in this case, because there are no
|
||||
# dimensions that are shared across the builds
|
||||
include:
|
||||
|
||||
# Single surrogate header build
|
||||
- cxx: clang++-10
|
||||
build_description: Surrogates build
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: clang-10
|
||||
cmake_configurations: -DCATCH_BUILD_SURROGATES=ON
|
||||
|
||||
# Extras and examples with gcc-7
|
||||
- cxx: g++-7
|
||||
build_description: Extras + Examples
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: g++-7
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
- cxx: g++-7
|
||||
build_description: Extras + Examples
|
||||
build_type: Release
|
||||
std: 14
|
||||
other_pkgs: g++-7
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
|
||||
# Extras and examples with Clang-10
|
||||
- cxx: clang++-10
|
||||
build_description: Extras + Examples
|
||||
build_type: Debug
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
- cxx: clang++-10
|
||||
build_description: Extras + Examples
|
||||
build_type: Release
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON
|
||||
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare environment
|
||||
run: sudo apt-get install -y ninja-build ${{matrix.other_pkgs}}
|
||||
|
||||
- name: Configure build
|
||||
working-directory: ${{runner.workspace}}
|
||||
env:
|
||||
CXX: ${{matrix.cxx}}
|
||||
CXXFLAGS: ${{matrix.cxxflags}}
|
||||
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
|
||||
# This is important
|
||||
run: |
|
||||
cmake -Bbuild -H$GITHUB_WORKSPACE \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
-DCMAKE_CXX_EXTENSIONS=OFF \
|
||||
-DCATCH_DEVELOPMENT_BUILD=ON \
|
||||
${{matrix.cmake_configurations}} \
|
||||
-G Ninja
|
||||
|
||||
- name: Build tests + lib
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: ninja
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
CTEST_OUTPUT_ON_FAILURE: 1
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
# Hardcode 2 cores we know are there
|
||||
run: ctest -C ${{matrix.build_type}} -j 2
|
97
.github/workflows/linux-simple-builds.yml
vendored
Normal file
97
.github/workflows/linux-simple-builds.yml
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
name: Linux builds (basic)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}}
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx:
|
||||
# - g++-6
|
||||
- g++-7
|
||||
- g++-8
|
||||
- g++-9
|
||||
- g++-10
|
||||
- clang++-6.0
|
||||
- clang++-7
|
||||
- clang++-8
|
||||
- clang++-9
|
||||
- clang++-10
|
||||
build_type: [Debug, Release]
|
||||
std: [14]
|
||||
include:
|
||||
# cannot be installed on ubuntu-20.04 be default?
|
||||
# - cxx: g++-6
|
||||
# other_pkgs: g++-6
|
||||
- cxx: g++-7
|
||||
other_pkgs: g++-7
|
||||
- cxx: g++-8
|
||||
other_pkgs: g++-8
|
||||
- cxx: g++-9
|
||||
other_pkgs: g++-9
|
||||
- cxx: g++-10
|
||||
other_pkgs: g++-10
|
||||
- cxx: clang++-6.0
|
||||
other_pkgs: clang-6.0
|
||||
- cxx: clang++-7
|
||||
other_pkgs: clang-7
|
||||
- cxx: clang++-8
|
||||
other_pkgs: clang-8
|
||||
- cxx: clang++-9
|
||||
other_pkgs: clang-9
|
||||
- cxx: clang++-10
|
||||
other_pkgs: clang-10
|
||||
# Clang 6 + C++17
|
||||
# does not work with the default libstdc++ version thanks
|
||||
# to a disagreement on variant implementation.
|
||||
# - cxx: clang++-6.0
|
||||
# build_type: Debug
|
||||
# std: 17
|
||||
# other_pkgs: clang-6.0
|
||||
# - cxx: clang++-6.0
|
||||
# build_type: Release
|
||||
# std: 17
|
||||
# other_pkgs: clang-6.0
|
||||
# Clang 10 + C++17
|
||||
- cxx: clang++-10
|
||||
build_type: Debug
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
- cxx: clang++-10
|
||||
build_type: Release
|
||||
std: 17
|
||||
other_pkgs: clang-10
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare environment
|
||||
run: sudo apt-get install -y ninja-build ${{matrix.other_pkgs}}
|
||||
|
||||
- name: Configure build
|
||||
working-directory: ${{runner.workspace}}
|
||||
env:
|
||||
CXX: ${{matrix.cxx}}
|
||||
CXXFLAGS: ${{matrix.cxxflags}}
|
||||
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
|
||||
# This is important
|
||||
run: |
|
||||
cmake -Bbuild -H$GITHUB_WORKSPACE \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
-DCMAKE_CXX_EXTENSIONS=OFF \
|
||||
-DCATCH_DEVELOPMENT_BUILD=ON \
|
||||
-G Ninja
|
||||
|
||||
- name: Build tests + lib
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: ninja
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
CTEST_OUTPUT_ON_FAILURE: 1
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
# Hardcode 2 cores we know are there
|
||||
run: ctest -C ${{matrix.build_type}} -j 2
|
45
.github/workflows/mac-builds.yml
vendored
Normal file
45
.github/workflows/mac-builds.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Mac builds
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-10.15
|
||||
strategy:
|
||||
matrix:
|
||||
cxx:
|
||||
- g++-9
|
||||
- clang++
|
||||
build_type: [Debug, Release]
|
||||
std: [14, 17]
|
||||
include:
|
||||
- build_type: Debug
|
||||
examples: ON
|
||||
extra_tests: ON
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Configure build
|
||||
working-directory: ${{runner.workspace}}
|
||||
env:
|
||||
CXX: ${{matrix.cxx}}
|
||||
CXXFLAGS: ${{matrix.cxxflags}}
|
||||
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
|
||||
# This is important
|
||||
run: |
|
||||
cmake -Bbuild -H$GITHUB_WORKSPACE \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
-DCATCH_DEVELOPMENT_BUILD=ON -DCATCH_BUILD_EXAMPLES=${{matrix.examples}} \
|
||||
-DCATCH_BUILD_EXTRA_TESTS=${{matrix.examples}}
|
||||
|
||||
- name: Build tests + lib
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
run: make -j 2
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
CTEST_OUTPUT_ON_FAILURE: 1
|
||||
working-directory: ${{runner.workspace}}/build
|
||||
# Hardcode 2 cores we know are there
|
||||
run: ctest -C ${{matrix.build_type}} -j 2
|
36
.github/workflows/validate-header-guards.yml
vendored
Normal file
36
.github/workflows/validate-header-guards.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: Check header guards
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Set the type of machine to run on
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Dependencies
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.7'
|
||||
- name: Install checkguard
|
||||
run: pip install guardonce
|
||||
|
||||
- name: Check that include guards are properly named
|
||||
run: |
|
||||
wrong_files=$(checkguard -r src/catch2/ -p "name | append _INCLUDED | upper")
|
||||
if [[ $wrong_files ]]; then
|
||||
echo "Files with wrong header guard:"
|
||||
echo $wrong_files
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check that there are no duplicated filenames
|
||||
run: |
|
||||
./tools/scripts/checkDuplicateFilenames.py
|
||||
|
||||
- name: Check that all source files have the correct license header
|
||||
run: |
|
||||
./tools/scripts/checkLicense.py
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -30,3 +30,4 @@ benchmark-dir
|
||||
.conan/test_package/build
|
||||
bazel-*
|
||||
build-fuzzers
|
||||
debug-build
|
||||
|
213
.travis.yml
213
.travis.yml
@@ -1,213 +0,0 @@
|
||||
language: cpp
|
||||
dist: xenial
|
||||
|
||||
|
||||
branches:
|
||||
except:
|
||||
- /dev-appveyor.*/
|
||||
|
||||
common_sources: &all_sources
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-xenial
|
||||
- llvm-toolchain-xenial-3.8
|
||||
- llvm-toolchain-xenial-3.9
|
||||
- llvm-toolchain-xenial-4.0
|
||||
- llvm-toolchain-xenial-5.0
|
||||
- llvm-toolchain-xenial-6.0
|
||||
- llvm-toolchain-xenial-7
|
||||
- llvm-toolchain-xenial-8
|
||||
|
||||
|
||||
matrix:
|
||||
include:
|
||||
# Clang builds
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-3.8']
|
||||
env: COMPILER='clang++-3.8' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-3.8', 'lcov']
|
||||
env: COMPILER='clang++-3.8' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-3.9']
|
||||
env: COMPILER='clang++-3.9' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-4.0']
|
||||
env: COMPILER='clang++-4.0' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-5.0']
|
||||
env: COMPILER='clang++-5.0' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-6.0']
|
||||
env: COMPILER='clang++-6.0' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-6.0', 'libstdc++-8-dev']
|
||||
env: COMPILER='clang++-6.0' CPP17=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-7']
|
||||
env: COMPILER='clang++-7' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-8']
|
||||
env: COMPILER='clang++-8' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-8', 'libstdc++-8-dev']
|
||||
env: COMPILER='clang++-8' CPP17=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||
|
||||
|
||||
# GCC builds
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['g++-5']
|
||||
env: COMPILER='g++-5' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['g++-6']
|
||||
env: COMPILER='g++-6' CPP14=1
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['g++-7', 'lcov']
|
||||
env: COMPILER='g++-7' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['g++-8']
|
||||
env: COMPILER='g++-8' CPP17=1
|
||||
|
||||
# OSX Clang Builds
|
||||
- os: osx
|
||||
osx_image: xcode9.4
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' CPP14=1
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode10.3
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' CPP14=1
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode11.2
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' CPP14=1
|
||||
|
||||
- os: osx
|
||||
osx_image: xcode11.2
|
||||
compiler: clang
|
||||
env: COMPILER='clang++' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||
|
||||
|
||||
|
||||
# Special builds, e.g. conan
|
||||
- language: python
|
||||
python:
|
||||
- "3.7"
|
||||
install:
|
||||
- pip install conan-package-tools
|
||||
env:
|
||||
- CONAN_GCC_VERSIONS=8
|
||||
- CONAN_DOCKER_IMAGE=conanio/gcc8
|
||||
- CPP14=1
|
||||
script:
|
||||
- python .conan/build.py
|
||||
|
||||
before_script:
|
||||
- export CXX=${COMPILER}
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
# We want to regenerate the amalgamated header if the extra tests
|
||||
# are enabled.
|
||||
- |
|
||||
if [[ ${EXTRAS} -eq 1 ]]; then
|
||||
python3 ./tools/scripts/generateAmalgamatedFiles.py
|
||||
fi
|
||||
|
||||
- |
|
||||
if [[ ${CPP17} -eq 1 ]]; then
|
||||
export CPP_STANDARD=17
|
||||
elif [[ ${CPP14} -eq 1 ]]; then
|
||||
export CPP_STANDARD=14
|
||||
else
|
||||
travis_terminate 4;
|
||||
fi
|
||||
|
||||
# Use Debug builds for running Valgrind and building examples
|
||||
- cmake -H. -BBuild-Debug -DCMAKE_BUILD_TYPE=Debug -Wdev -DCATCH_USE_VALGRIND=${VALGRIND} -DCATCH_BUILD_EXAMPLES=${EXAMPLES} -DCATCH_ENABLE_COVERAGE=${COVERAGE} -DCATCH_BUILD_EXTRA_TESTS=${EXTRAS} -DCMAKE_CXX_STANDARD=${CPP_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=On -DCMAKE_CXX_EXTENSIONS=OFF -DCATCH_DEVELOPMENT_BUILD=ON
|
||||
# Don't bother with release build for coverage build
|
||||
- cmake -H. -BBuild-Release -DCMAKE_BUILD_TYPE=Release -Wdev -DCMAKE_CXX_STANDARD=${CPP_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=On -DCMAKE_CXX_EXTENSIONS=OFF -DCATCH_DEVELOPMENT_BUILD=ON
|
||||
|
||||
|
||||
script:
|
||||
- cd Build-Debug
|
||||
- make -j 2
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j 2
|
||||
# Coverage collection does not work for OS X atm
|
||||
- |
|
||||
if [[ "${TRAVIS_OS_NAME}" == "linux" ]] && [[ "${COVERAGE}" == "1" ]]; then
|
||||
make gcov
|
||||
make lcov
|
||||
bash <(curl -s https://codecov.io/bash) -X gcov || echo "Codecov did not collect coverage reports"
|
||||
fi
|
||||
- # Go to release build
|
||||
- cd ../Build-Release
|
||||
- make -j 2
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j 2
|
@@ -45,7 +45,7 @@ function(add_warnings_to_targets targets)
|
||||
"-Wglobal-constructors"
|
||||
"-Wmissing-noreturn"
|
||||
"-Wparentheses"
|
||||
"-Wextra-semi-stmt"
|
||||
"-Wextra-semi"
|
||||
"-Wunreachable-code"
|
||||
"-Wstrict-aliasing"
|
||||
"-Wreturn-std-move"
|
||||
@@ -63,6 +63,7 @@ function(add_warnings_to_targets targets)
|
||||
"-Wdeprecated-register"
|
||||
"-Wsuggest-override"
|
||||
"-Wshadow"
|
||||
"-Wold-style-cast"
|
||||
)
|
||||
foreach(warning ${CHECKED_WARNING_FLAGS})
|
||||
add_cxx_flag_if_supported_to_targets(${warning} "${targets}")
|
||||
@@ -76,3 +77,13 @@ function(add_warnings_to_targets targets)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Adds flags required for reproducible build to the target
|
||||
# Currently only supports GCC and Clang
|
||||
function(add_build_reproducibility_settings target)
|
||||
# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
|
||||
if(("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 8) OR
|
||||
("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 10))
|
||||
target_compile_options(${target} PRIVATE "-ffile-prefix-map=${CATCH_DIR}=.")
|
||||
endif()
|
||||
endfunction()
|
||||
|
@@ -1,3 +1,5 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||
|
||||
|
@@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.5)
|
||||
# disable testsuite in that case
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
set(NOT_SUBPROJECT ON)
|
||||
else()
|
||||
set(NOT_SUBPROJECT OFF)
|
||||
endif()
|
||||
|
||||
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
|
||||
@@ -17,6 +19,8 @@ cmake_dependent_option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF "CATCH_DE
|
||||
cmake_dependent_option(CATCH_BUILD_FUZZERS "Build fuzzers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_ENABLE_WERROR "Enables Werror during build" ON "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_BUILD_SURROGATES "Enable generating and building surrogate TUs for the main headers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
|
||||
|
||||
# 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
|
||||
@@ -25,6 +29,11 @@ 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()
|
||||
|
||||
if(CMAKE_VERSION VERSION_GREATER 3.8)
|
||||
# Enable IPO for CMake versions that support it
|
||||
cmake_policy(SET CMP0069 NEW)
|
||||
endif()
|
||||
|
||||
|
||||
project(Catch2 LANGUAGES CXX VERSION 3.0.0)
|
||||
|
||||
@@ -32,7 +41,9 @@ project(Catch2 LANGUAGES CXX VERSION 3.0.0)
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(CTest)
|
||||
if(CATCH_DEVELOPMENT_BUILD)
|
||||
include(CTest)
|
||||
endif()
|
||||
|
||||
# This variable is used in some subdirectories, so we need it here, rather
|
||||
# than later in the install block
|
||||
@@ -103,27 +114,11 @@ if (NOT_SUBPROJECT)
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
|
||||
## TODO: Catch2 main target?
|
||||
## Install some cpp file as well?
|
||||
|
||||
# By default, FooConfigVersion is tied to architecture that it was
|
||||
# generated on. Because Catch2 is header-only, it is arch-independent
|
||||
# and thus Catch2ConfigVersion should not be tied to the architecture
|
||||
# it was generated on.
|
||||
#
|
||||
# CMake does not provide a direct customization point for this in
|
||||
# `write_basic_package_version_file`, but it can be accomplished
|
||||
# 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})
|
||||
set(CMAKE_SIZEOF_VOID_P "")
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
||||
COMPATIBILITY
|
||||
SameMajorVersion
|
||||
)
|
||||
set(CMAKE_SIZEOF_VOID_P ${CATCH2_CMAKE_SIZEOF_VOID_P})
|
||||
|
||||
install(
|
||||
FILES
|
||||
|
47
README.md
47
README.md
@@ -1,24 +1,41 @@
|
||||
<a id="top"></a>
|
||||

|
||||

|
||||
|
||||
[](https://github.com/catchorg/catch2/releases)
|
||||
[](https://travis-ci.org/catchorg/Catch2)
|
||||
[](https://ci.appveyor.com/project/catchorg/catch2)
|
||||
[](https://codecov.io/gh/catchorg/Catch2)
|
||||
<!-- We can eventually bring this back, but the upload script will have to be more complex -->
|
||||
<!-- [](https://wandbox.org/permlink/LzYWgcPrcy9yQmed) -->
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/linux-simple-builds.yml)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/linux-other-builds.yml)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/mac-builds.yml)
|
||||
[](https://ci.appveyor.com/project/catchorg/catch2)
|
||||
[](https://codecov.io/gh/catchorg/Catch2)
|
||||
[](https://godbolt.org/z/9x9qoM)
|
||||
[](https://discord.gg/4CWS9zD)
|
||||
|
||||
|
||||
## Catch2 is released!
|
||||
## What's the Catch2?
|
||||
|
||||
If you've been using an earlier version of Catch, please see the
|
||||
Breaking Changes section of [the release notes](https://github.com/catchorg/Catch2/releases/tag/v2.0.1)
|
||||
before moving to Catch2. You might also like to read [this blog post](https://levelofindirection.com/blog/catch2-released.html) for more details.
|
||||
Catch2 is mainly a unit testing framework for C++, but it also
|
||||
provides basic micro-benchmarking features, and simple BDD macros.
|
||||
|
||||
## What's the Catch?
|
||||
Catch2's main advantage is that using it is both simple and natural.
|
||||
Tests autoregister themselves and do not have to be named with valid
|
||||
identifiers, assertions look like normal C++ code, and sections provide
|
||||
a nice way to share set-up and tear-down code in tests.
|
||||
|
||||
|
||||
## Catch2 v3 is being developed!
|
||||
|
||||
You are on the `devel` branch, where the next major version, v3, of
|
||||
Catch2 is being developed. As it is a significant rework, you will
|
||||
find that parts of this documentation are likely still stuck on v2.
|
||||
|
||||
For stable (and documentation-matching) version of Catch2, [go to the
|
||||
`v2.x` branch](https://github.com/catchorg/Catch2/tree/v2.x).
|
||||
|
||||
For migrating from the v2 releases to v3, you should look at [our
|
||||
documentation](docs/migrate-v2-to-v3.md#top). It provides a simple
|
||||
guidelines on getting started, and collects most common migration
|
||||
problems.
|
||||
|
||||
Catch2 is a multi-paradigm test framework for C++.
|
||||
|
||||
## How to use it
|
||||
This documentation comprises these three parts:
|
||||
@@ -27,7 +44,9 @@ This documentation comprises these three parts:
|
||||
* [Tutorial](docs/tutorial.md#top) - getting started
|
||||
* [Reference section](docs/Readme.md#top) - all the details
|
||||
|
||||
|
||||
## More
|
||||
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/catchorg/Catch2/issues)
|
||||
* For discussion or questions please use [the dedicated Google Groups forum](https://groups.google.com/forum/?fromgroups#!forum/catch-forum) or our [Discord](https://discord.gg/4CWS9zD)
|
||||
* See [who else is using Catch2](docs/opensource-users.md#top)
|
||||
* For discussion or questions please use [our Discord](https://discord.gg/4CWS9zD)
|
||||
* See who else is using Catch2 in [Open Source Software](docs/opensource-users.md#top)
|
||||
or [commercially](docs/commercial-users.md#top).
|
||||
|
19
SECURITY.md
Normal file
19
SECURITY.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
* Versions 1.x (branch Catch1.x) are no longer supported.
|
||||
* Versions 2.x (branch v2.x) are currently supported.
|
||||
* `devel` branch serves for stable-ish development and is supported,
|
||||
but branches `devel-*` are considered short lived and are not supported separately.
|
||||
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Due to its nature as a _unit_ test framework, Catch2 shouldn't interact
|
||||
with untrusted inputs and there shouldn't be many security vulnerabilities
|
||||
in it.
|
||||
|
||||
However, if you find one you send email to martin <dot> horenovsky <at>
|
||||
gmail <dot> com. If you want to encrypt the email, my pgp key is
|
||||
`E29C 46F3 B8A7 5028 6079 3B7D ECC9 C20E 314B 2360`.
|
@@ -18,10 +18,13 @@ init:
|
||||
|
||||
install:
|
||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { pip --disable-pip-version-check install codecov }
|
||||
# This removes our changes to PATH. Keep this step last!
|
||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { .\tools\misc\installOpenCppCoverage.ps1 }
|
||||
|
||||
|
||||
before_build:
|
||||
# We need to modify PATH again, because it was reset since the "init" step
|
||||
- set PATH=C:\Python35;C:\Python35\Scripts;%PATH%
|
||||
- set CXXFLAGS=%additional_flags%
|
||||
# If we are building examples/extra-tests, we need to regenerate the amalgamated files
|
||||
- cmd: if "%examples%"=="1" ( python .\tools\scripts\generateAmalgamatedFiles.py )
|
||||
@@ -48,8 +51,9 @@ test_script:
|
||||
# build explicitly.
|
||||
environment:
|
||||
matrix:
|
||||
- FLAVOR: VS 2019 x64 Debug
|
||||
- FLAVOR: VS 2019 x64 Debug Surrogates
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
surrogates: 1
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
|
||||
|
@@ -15,7 +15,7 @@ coverage:
|
||||
|
||||
|
||||
codecov:
|
||||
branch: master
|
||||
branch: devel
|
||||
max_report_age: off
|
||||
|
||||
comment:
|
||||
|
30
conanfile.py
30
conanfile.py
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
from conans import ConanFile, CMake
|
||||
|
||||
from conans import ConanFile, CMake, tools
|
||||
|
||||
class CatchConan(ConanFile):
|
||||
name = "catch2"
|
||||
@@ -15,8 +14,7 @@ class CatchConan(ConanFile):
|
||||
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
|
||||
options = {"with_main": [True, False]}
|
||||
default_options = {"with_main": True}
|
||||
generators = "cmake"
|
||||
|
||||
def _configure_cmake(self):
|
||||
cmake = CMake(self)
|
||||
@@ -27,6 +25,14 @@ class CatchConan(ConanFile):
|
||||
return cmake
|
||||
|
||||
def build(self):
|
||||
# We need this workaround until the toolchains feature
|
||||
# to inject stuff like MD/MT
|
||||
line_to_replace = 'list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")'
|
||||
tools.replace_in_file("CMakeLists.txt", line_to_replace,
|
||||
'''{}
|
||||
include("{}/conanbuildinfo.cmake")
|
||||
conan_basic_setup()'''.format(line_to_replace, self.install_folder.replace("\\", "/")))
|
||||
|
||||
cmake = self._configure_cmake()
|
||||
cmake.build()
|
||||
|
||||
@@ -35,11 +41,17 @@ class CatchConan(ConanFile):
|
||||
cmake = self._configure_cmake()
|
||||
cmake.install()
|
||||
|
||||
def package_id(self):
|
||||
del self.info.options.with_main
|
||||
|
||||
def package_info(self):
|
||||
self.cpp_info.libs = [
|
||||
'Catch2Main', 'Catch2'] if self.options.with_main else ['Catch2']
|
||||
self.cpp_info.names["cmake_find_package"] = "Catch2"
|
||||
self.cpp_info.names["cmake_find_package_multi"] = "Catch2"
|
||||
# Catch2
|
||||
self.cpp_info.components["catch2base"].names["cmake_find_package"] = "Catch2"
|
||||
self.cpp_info.components["catch2base"].names["cmake_find_package_multi"] = "Catch2"
|
||||
self.cpp_info.components["catch2base"].names["pkg_config"] = "Catch2"
|
||||
self.cpp_info.components["catch2base"].libs = ["Catch2"]
|
||||
# Catch2WithMain
|
||||
self.cpp_info.components["catch2main"].names["cmake_find_package"] = "Catch2WithMain"
|
||||
self.cpp_info.components["catch2main"].names["cmake_find_package_multi"] = "Catch2WithMain"
|
||||
self.cpp_info.components["catch2main"].names["pkg_config"] = "Catch2WithMain"
|
||||
self.cpp_info.components["catch2main"].libs = ["Catch2Main"]
|
||||
self.cpp_info.components["catch2main"].requires = ["catch2base"]
|
||||
|
@@ -25,17 +25,16 @@ Running:
|
||||
* [Command line](command-line.md#top)
|
||||
|
||||
Odds and ends:
|
||||
* [Frequently Asked Questions (FAQ)](faq.md#top)
|
||||
* [CMake integration](cmake-integration.md#top)
|
||||
* [CI and other miscellaneous pieces](ci-and-misc.md#top)
|
||||
|
||||
FAQ:
|
||||
* [Why are my tests slow to compile?](slow-compiles.md#top)
|
||||
* [Known limitations](limitations.md#top)
|
||||
|
||||
Other:
|
||||
* [Why Catch?](why-catch.md#top)
|
||||
* [Open Source Projects using Catch](opensource-users.md#top)
|
||||
* [Commercial Projects using Catch](commercial-users.md#top)
|
||||
* [Why Catch2?](why-catch.md#top)
|
||||
* [Migrating from v2 to v3](migrate-v2-to-v3.md#top)
|
||||
* [Open Source Projects using Catch2](opensource-users.md#top)
|
||||
* [Commercial Projects using Catch2](commercial-users.md#top)
|
||||
* [Contributing](contributing.md#top)
|
||||
* [Release Notes](release-notes.md#top)
|
||||
* [Deprecations and incoming changes](deprecations.md#top)
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<a id="top"></a>
|
||||
# Authoring benchmarks
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
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
|
||||
@@ -11,7 +11,8 @@ First off, let's go over some terminology that will be used throughout this
|
||||
guide.
|
||||
|
||||
- *User code*: user code is the code that the user provides to be measured.
|
||||
- *Run*: one run is one execution of the user code.
|
||||
- *Run*: one run is one execution of the user code. Sometimes also referred
|
||||
to as an _iteration_.
|
||||
- *Sample*: one sample is one data point obtained by measuring the time it takes
|
||||
to perform a certain number of runs. One sample can consist of more than one
|
||||
run if the clock available does not have enough resolution to accurately
|
||||
|
@@ -95,7 +95,7 @@ can use `pkg-config` to get its include path: `pkg-config --cflags catch2`.
|
||||
|
||||
### gdb and lldb scripts
|
||||
|
||||
Catch2's `contrib` folder also contains two simple debugger scripts,
|
||||
Catch2's `extras` folder also contains two simple debugger scripts,
|
||||
`gdbinit` for `gdb` and `lldbinit` for `lldb`. If loaded into their
|
||||
respective debugger, these will tell it to step over Catch2's internals
|
||||
when stepping through code.
|
||||
|
@@ -2,7 +2,7 @@
|
||||
# CMake integration
|
||||
|
||||
**Contents**<br>
|
||||
[CMake target](#cmake-target)<br>
|
||||
[CMake targets](#cmake-targets)<br>
|
||||
[Automatic test registration](#automatic-test-registration)<br>
|
||||
[CMake project options](#cmake-project-options)<br>
|
||||
[Installing Catch2 from git repository](#installing-catch2-from-git-repository)<br>
|
||||
@@ -15,26 +15,33 @@ integration points for our users.
|
||||
2) Catch2's repository contains CMake scripts for automatic registration
|
||||
of `TEST_CASE`s in CTest
|
||||
|
||||
## CMake target
|
||||
## CMake targets
|
||||
|
||||
Catch2's CMake build exports an interface target `Catch2::Catch2`. Linking
|
||||
against it will add the proper include path and all necessary capabilities
|
||||
to the resulting binary.
|
||||
Catch2's CMake build exports two targets, `Catch2::Catch2`, and
|
||||
`Catch2::Catch2WithMain`. If you do not need custom `main` function,
|
||||
you should be using the latter (and only the latter). Linking against
|
||||
it will add the proper include paths and link your target together with
|
||||
2 static libraries that implement Catch2 and its main respectively.
|
||||
If you need custom `main`, you should link only against `Catch2::Catch2`.
|
||||
|
||||
This means that if Catch2 has been installed on the system, it should be
|
||||
enough to do:
|
||||
This means that if Catch2 has been installed on the system, it should
|
||||
be enough to do
|
||||
```cmake
|
||||
find_package(Catch2 REQUIRED)
|
||||
target_link_libraries(tests Catch2::Catch2)
|
||||
find_package(Catch2 3 REQUIRED)
|
||||
# These tests can use the Catch2-provided main
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
|
||||
|
||||
# These tests need their own main
|
||||
add_executable(custom-main-tests test.cpp test-main.cpp)
|
||||
target_link_libraries(custom-main-tests PRIVATE Catch2::Catch2)
|
||||
```
|
||||
|
||||
These targets are also provided when Catch2 is used as a subdirectory.
|
||||
Assuming Catch2 has been cloned to `lib/Catch2`, you only need to replace
|
||||
the `find_package` call with `add_subdirectory(lib/Catch2)` and the snippet
|
||||
above still works.
|
||||
|
||||
This target is also provided when Catch2 is used as a subdirectory.
|
||||
Assuming that Catch2 has been cloned to `lib/Catch2`:
|
||||
```cmake
|
||||
add_subdirectory(lib/Catch2)
|
||||
target_link_libraries(tests Catch2::Catch2)
|
||||
```
|
||||
|
||||
Another possibility is to use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html):
|
||||
```cmake
|
||||
@@ -43,21 +50,24 @@ Include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v2.13.1)
|
||||
GIT_TAG v3.0.0-preview3
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
target_link_libraries(tests Catch2::Catch2)
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
|
||||
```
|
||||
|
||||
|
||||
## Automatic test registration
|
||||
|
||||
Catch2's repository also contains two CMake scripts that help users
|
||||
with automatically registering their `TEST_CASE`s with CTest. They
|
||||
can be found in the `contrib` folder, and are
|
||||
can be found in the `extras` folder, and are
|
||||
|
||||
1) `Catch.cmake` (and its dependency `CatchAddTests.cmake`)
|
||||
2) `ParseAndAddCatchTests.cmake`
|
||||
2) `ParseAndAddCatchTests.cmake` (deprecated)
|
||||
|
||||
If Catch2 has been installed in system, both of these can be used after
|
||||
doing `find_package(Catch2 REQUIRED)`. Otherwise you need to add them
|
||||
@@ -78,13 +88,25 @@ project(baz LANGUAGES CXX VERSION 0.0.1)
|
||||
|
||||
find_package(Catch2 REQUIRED)
|
||||
add_executable(foo test.cpp)
|
||||
target_link_libraries(foo Catch2::Catch2)
|
||||
target_link_libraries(foo PRIVATE Catch2::Catch2)
|
||||
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
catch_discover_tests(foo)
|
||||
```
|
||||
|
||||
When using `FetchContent`, `include(Catch)` will fail unless
|
||||
`CMAKE_MODULE_PATH` is explicitly updated to include the extras
|
||||
directory.
|
||||
|
||||
```cmake
|
||||
# ... FetchContent ...
|
||||
#
|
||||
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
catch_discover_tests()
|
||||
```
|
||||
|
||||
#### Customization
|
||||
`catch_discover_tests` can be given several extra argumets:
|
||||
@@ -176,10 +198,17 @@ the output file name e.g. ".xml".
|
||||
|
||||
### `ParseAndAddCatchTests.cmake`
|
||||
|
||||
⚠ This script is [deprecated](https://github.com/catchorg/Catch2/pull/2120)
|
||||
in Catch2 2.13.4 and superseded by the above approach using `catch_discover_tests`.
|
||||
See [#2092](https://github.com/catchorg/Catch2/issues/2092) for details.
|
||||
|
||||
`ParseAndAddCatchTests` works by parsing all implementation files
|
||||
associated with the provided target, and registering them via CTest's
|
||||
`add_test`. This approach has some limitations, such as the fact that
|
||||
commented-out tests will be registered anyway.
|
||||
commented-out tests will be registered anyway. More serious, only a
|
||||
subset of the assertion macros currently available in Catch can be
|
||||
detected by this script and tests with any macros that cannot be
|
||||
parsed are *silently ignored*.
|
||||
|
||||
|
||||
#### Usage
|
||||
@@ -191,7 +220,7 @@ project(baz LANGUAGES CXX VERSION 0.0.1)
|
||||
|
||||
find_package(Catch2 REQUIRED)
|
||||
add_executable(foo test.cpp)
|
||||
target_link_libraries(foo Catch2::Catch2)
|
||||
target_link_libraries(foo PRIVATE Catch2::Catch2)
|
||||
|
||||
include(CTest)
|
||||
include(ParseAndAddCatchTests)
|
||||
@@ -230,7 +259,21 @@ ParseAndAddCatchTests(bar)
|
||||
## CMake project options
|
||||
|
||||
Catch2's CMake project also provides some options for other projects
|
||||
that consume it. These are
|
||||
that consume it. These are:
|
||||
|
||||
* `BUILD_TESTING` -- When `ON` and the project is not used as a subproject,
|
||||
Catch2's test binary will be built. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_DOCS` -- When `ON`, Catch2's documentation will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_HELPERS` -- When `ON`, Catch2's extras folder will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `CATCH_DEVELOPMENT_BUILD` -- When `ON`, configures the build for development
|
||||
of Catch2. This means enabling test projects, warnings and so on.
|
||||
Defaults to `OFF`.
|
||||
|
||||
|
||||
Enabling `CATCH_DEVELOPMENT_BUILD` also enables further configuration
|
||||
customization options:
|
||||
|
||||
* `CATCH_BUILD_TESTING` -- When `ON`, Catch2's SelfTest project will be
|
||||
built. Defaults to `ON`. Note that Catch2 also obeys `BUILD_TESTING` CMake
|
||||
@@ -238,12 +281,15 @@ variable, so _both_ of them need to be `ON` for the SelfTest to be built,
|
||||
and either of them can be set to `OFF` to disable building SelfTest.
|
||||
* `CATCH_BUILD_EXAMPLES` -- When `ON`, Catch2's usage examples will be
|
||||
built. Defaults to `OFF`.
|
||||
* `CATCH_INSTALL_DOCS` -- When `ON`, Catch2's documentation will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_HELPERS` -- When `ON`, Catch2's contrib folder will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `BUILD_TESTING` -- When `ON` and the project is not used as a subproject,
|
||||
Catch2's test binary will be built. Defaults to `ON`.
|
||||
* `CATCH_BUILD_EXTRA_TESTS` -- When `ON`, Catch2's extra tests will be
|
||||
built. Defaults to `OFF`.
|
||||
* `CATCH_BUILD_FUZZERS` -- When `ON`, Catch2 fuzzing entry points will
|
||||
be built. Defaults to `OFF`.
|
||||
* `CATCH_ENABLE_WERROR` -- When `ON`, adds `-Werror` or equivalent flag
|
||||
to the compilation. Defaults to `ON`.
|
||||
* `CATCH_BUILD_SURROGATES` -- When `ON`, each header in Catch2 will be
|
||||
compiled separately to ensure that they are self-sufficient.
|
||||
Defaults to `OFF`.
|
||||
|
||||
|
||||
## Installing Catch2 from git repository
|
||||
|
@@ -29,14 +29,14 @@
|
||||
[Specify the section to run](#specify-the-section-to-run)<br>
|
||||
[Filenames as tags](#filenames-as-tags)<br>
|
||||
[Override output colouring](#override-output-colouring)<br>
|
||||
[Test Sharding](#test-sharding)<br>
|
||||
[Allow running the binary without tests](#allow-running-the-binary-without-tests)<br>
|
||||
|
||||
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available.
|
||||
Click one of the following links to take you straight to that option - or scroll on to browse the available options.
|
||||
|
||||
<a href="#specifying-which-tests-to-run"> ` <test-spec> ...`</a><br />
|
||||
<a href="#usage"> ` -h, -?, --help`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` -l, --list-tests`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` -t, --list-tags`</a><br />
|
||||
<a href="#showing-results-for-successful-tests"> ` -s, --success`</a><br />
|
||||
<a href="#breaking-into-the-debugger"> ` -b, --break`</a><br />
|
||||
<a href="#eliding-assertions-expected-to-throw"> ` -e, --nothrow`</a><br />
|
||||
@@ -55,7 +55,8 @@ Click one of the following links to take you straight to that option - or scroll
|
||||
|
||||
</br>
|
||||
|
||||
<a href="#list-test-names-only"> ` --list-test-names-only`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-tests`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-tags`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-reporters`</a><br />
|
||||
<a href="#order"> ` --order`</a><br />
|
||||
<a href="#rng-seed"> ` --rng-seed`</a><br />
|
||||
@@ -67,6 +68,10 @@ Click one of the following links to take you straight to that option - or scroll
|
||||
<a href="#benchmark-no-analysis"> ` --benchmark-no-analysis`</a><br />
|
||||
<a href="#benchmark-warmup-time"> ` --benchmark-warmup-time`</a><br />
|
||||
<a href="#use-colour"> ` --use-colour`</a><br />
|
||||
<a href="#test-sharding"> ` --shard-count`</a><br />
|
||||
<a href="#test-sharding"> ` --shard-index`</a><br />
|
||||
<a href=#no-tests-override> ` --allow-running-no-tests`</a><br />
|
||||
<a href=#output-verbosity> ` --verbosity`</a><br />
|
||||
|
||||
</br>
|
||||
|
||||
@@ -93,7 +98,8 @@ Inclusions and exclusions are evaluated in left-to-right order.
|
||||
|
||||
Test case examples:
|
||||
|
||||
<pre>thisTestOnly Matches the test case called, 'thisTestOnly'
|
||||
```
|
||||
thisTestOnly Matches the test case called, 'thisTestOnly'
|
||||
"this test only" Matches the test case called, 'this test only'
|
||||
these* Matches all cases starting with 'these'
|
||||
exclude:notThis Matches all tests except, 'notThis'
|
||||
@@ -101,8 +107,9 @@ 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
|
||||
~[tag1] Matches all tests except those tagged with '[tag1]'
|
||||
-# [#somefile] Matches all tests from the file 'somefile.cpp'
|
||||
</pre>
|
||||
```
|
||||
|
||||
Names within square brackets are interpreted as tags.
|
||||
A series of tags form an AND expression whereas a comma-separated sequence forms an OR expression. e.g.:
|
||||
@@ -116,18 +123,38 @@ Test names containing special characters, such as `,` or `[` can specify them on
|
||||
<a id="choosing-a-reporter-to-use"></a>
|
||||
## Choosing a reporter to use
|
||||
|
||||
<pre>-r, --reporter <reporter></pre>
|
||||
<pre>-r, --reporter <reporter[::output-file]></pre>
|
||||
|
||||
A reporter is an object that formats and structures the output of running tests, and potentially summarises the results. By default a console reporter is used that writes, IDE friendly, textual output. Catch comes bundled with some alternative reporters, but more can be added in client code.<br />
|
||||
The bundled reporters are:
|
||||
> Support for providing output-file through the `-r`, `--reporter` flag was [introduced](https://github.com/catchorg/Catch2/pull/2183) in Catch2 X.Y.Z
|
||||
|
||||
<pre>-r console
|
||||
-r compact
|
||||
-r xml
|
||||
-r junit
|
||||
</pre>
|
||||
Reporters are how the output from Catch2 (results of assertions, tests,
|
||||
benchmarks and so on) is formatted and written out. The default reporter
|
||||
is called the "Console" reporter and is intended to provide relatively
|
||||
verbose and human-friendly output.
|
||||
|
||||
The JUnit reporter is an xml format that follows the structure of the JUnit XML Report ANT task, as consumed by a number of third-party tools, including Continuous Integration servers such as Hudson. If not otherwise needed, the standard XML reporter is preferred as this is a streaming reporter, whereas the Junit reporter needs to hold all its results until the end so it can write the overall results into attributes of the root node.
|
||||
There are multiple built-in reporters, you can see what they do by using the
|
||||
[`--list-reporter`](command-line.md#listing-available-tests-tags-or-reporters)
|
||||
flag. If you need a reporter providing custom format outside of the already
|
||||
provided ones, look at the ["write your own reporter" part of the reporter
|
||||
documentation](reporters.md#writing-your-own-reporter).
|
||||
|
||||
|
||||
This option may be passed multiple times to use multiple (different)
|
||||
reporters at the same time. See the [reporter documentation](reporters.md#multiple-reporters)
|
||||
for details on what the resulting behaviour is. Also note that at most one
|
||||
reporter can be provided without the output-file part of reporter spec.
|
||||
This reporter will use the "default" output destination, based on
|
||||
the [`-o`, `--out`](#sending-output-to-a-file) option.
|
||||
|
||||
> Support for using multiple different reporters at the same time was [introduced](https://github.com/catchorg/Catch2/pull/2183) in Catch2 X.Y.Z
|
||||
|
||||
As with the `--out` option, using `-` for the output file name sends the
|
||||
output to stdout.
|
||||
|
||||
_Note: There is currently no way to escape `::` in the reporter spec,
|
||||
and thus reporter/file names with `::` in them will not work properly.
|
||||
As `::` in paths is relatively obscure (unlike `:`), we do not consider
|
||||
this an issue._
|
||||
|
||||
<a id="breaking-into-the-debugger"></a>
|
||||
## Breaking into the debugger
|
||||
@@ -157,25 +184,37 @@ Sometimes this results in a flood of failure messages and you'd rather just see
|
||||
|
||||
<a id="listing-available-tests-tags-or-reporters"></a>
|
||||
## Listing available tests, tags or reporters
|
||||
<pre>-l, --list-tests
|
||||
-t, --list-tags
|
||||
```
|
||||
--list-tests
|
||||
--list-tags
|
||||
--list-reporters
|
||||
</pre>
|
||||
```
|
||||
|
||||
```-l``` or ```--list-tests``` will list all registered tests, along with any tags.
|
||||
If one or more test-specs have been supplied too then only the matching tests will be listed.
|
||||
> The `--list*` options became customizable through reporters in Catch2 X.Y.Z
|
||||
|
||||
```-t``` or ```--list-tags``` lists all available tags, along with the number of test cases they match. Again, supplying test specs limits the tags that match.
|
||||
`--list-tests` lists all registered tests matching specified test spec.
|
||||
Usually this listing also includes tags, and potentially also other
|
||||
information, like source location, based on verbosity and reporter's design.
|
||||
|
||||
`--list-tags` lists all tags from registered tests matching specified test
|
||||
spec. Usually this also includes number of tests cases they match and
|
||||
similar information.
|
||||
|
||||
`--list-reporters` lists all available reporters and their descriptions.
|
||||
|
||||
```--list-reporters``` lists the available reporters.
|
||||
|
||||
<a id="sending-output-to-a-file"></a>
|
||||
## Sending output to a file
|
||||
<pre>-o, --out <filename>
|
||||
<pre>-o, --out <filename>
|
||||
</pre>
|
||||
|
||||
Use this option to send all output to a file. By default output is sent to stdout (note that uses of stdout and stderr *from within test cases* are redirected and included in the report - so even stderr will effectively end up on stdout).
|
||||
|
||||
Using `-` as the filename sends the output to stdout.
|
||||
|
||||
> Support for `-` as the filename was introduced in Catch2 X.Y.Z
|
||||
|
||||
|
||||
<a id="naming-a-test-run"></a>
|
||||
## Naming a test run
|
||||
<pre>-n, --name <name for test run></pre>
|
||||
@@ -205,16 +244,24 @@ This option transforms tabs and newline characters into ```\t``` and ```\n``` re
|
||||
## Warnings
|
||||
<pre>-w, --warn <warning name></pre>
|
||||
|
||||
Enables reporting of suspicious test states. There are currently two
|
||||
available warnings
|
||||
You can think of Catch2's warnings as the equivalent of `-Werror` (`/WX`)
|
||||
flag for C++ compilers. It turns some suspicious occurences, like a section
|
||||
without assertions, into errors. Because these might be intended, warnings
|
||||
are not enabled by default, but user can opt in.
|
||||
|
||||
You can enable multiple warnings at the same time.
|
||||
|
||||
There are currently two warnings implemented:
|
||||
|
||||
```
|
||||
NoAssertions // Fail test case / leaf section if no assertions
|
||||
// (e.g. `REQUIRE`) is encountered.
|
||||
NoTests // Return non-zero exit code when no test cases were run
|
||||
// Also calls reporter's noMatchingTestCases method
|
||||
NoAssertions // Fail test case / leaf section if no assertions
|
||||
// (e.g. `REQUIRE`) is encountered.
|
||||
UnmatchedTestSpec // Fail test run if any of the CLI test specs did
|
||||
// not match any tests.
|
||||
```
|
||||
|
||||
> `UnmatchedTestSpec` was introduced in Catch2 X.Y.Z.
|
||||
|
||||
|
||||
<a id="reporting-timings"></a>
|
||||
## Reporting timings
|
||||
@@ -224,7 +271,7 @@ When set to ```yes``` Catch will report the duration of each test case, in milli
|
||||
|
||||
<pre>-D, --min-duration <value></pre>
|
||||
|
||||
> `--min-duration` was [introduced](https://github.com/catchorg/Catch2/pull/1910) in Catch 2.13.0
|
||||
> `--min-duration` was [introduced](https://github.com/catchorg/Catch2/pull/1910) in Catch2 2.13.0
|
||||
|
||||
When set, Catch will report the duration of each test case that took more
|
||||
than <value> seconds, in milliseconds. This option is overriden by both
|
||||
@@ -236,15 +283,13 @@ are.
|
||||
## Load test names to run from a file
|
||||
<pre>-f, --input-file <filename></pre>
|
||||
|
||||
Provide the name of a file that contains a list of test case names - one per line. Blank lines are skipped and anything after the comment character, ```#```, is ignored.
|
||||
Provide the name of a file that contains a list of test case names,
|
||||
one per line. Blank lines are skipped.
|
||||
|
||||
A useful way to generate an initial instance of this file is to use the <a href="#list-test-names-only">list-test-names-only</a> option. This can then be manually curated to specify a specific subset of tests - or in a specific order.
|
||||
|
||||
<a id="list-test-names-only"></a>
|
||||
## Just test names
|
||||
<pre>--list-test-names-only</pre>
|
||||
|
||||
This option lists all available tests in a non-indented form, one on each line. This makes it ideal for saving to a file and feeding back into the <a href="#input-file">```-f``` or ```--input-file```</a> option.
|
||||
A useful way to generate an initial instance of this file is to combine
|
||||
the [`--list-tests`](#listing-available-tests-tags-or-reporters) flag with
|
||||
the [`--verbosity quiet`](#output-verbosity) option. You can also
|
||||
use test specs to filter this list down to what you want first.
|
||||
|
||||
|
||||
<a id="order"></a>
|
||||
@@ -275,13 +320,20 @@ is that as long as the random seed is fixed, running only some tests
|
||||
|
||||
<a id="rng-seed"></a>
|
||||
## Specify a seed for the Random Number Generator
|
||||
<pre>--rng-seed <'time'|number></pre>
|
||||
<pre>--rng-seed <'time'|'random-device'|number></pre>
|
||||
|
||||
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. In some cases, you might need to pass the keyword ```time``` in double quotes instead of single quotes.
|
||||
Sets the seed for random number generators used by Catch2. These are used
|
||||
e.g. to shuffle tests when user asks for tests to be in random order.
|
||||
|
||||
Using `time` as the argument asks Catch2 generate the seed through call
|
||||
to `std::time(nullptr)`. This provides very weak randomness and multiple
|
||||
runs of the binary can generate the same seed if they are started close
|
||||
to each other.
|
||||
|
||||
Using `random-device` asks for `std::random_device` to be used instead.
|
||||
If your implementation provides working `std::random_device`, it should
|
||||
be preferred to using `time`. Catch2 uses `std::random_device` by default.
|
||||
|
||||
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)```.
|
||||
|
||||
<a id="libidentify"></a>
|
||||
## Identify framework and version according to the libIdentify standard
|
||||
@@ -300,7 +352,7 @@ either before running any tests, after running all tests - or both, depending on
|
||||
## Specify the number of benchmark samples to collect
|
||||
<pre>--benchmark-samples <# of samples></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 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.
|
||||
@@ -309,7 +361,7 @@ Per sample a clock resolution dependent number of iterations of the user code is
|
||||
## Specify the number of resamples for bootstrapping
|
||||
<pre>--benchmark-resamples <# of resamples></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
After the measurements are performed, statistical [bootstrapping] is performed
|
||||
on the samples. The number of resamples for that bootstrapping is configurable
|
||||
@@ -324,7 +376,7 @@ defaults to 95%).
|
||||
## Specify the confidence-interval for bootstrapping
|
||||
<pre>--benchmark-confidence-interval <confidence-interval></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 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.
|
||||
@@ -334,7 +386,7 @@ 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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 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.
|
||||
@@ -343,7 +395,7 @@ Instead the user code is only measured and the plain mean from the samples is re
|
||||
## Specify the amount of time in milliseconds spent on warming up each test
|
||||
<pre>--benchmark-warmup-time</pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1844) in Catch 2.11.2.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1844) in Catch2 2.11.2.
|
||||
|
||||
Configure the amount of time spent warming up each test.
|
||||
|
||||
@@ -392,7 +444,7 @@ There are some limitations of this feature to be aware of:
|
||||
- Code outside of sections being skipped will still be executed - e.g. any set-up code in the TEST_CASE before the
|
||||
start of the first section.</br>
|
||||
- At time of writing, wildcards are not supported in section names.
|
||||
- If you specify a section without narrowing to a test case first then all test cases will be executed
|
||||
- If you specify a section without narrowing to a test case first then all test cases will be executed
|
||||
(but only matching sections within them).
|
||||
|
||||
|
||||
@@ -400,7 +452,7 @@ start of the first section.</br>
|
||||
## Filenames as tags
|
||||
<pre>-#, --filenames-as-tags</pre>
|
||||
|
||||
When this option is used then every test is given an additional tag which is formed of the unqualified
|
||||
When this option is used then every test is given an additional tag which is formed of the unqualified
|
||||
filename it is found in, with any extension stripped, prefixed with the `#` character.
|
||||
|
||||
So, for example, tests within the file `~\Dev\MyProject\Ferrets.cpp` would be tagged `[#Ferrets]`.
|
||||
@@ -416,6 +468,44 @@ processing of output.
|
||||
`--use-colour yes` forces coloured output, `--use-colour no` disables coloured
|
||||
output. The default behaviour is `--use-colour auto`.
|
||||
|
||||
<a id="test-sharding"></a>
|
||||
## Test Sharding
|
||||
<pre>--shard-count <#number of shards>, --shard-index <#shard index to run></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/2257) in Catch2 X.Y.Z.
|
||||
|
||||
When `--shard-count <#number of shards>` is used, the tests to execute will be split evenly in to the given number of sets,
|
||||
identified by indicies starting at 0. The tests in the set given by `--shard-index <#shard index to run>` will be executed.
|
||||
The default shard count is `1`, and the default index to run is `0`. It is an error to specify a shard index greater than
|
||||
the number of shards.
|
||||
|
||||
This is useful when you want to split test execution across multiple processes, as is done with [Bazel test sharding](https://docs.bazel.build/versions/main/test-encyclopedia.html#test-sharding).
|
||||
|
||||
<a id="no-tests-override"></a>
|
||||
## Allow running the binary without tests
|
||||
<pre>--allow-running-no-tests</pre>
|
||||
|
||||
> Introduced in Catch2 X.Y.Z.
|
||||
|
||||
By default, Catch2 test binaries return non-0 exit code if no tests were
|
||||
run, e.g. if the binary was compiled with no tests, or the provided test
|
||||
spec matched no tests. This flag overrides that, so a test run with no
|
||||
tests still returns 0.
|
||||
|
||||
## Output verbosity
|
||||
```
|
||||
-v, --verbosity <quiet|normal|high>
|
||||
```
|
||||
|
||||
Changing verbosity might change how much details Catch2's reporters output.
|
||||
However, you should consider changing the verbosity level as a _suggestion_.
|
||||
Not all reporters support all verbosity levels, e.g. because the reporter's
|
||||
format cannot meaningfully change. In that case, the verbosity level is
|
||||
ignored.
|
||||
|
||||
Verbosity defaults to _normal_.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
@@ -1,22 +1,22 @@
|
||||
<a id="top"></a>
|
||||
# Commercial users of Catch
|
||||
# Commercial users of Catch2
|
||||
|
||||
As well as [Open Source](opensource-users.md#top) users Catch is widely used within proprietary code bases too.
|
||||
Many organisations like to keep this information internal, and that's fine,
|
||||
but if you're more open it would be great if we could list the names of as
|
||||
many organisations as possible that use Catch somewhere in their codebase.
|
||||
Enterprise environments often tend to be far more conservative in their tool adoption -
|
||||
and being aware that other companies are using Catch can ease the path in.
|
||||
Catch2 is also widely used in proprietary code bases. This page contains
|
||||
some of them that are willing to share this information.
|
||||
|
||||
So if you are aware of Catch usage in your organisation, and are fairly confident there is no issue with sharing this
|
||||
fact then please let us know - either directly, via a PR or
|
||||
[issue](https://github.com/philsquared/Catch/issues), or on the [forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum).
|
||||
If you want to add your organisation, please check that there is no issue
|
||||
with you sharing this fact.
|
||||
|
||||
- Bloomberg
|
||||
- [Bloomlife](https://bloomlife.com)
|
||||
- NASA
|
||||
- [Inscopix Inc.](https://www.inscopix.com/)
|
||||
- Locksley.CZ
|
||||
- [Makimo](https://makimo.pl/)
|
||||
- NASA
|
||||
- [UX3D](https://ux3d.io)
|
||||
- [King](https://king.com)
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
@@ -56,7 +56,7 @@ By default a console width of 80 is assumed but this can be controlled by defini
|
||||
CATCH_CONFIG_NOSTDOUT
|
||||
|
||||
To support platforms that do not provide `std::cout`, `std::cerr` and
|
||||
`std::clog`, Catch does not usem the directly, but rather calls
|
||||
`std::clog`, Catch does not use them directly, but rather calls
|
||||
`Catch::cout`, `Catch::cerr` and `Catch::clog`. You can replace their
|
||||
implementation by defining `CATCH_CONFIG_NOSTDOUT` and implementing
|
||||
them yourself, their signatures are:
|
||||
@@ -117,7 +117,7 @@ Catch's selection, by defining either `CATCH_CONFIG_CPP11_TO_STRING` or
|
||||
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_CONFIG_CPP17_STRING_VIEW` was [introduced](https://github.com/catchorg/Catch2/issues/1376) in Catch2 2.4.1.
|
||||
|
||||
Catch contains basic compiler/standard detection and attempts to use
|
||||
some C++17 features whenever appropriate. This automatic detection
|
||||
@@ -141,7 +141,7 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`.
|
||||
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
|
||||
> [`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 Catch2 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.
|
||||
|
||||
@@ -197,13 +197,13 @@ 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_VARIANT_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1380) in Catch2 2.4.1.
|
||||
|
||||
> `CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1510) in Catch 2.6.0.
|
||||
> `CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1510) in Catch2 2.6.0.
|
||||
|
||||
## Disabling exceptions
|
||||
|
||||
> Introduced in Catch 2.4.0.
|
||||
> Introduced in Catch2 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
|
||||
@@ -239,7 +239,7 @@ namespace Catch {
|
||||
|
||||
## Overriding Catch's debug break (`-b`)
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1846) in Catch 2.11.2.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1846) in Catch2 2.11.2.
|
||||
|
||||
You can override Catch2's break-into-debugger code by defining the
|
||||
`CATCH_BREAK_INTO_DEBUGGER()` macro. This can be used if e.g. Catch2 does
|
||||
|
@@ -26,7 +26,7 @@ Ongoing development happens in the `devel` branch for Catch2 v3, and in
|
||||
|
||||
Commits should be small and atomic. A commit is atomic when, after it is
|
||||
applied, the codebase, tests and all, still works as expected. Small
|
||||
commits are also prefered, as they make later operations with git history,
|
||||
commits are also preferred, as they make later operations with git history,
|
||||
whether it is bisecting, reverting, or something else, easier.
|
||||
|
||||
_When submitting a pull request please do not include changes to the
|
||||
@@ -78,25 +78,34 @@ the invocation of CMake configuration step.
|
||||
Bringing this all together, the steps below should configure, build,
|
||||
and run all tests in the `Debug` compilation.
|
||||
|
||||
1. Regenerate the amalgamated distribution
|
||||
<!-- snippet: catch2-build-and-test -->
|
||||
<a id='snippet-catch2-build-and-test'></a>
|
||||
```sh
|
||||
# 1. Regenerate the amalgamated distribution
|
||||
./tools/scripts/generateAmalgamatedFiles.py
|
||||
|
||||
# 2. Configure the full test build
|
||||
cmake -Bdebug-build -H. -DCMAKE_BUILD_TYPE=Debug -DCATCH_BUILD_EXAMPLES=ON -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_DEVELOPMENT_BUILD=ON
|
||||
|
||||
# 3. Run the actual build
|
||||
cmake --build debug-build
|
||||
|
||||
# 4. Run the tests using CTest
|
||||
cd debug-build
|
||||
ctest -j 4 --output-on-failure -C Debug
|
||||
```
|
||||
$ cd Catch2
|
||||
$ ./tools/scripts/generateAmalgamatedFiles.py
|
||||
```
|
||||
2. Configure the full test build
|
||||
```
|
||||
$ cmake -Bdebug-build -H. -DCMAKE_BUILD_TYPE=Debug -DCATCH_BUILD_EXAMPLES=ON -DCATCH_BUILD_EXTRA_TESTS=ON
|
||||
```
|
||||
3. Run the actual build
|
||||
```
|
||||
$ cmake --build debug-build
|
||||
```
|
||||
4. Run the tests using CTest
|
||||
```
|
||||
$ cd debug-build
|
||||
$ ctest -j 4 --output-on-failure -C Debug
|
||||
<sup><a href='/tools/scripts/buildAndTest.sh#L6-L19' title='File snippet `catch2-build-and-test` was extracted from'>snippet source</a> | <a href='#snippet-catch2-build-and-test' title='Navigate to start of snippet `catch2-build-and-test`'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
For convenience, the above commands are in the script `tools/scripts/buildAndTest.sh`, and can be run like this:
|
||||
|
||||
```bash
|
||||
cd Catch2
|
||||
./tools/scripts/buildAndTest.sh
|
||||
```
|
||||
|
||||
A Windows version of the script is available at `tools\scripts\buildAndTest.cmd`.
|
||||
|
||||
If you added new tests, you will likely see `ApprovalTests` failure.
|
||||
After you check that the output difference is expected, you should
|
||||
run `tools/scripts/approve.py` to confirm them, and include these changes
|
||||
@@ -140,9 +149,9 @@ 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
|
||||
* `> [Introduced](link-to-issue-or-PR) in Catch2 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`
|
||||
* `> X (Y and Z) was [introduced](link-to-issue-or-PR) in Catch2 X.Y.Z`
|
||||
- this placeholder is used when you need to tag a subpart of something,
|
||||
e.g. a list
|
||||
|
||||
@@ -183,6 +192,24 @@ If want to contribute code, this section contains some simple rules
|
||||
and tips on things like code formatting, code constructions to avoid,
|
||||
and so on.
|
||||
|
||||
### C++ standard version
|
||||
|
||||
Catch2 currently targets C++14 as the minimum supported C++ version.
|
||||
Features from higher language versions should be used only sparingly,
|
||||
when the benefits from using them outweight the maintenance overhead.
|
||||
|
||||
Example of good use of polyfilling features is our use of `conjunction`,
|
||||
where if available we use `std::conjunction` and otherwise provide our
|
||||
own implementation. The reason it is good is that the surface area for
|
||||
maintenance is quite small, and `std::conjunction` can directly use
|
||||
compiler built-ins, thus providing significant compilation benefits.
|
||||
|
||||
Example of bad use of polyfilling features would be to keep around two
|
||||
sets of metaprogramming in the stringification implementation, once
|
||||
using C++14 compliant TMP and once using C++17's `if constexpr`. While
|
||||
the C++17 would provide significant compilation speedups, the maintenance
|
||||
cost would be too high.
|
||||
|
||||
|
||||
### Formatting
|
||||
|
||||
@@ -203,7 +230,7 @@ are problematic and are not always caught by our CI infrastructure.
|
||||
#### Naked exceptions and exceptions-related function
|
||||
|
||||
If you are throwing an exception, it should be done via `CATCH_ERROR`
|
||||
or `CATCH_RUNTIME_ERROR` in `catch_enforce.h`. These macros will handle
|
||||
or `CATCH_RUNTIME_ERROR` in `internal/catch_enforce.hpp`. These macros will handle
|
||||
the differences between compilation with or without exceptions for you.
|
||||
However, some platforms (IAR) also have problems with exceptions-related
|
||||
functions, such as `std::current_exceptions`. We do not have IAR in our
|
||||
@@ -212,6 +239,18 @@ However, if you do, they should be kept behind a
|
||||
`CATCH_CONFIG_DISABLE_EXCEPTIONS` macro.
|
||||
|
||||
|
||||
#### Avoid `std::move` and `std::forward`
|
||||
|
||||
`std::move` and `std::forward` provide nice semantic name for a specific
|
||||
`static_cast`. However, being function templates they have surprisingly
|
||||
high cost during compilation, and can also have a negative performance
|
||||
impact for low-optimization builds.
|
||||
|
||||
You should be using `CATCH_MOVE` and `CATCH_FORWARD` macros from
|
||||
`internal/catch_move_and_forward.hpp` instead. They expand into the proper
|
||||
`static_cast`, and avoid the overhead of `std::move` and `std::forward`.
|
||||
|
||||
|
||||
#### Unqualified usage of functions from C's stdlib
|
||||
|
||||
If you are using a function from C's stdlib, please include the header
|
||||
@@ -220,6 +259,23 @@ there is no difference is wrong, QNX and VxWorks won't compile if you
|
||||
include the header as `<cfoo>` and call the function unqualified.
|
||||
|
||||
|
||||
#### User-Defined Literals (UDL) for Catch2' types
|
||||
|
||||
Due to messy standardese and ... not great ... implementation of
|
||||
`-Wreserved-identifier` in Clang, avoid declaring UDLs as
|
||||
```cpp
|
||||
Approx operator "" _a(long double);
|
||||
```
|
||||
and instead declare them as
|
||||
```cpp
|
||||
Approx operator ""_a(long double);
|
||||
```
|
||||
|
||||
Notice that the second version does not have a space between the `""` and
|
||||
the literal suffix.
|
||||
|
||||
|
||||
|
||||
### New source file template
|
||||
|
||||
If you are adding new source file, there is a template you should use.
|
||||
|
@@ -9,17 +9,16 @@ either of these is a breaking change, and thus will not happen until
|
||||
at least the next major release.
|
||||
|
||||
|
||||
### `ParseAndAddCatchTests.cmake`
|
||||
|
||||
The CMake/CTest integration using `ParseAndAddCatchTests.cmake` is deprecated,
|
||||
as it can be replaced by `Catch.cmake` that provides the function
|
||||
`catch_discover_tests` to get tests directly from a CMake target via the
|
||||
command line interface instead of parsing C++ code with regular expressions.
|
||||
|
||||
|
||||
## Planned changes
|
||||
|
||||
### `CHECKED_IF` and `CHECKED_ELSE`
|
||||
|
||||
To make the `CHECKED_IF` and `CHECKED_ELSE` macros more useful, they will
|
||||
be marked as "OK to fail" (`Catch::ResultDisposition::SuppressFail` flag
|
||||
will be added), which means that their failure will not fail the test,
|
||||
making the `else` actually useful.
|
||||
|
||||
|
||||
### Console Colour API
|
||||
|
||||
The API for Catch2's console colour will be changed to take an extra
|
||||
|
@@ -1,74 +1,43 @@
|
||||
<a id="top"></a>
|
||||
# Event Listeners
|
||||
|
||||
A `Listener` is a class you can register with Catch that will then be passed events,
|
||||
such as a test case starting or ending, as they happen during a test run.
|
||||
`Listeners` are actually types of `Reporters`, with a few small differences:
|
||||
|
||||
1. Once registered in code they are automatically used - you don't need to specify them on the command line
|
||||
2. They are called in addition to (just before) any reporters, and you can register multiple listeners.
|
||||
3. They derive from `Catch::TestEventListenerBase`, which has default stubs for all the events,
|
||||
so you are not forced to implement events you're not interested in.
|
||||
4. You register a listener with `CATCH_REGISTER_LISTENER`
|
||||
An event listener is a bit like a reporter, in that it responds to various
|
||||
reporter events in Catch2, but it is not expected to write any output.
|
||||
Instead, an event listener performs actions within the test process, such
|
||||
as performing global initialization (e.g. of a C library), or cleaning out
|
||||
in-memory logs if they are not needed (the test case passed).
|
||||
|
||||
Unlike reporters, each registered event listener is always active. Event
|
||||
listeners are always notified before reporter(s).
|
||||
|
||||
## Implementing a Listener
|
||||
Simply derive a class from `Catch::TestEventListenerBase` and implement the methods you are interested in, either in
|
||||
the main source file (i.e. the one that defines `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`), or in a
|
||||
file that defines `CATCH_CONFIG_EXTERNAL_INTERFACES`.
|
||||
To write your own event listener, you should derive from `Catch::TestEventListenerBase`,
|
||||
as it provides empty stubs for all reporter events, allowing you to
|
||||
only override events you care for. Afterwards you have to register it
|
||||
with Catch2 using `CATCH_REGISTER_LISTENER` macro, so that Catch2 knows
|
||||
about it and instantiates it before running tests.
|
||||
|
||||
Then register it using `CATCH_REGISTER_LISTENER`.
|
||||
Example event listener:
|
||||
```cpp
|
||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
|
||||
For example ([complete source code](../examples/210-Evt-EventListeners.cpp)):
|
||||
class testRunListener : public Catch::EventListenerBase {
|
||||
public:
|
||||
using Catch::EventListenerBase::EventListenerBase;
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
struct MyListener : Catch::TestEventListenerBase {
|
||||
|
||||
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
|
||||
|
||||
void testCaseStarting( Catch::TestCaseInfo const& testInfo ) override {
|
||||
// Perform some setup before a test case is run
|
||||
}
|
||||
|
||||
void testCaseEnded( Catch::TestCaseStats const& testCaseStats ) override {
|
||||
// Tear-down after a test case is run
|
||||
void testRunStarting(Catch::TestRunInfo const&) override {
|
||||
lib_foo_init();
|
||||
}
|
||||
};
|
||||
CATCH_REGISTER_LISTENER( MyListener )
|
||||
|
||||
CATCH_REGISTER_LISTENER(testRunListener)
|
||||
```
|
||||
|
||||
_Note that you should not use any assertion macros within a Listener!_
|
||||
|
||||
## Events that can be hooked
|
||||
[You can find the list of events that the listeners can react to on its
|
||||
own page](reporter-events.md#top).
|
||||
|
||||
The following are the methods that can be overridden in the Listener:
|
||||
|
||||
```c++
|
||||
// The whole test run, starting and ending
|
||||
virtual void testRunStarting( TestRunInfo const& testRunInfo );
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats );
|
||||
|
||||
// Test cases starting and ending
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo );
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats );
|
||||
|
||||
// Sections starting and ending
|
||||
virtual void sectionStarting( SectionInfo const& sectionInfo );
|
||||
virtual void sectionEnded( SectionStats const& sectionStats );
|
||||
|
||||
// Assertions before/ after
|
||||
virtual void assertionStarting( AssertionInfo const& assertionInfo );
|
||||
virtual bool assertionEnded( AssertionStats const& assertionStats );
|
||||
|
||||
// A test is being skipped (because it is "hidden")
|
||||
virtual void skipTest( TestCaseInfo const& testInfo );
|
||||
```
|
||||
|
||||
More information about the events (e.g. name of the test case) is contained in the structs passed as arguments -
|
||||
just look in the source code to see what fields are available.
|
||||
|
||||
---
|
||||
|
||||
|
27
docs/faq.md
Normal file
27
docs/faq.md
Normal file
@@ -0,0 +1,27 @@
|
||||
<a id="top"></a>
|
||||
# Frequently Asked Questions (FAQ)
|
||||
|
||||
## How do I run global setup/teardown only if tests will be run?
|
||||
|
||||
Write a custom [event listener](event-listeners.md#top) and place the
|
||||
global setup/teardown code into the `testRun*` events.
|
||||
|
||||
|
||||
## How do I clean up global state between running different tests?
|
||||
|
||||
Write a custom [event listener](event-listeners.md#top) and place the
|
||||
cleanup code into either `testCase*` or `testCasePartial*` events,
|
||||
depending on how often the cleanup needs to happen.
|
||||
|
||||
|
||||
## Why cannot I derive from the built-in reporters?
|
||||
|
||||
They are not made to be overriden, in that we do not attempt to maintain
|
||||
a consistent internal state if a member function is overriden, and by
|
||||
forbidding users from using them as a base class, we can refactor them
|
||||
as needed later.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -1,7 +1,7 @@
|
||||
<a id="top"></a>
|
||||
# Data Generators
|
||||
|
||||
> Introduced in Catch 2.6.0.
|
||||
> Introduced in Catch2 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.
|
||||
@@ -92,7 +92,7 @@ TEST_CASE("Complex mix of sections and generates") {
|
||||
}
|
||||
```
|
||||
|
||||
> The ability to place `GENERATE` between two `SECTION`s was [introduced](https://github.com/catchorg/Catch2/issues/1938) in Catch 2.13.0.
|
||||
> The ability to place `GENERATE` between two `SECTION`s was [introduced](https://github.com/catchorg/Catch2/issues/1938) in Catch2 2.13.0.
|
||||
|
||||
## Provided generators
|
||||
|
||||
@@ -114,12 +114,12 @@ a test case,
|
||||
* 4 specific purpose generators
|
||||
* `RandomIntegerGenerator<Integral>` -- generates random Integrals from range
|
||||
* `RandomFloatGenerator<Float>` -- generates random Floats from range
|
||||
* `RangeGenerator<T>` -- generates all values inside an arithmetic range
|
||||
* `RangeGenerator<T>(first, last)` -- generates all values inside a `[first, last)` arithmetic 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.
|
||||
> `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch2 2.7.0.
|
||||
|
||||
> `IteratorGenerator<T>` was introduced in Catch 2.10.0.
|
||||
> `IteratorGenerator<T>` was introduced in Catch2 2.10.0.
|
||||
|
||||
The generators also have associated helper functions that infer their
|
||||
type, making their usage much nicer. These are
|
||||
@@ -139,11 +139,11 @@ type, making their usage much nicer. These are
|
||||
* `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.
|
||||
> `chunk()`, `random()` and both `range()` functions were introduced in Catch2 2.7.0.
|
||||
|
||||
> `from_range` has been introduced in Catch 2.10.0
|
||||
> `from_range` has been introduced in Catch2 2.10.0
|
||||
|
||||
> `range()` for floating point numbers has been introduced in Catch 2.11.0
|
||||
> `range()` for floating point numbers has been introduced in Catch2 2.11.0
|
||||
|
||||
And can be used as shown in the example below to create a generator
|
||||
that returns 100 odd random number:
|
||||
@@ -176,7 +176,7 @@ 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.
|
||||
> `GENERATE_COPY` and `GENERATE_REF` were introduced in Catch2 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,
|
||||
|
@@ -94,39 +94,57 @@ to remove this limitation in the future.
|
||||
### Process isolation in a test
|
||||
Catch does not support running tests in isolated (forked) processes. While this might in the future, the fact that Windows does not support forking and only allows full-on process creation and the desire to keep code as similar as possible across platforms, mean that this is likely to take significant development time, that is not currently available.
|
||||
|
||||
### Running multiple tests in parallel
|
||||
Catch's test execution is strictly serial. If you find yourself with a test suite that takes too long to run and you want to make it parallel, there are 2 feasible solutions
|
||||
* You can split your tests into multiple binaries and then run these binaries in parallel.
|
||||
* You can have Catch list contained test cases and then run the same test binary multiple times in parallel, passing each instance list of test cases it should run.
|
||||
|
||||
Both of these solutions have their problems, but should let you wring parallelism out of your test suite.
|
||||
### Running multiple tests in parallel
|
||||
|
||||
Catch2 keeps test execution in one process strictly serial, and there
|
||||
are no plans to change this. If you find yourself with a test suite
|
||||
that takes too long to run and yo uwant to make it parallel, you have
|
||||
to run multiple processes side by side.
|
||||
|
||||
There are 2 basic ways to do that,
|
||||
* you can split your tests into multiple binaries, and run those binaries
|
||||
in parallel
|
||||
* you can run the same test binary multiple times, but run a different
|
||||
subset of the tests in each process
|
||||
|
||||
There are multiple ways to achieve the latter, the easiest way is to use
|
||||
[test sharding](command-line.md#test-sharding).
|
||||
|
||||
|
||||
## 3rd party bugs
|
||||
|
||||
This section outlines known bugs in 3rd party components (this means compilers, standard libraries, standard runtimes).
|
||||
|
||||
|
||||
### Visual Studio 2017 -- raw string literal in assert fails to compile
|
||||
There is a known bug in Visual Studio 2017 (VC 15), that causes compilation error when preprocessor attempts to stringize a raw string literal (`#` preprocessor is applied to it). This snippet is sufficient to trigger the compilation error:
|
||||
|
||||
There is a known bug in Visual Studio 2017 (VC 15), that causes compilation
|
||||
error when preprocessor attempts to stringize a raw string literal
|
||||
(`#` preprocessor directive is applied to it). This snippet is sufficient
|
||||
to trigger the compilation error:
|
||||
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("test") {
|
||||
CHECK(std::string(R"("\)") == "\"\\");
|
||||
}
|
||||
```
|
||||
|
||||
Catch provides a workaround, it is possible to disable stringification of original expressions by defining `CATCH_CONFIG_DISABLE_STRINGIFICATION`:
|
||||
Catch2 provides a workaround, by letting the user disable stringification
|
||||
of the original expression by defining `CATCH_CONFIG_DISABLE_STRINGIFICATION`,
|
||||
like so:
|
||||
```cpp
|
||||
#define CATCH_CONFIG_FAST_COMPILE
|
||||
#define CATCH_CONFIG_DISABLE_STRINGIFICATION
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("test") {
|
||||
CHECK(std::string(R"("\)") == "\"\\");
|
||||
}
|
||||
```
|
||||
|
||||
_Do note that this changes the output somewhat_
|
||||
_Do note that this changes the output:_
|
||||
```
|
||||
catchwork\test1.cpp(6):
|
||||
PASSED:
|
||||
@@ -135,26 +153,11 @@ with expansion:
|
||||
""\" == ""\"
|
||||
```
|
||||
|
||||
### Visual Studio 2015 -- Alignment compilation error (C2718)
|
||||
|
||||
VS 2015 has a known bug, where `declval<T>` can cause compilation error
|
||||
if `T` has alignment requirements that it cannot meet.
|
||||
|
||||
|
||||
A workaround is to explicitly specialize `Catch::is_range` for given
|
||||
type (this avoids code path that uses `declval<T>` in a SFINAE context).
|
||||
|
||||
|
||||
### Visual Studio 2015 -- Wrong line number reported in debug mode
|
||||
VS 2015 has a known bug where `__LINE__` macro can be improperly expanded under certain circumstances, while compiling multi-file project in Debug mode.
|
||||
|
||||
A workaround is to compile the binary in Release mode.
|
||||
|
||||
### Clang/G++ -- skipping leaf sections after an exception
|
||||
Some versions of `libc++` and `libstdc++` (or their runtimes) have a bug with `std::uncaught_exception()` getting stuck returning `true` after rethrow, even if there are no active exceptions. One such case is this snippet, which skipped the sections "a" and "b", when compiled against `libcxxrt` from master
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("a") {
|
||||
CHECK_THROWS(throw 3);
|
||||
@@ -170,11 +173,6 @@ TEST_CASE("b") {
|
||||
|
||||
If you are seeing a problem like this, i.e. a weird test paths that trigger only under Clang with `libc++`, or only under very specific version of `libstdc++`, it is very likely you are seeing this. The only known workaround is to use a fixed version of your standard library.
|
||||
|
||||
### Clang/G++ -- `Matches` string matcher always returns false
|
||||
This is a bug in `libstdc++-4.8`, where all matching methods from `<regex>` return false. Since `Matches` uses `<regex>` internally, if the underlying implementation does not work, it doesn't work either.
|
||||
|
||||
Workaround: Use newer version of `libstdc++`.
|
||||
|
||||
|
||||
### libstdc++, `_GLIBCXX_DEBUG` macro and random ordering of tests
|
||||
|
||||
|
@@ -30,7 +30,7 @@ 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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
|
||||
|
||||
`UNSCOPED_INFO` is similar to `INFO` with two key differences:
|
||||
|
||||
@@ -106,7 +106,7 @@ 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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 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.
|
||||
|
||||
|
@@ -35,10 +35,10 @@ operators, that is `&&`, `||`, and `!`, like so:
|
||||
|
||||
```cpp
|
||||
using Catch::Matchers::EndsWith;
|
||||
using Catch::Matchers::Contains;
|
||||
using Catch::Matchers::ContainsSubstring;
|
||||
|
||||
REQUIRE_THAT( getSomeString(),
|
||||
EndsWith("as a service") && Contains("web scale"));
|
||||
EndsWith("as a service") && ContainsSubstring("web scale"));
|
||||
```
|
||||
|
||||
The example above asserts that the string returned from `getSomeString`
|
||||
@@ -58,13 +58,13 @@ to a use-after-free (UAF):
|
||||
|
||||
```cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers_string.h>
|
||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
||||
|
||||
TEST_CASE("Bugs, bugs, bugs", "[Bug]"){
|
||||
std::string str = "Bugs as a service";
|
||||
|
||||
auto match_expression = Catch::Matchers::EndsWith( "as a service" ) ||
|
||||
(Catch::Matchers::StartsWith( "Big data" ) && !Catch::Matchers::Contains( "web scale" ) );
|
||||
(Catch::Matchers::StartsWith( "Big data" ) && !Catch::Matchers::ContainsSubstring( "web scale" ) );
|
||||
REQUIRE_THAT(str, match_expression);
|
||||
}
|
||||
```
|
||||
@@ -88,7 +88,7 @@ Out of the box, Catch2 provides the following matchers:
|
||||
Catch2 provides 5 different matchers that work with `std::string`,
|
||||
* `StartsWith(std::string str, CaseSensitive)`,
|
||||
* `EndsWith(std::string str, CaseSensitive)`,
|
||||
* `Contains(std::string str, CaseSensitive)`,
|
||||
* `ContainsSubstring(std::string str, CaseSensitive)`,
|
||||
* `Equals(std::string str, CaseSensitive)`, and
|
||||
* `Matches(std::string str, CaseSensitive)`.
|
||||
|
||||
@@ -99,9 +99,9 @@ somewhere inside it.
|
||||
The `Equals` matcher matches a string if (and only if) the argument
|
||||
string is equal to `str`.
|
||||
|
||||
Finally, the `Matches` matcher performs an ECMASCript regex match using
|
||||
Finally, the `Matches` matcher performs an ECMAScript regex match using
|
||||
`str` against the argument string. It is important to know that
|
||||
the match is performed agains the string as a whole, meaning that
|
||||
the match is performed against the string as a whole, meaning that
|
||||
the regex `"abc"` will not match input string `"abcd"`. To match
|
||||
`"abcd"`, you need to use e.g. `"abc.*"` as your regex.
|
||||
|
||||
@@ -125,7 +125,7 @@ These are
|
||||
* `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.
|
||||
> Approx matcher was [introduced](https://github.com/catchorg/Catch2/issues/1499) in Catch2 2.7.2.
|
||||
|
||||
An example usage:
|
||||
```cpp
|
||||
@@ -145,10 +145,10 @@ Catch2 provides 3 matchers that target floating point numbers. These
|
||||
are:
|
||||
|
||||
* `WithinAbs(double target, double margin)`,
|
||||
* `WithinUlps(FloatingPoint target, uint64_t maxUlpDiff)`, and
|
||||
* `WithinULP(FloatingPoint target, uint64_t maxUlpDiff)`, and
|
||||
* `WithinRel(FloatingPoint target, FloatingPoint eps)`.
|
||||
|
||||
> `WithinRel` matcher was introduced in Catch 2.10.0
|
||||
> `WithinRel` matcher was introduced in Catch2 2.10.0
|
||||
|
||||
|
||||
`WithinAbs` creates a matcher that accepts floating point numbers whose
|
||||
@@ -161,6 +161,11 @@ away from the `target` value. The short version of what this means
|
||||
is that there is no more than `maxUlpDiff - 1` representeable floating
|
||||
point numbers between the argument for matching and the `target` value.
|
||||
|
||||
**Important**: The WithinULP matcher requires the platform to use the
|
||||
[IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) representation for
|
||||
floating point numbers.
|
||||
|
||||
|
||||
`WithinRel` creates a matcher that accepts floating point numbers that
|
||||
are _approximately equal_ with the `target` with tolerance of `eps.`
|
||||
Specifically, it matches if
|
||||
@@ -243,7 +248,7 @@ Note that `DerivedException` in the example above has to derive from
|
||||
|
||||
### Generic range Matchers
|
||||
|
||||
> Generic range matchers were introduced in Catch X.Y.Z
|
||||
> Generic range matchers were introduced in Catch2 X.Y.Z
|
||||
|
||||
Catch2 also provides some matchers that use the new style matchers
|
||||
definitions to handle generic range-like types. These are:
|
||||
@@ -294,7 +299,7 @@ within certain range. We will call it `IsBetweenMatcher<T>`:
|
||||
|
||||
```c++
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers.h>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
// ...
|
||||
|
||||
|
||||
@@ -345,7 +350,7 @@ style matchers arbitrarily.
|
||||
|
||||
## Writing custom matchers (new style)
|
||||
|
||||
> New style matchers were introduced in Catch X.Y.Z
|
||||
> New style matchers were introduced in Catch2 X.Y.Z
|
||||
|
||||
To create a new-style matcher, you have to create your own type that
|
||||
derives from `Catch::Matchers::MatcherGenericBase`. Your type has to
|
||||
|
84
docs/migrate-v2-to-v3.md
Normal file
84
docs/migrate-v2-to-v3.md
Normal file
@@ -0,0 +1,84 @@
|
||||
<a id="top"></a>
|
||||
# Migrating from v2 to v3
|
||||
|
||||
v3 is the next major version of Catch2 and brings three significant changes:
|
||||
* Catch2 is now split into multiple headers
|
||||
* Catch2 is now compiled as a static library
|
||||
* C++14 is the minimum required C++ version
|
||||
|
||||
There are many reasons why we decided to go from the old single-header
|
||||
distribution model to a more standard library distribution model. The
|
||||
big one is compile-time performance, but moving over to a split header
|
||||
distribution model also improves the future maintainability and
|
||||
extendability of the codebase. For example v3 adds a new kind of matchers
|
||||
without impacting the compilation times of users that do not use matchers
|
||||
in their tests. The new model is also more friendly towards package
|
||||
managers, such as vcpkg and Conan.
|
||||
|
||||
The result of this move is a significant improvement in compilation
|
||||
times, e.g. the inclusion overhead of Catch2 in the common case has been
|
||||
reduced by roughly 80%. The improved ease of maintenance also led to
|
||||
various runtime performance improvements and the introduction of new features.
|
||||
For details, look at [the release notes of 3.0.1](release-notes.md#301).
|
||||
|
||||
_Note that we still provide one header + one TU distribution but do
|
||||
not consider it the primarily supported option. You should also expect
|
||||
that the compilation times will be worse if you use this option._
|
||||
|
||||
|
||||
## How to migrate projects from v2 to v3
|
||||
|
||||
To migrate to v3, there are two basic approaches to do so.
|
||||
|
||||
1. Use `catch_amalgamated.hpp` and `catch_amalgamated.cpp`.
|
||||
2. Build Catch2 as a proper (static) library, and move to piecewise headers
|
||||
|
||||
Doing 1 means downloading the [amalgamated header](/extras/catch_amalgamated.hpp)
|
||||
and the [amalgamated sources](/extras/catch_amalgamated.cpp) from `extras`,
|
||||
dropping them into your test project, and rewriting your includes from
|
||||
`<catch2/catch.hpp>` to `"catch_amalgamated.hpp"` (or something similar,
|
||||
based on how you set up your paths).
|
||||
|
||||
The disadvantage of using this approach are increased compilation times,
|
||||
at least compared to the second approach, but it does let you avoid
|
||||
dealing with consuming libraries in your build system of choice.
|
||||
|
||||
|
||||
However, we recommend doing 2, and taking extra time to migrate to v3
|
||||
properly. This lets you reap the benefits of significantly improved
|
||||
compilation times in the v3 version. The basic steps to do so are:
|
||||
|
||||
1. Change your CMakeLists.txt to link against `Catch2WithMain` target if
|
||||
you use Catch2's default main. (If you do not, keep linking against
|
||||
the `Catch2` target.)
|
||||
2. Delete TU with `CATCH_CONFIG_RUNNER` or `CATCH_CONFIG_MAIN` defined,
|
||||
as it is no longer needed.
|
||||
3. Change `#include <catch2/catch.hpp>` to `#include <catch2/catch_all.hpp>`
|
||||
4. Check that everything compiles. You might have to modify namespaces,
|
||||
or perform some other changes (see the
|
||||
[Things that can break during porting](#things-that-can-break-during-porting)
|
||||
section for the most common things).
|
||||
5. Start migrating your test TUs from including `<catch2/catch_all.hpp>`
|
||||
to piecemeal includes. You will likely want to start by including
|
||||
`<catch2/catch_test_macros.hpp>`, and then go from there. (see
|
||||
[other notes](#other-notes) for further ideas)
|
||||
|
||||
## Other notes
|
||||
* The main test include is now `<catch2/catch_test_macros.hpp>`
|
||||
* Big "subparts" like Matchers, or Generators, have their own folder, and
|
||||
also their own "big header", so if you just want to include all matchers,
|
||||
you can include `<catch2/matchers/catch_matchers_all.hpp>`,
|
||||
or `<catch2/generators/catch_generators_all.hpp>`
|
||||
|
||||
|
||||
## Things that can break during porting
|
||||
* The namespace on Matchers were cleaned up, they are no longer first declared
|
||||
deep within an internal namespace and then brought up. All Matchers now live
|
||||
in `Catch::Matchers`.
|
||||
* The reporter interfaces changed in a breaking manner. If you wrote custom
|
||||
reporter or listener, you might need to modify them a bit.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -1,22 +1,25 @@
|
||||
<a id="top"></a>
|
||||
# Open Source projects using Catch
|
||||
# Open Source projects using Catch2
|
||||
|
||||
Catch is great for open source. With its [liberal license](../LICENSE.txt) and single-header, dependency-free, distribution
|
||||
it's easy to just drop the header into your project and start writing tests - what's not to like?
|
||||
Catch2 is great for open source. It is licensed under the [Boost Software
|
||||
License (BSL)](../LICENSE.txt), has no further dependencies and supports
|
||||
two file distribution.
|
||||
|
||||
As a result Catch is now being used in many Open Source projects, including some quite well known ones.
|
||||
This page is an attempt to track those projects. Obviously it can never be complete.
|
||||
This effort largely relies on the maintainers of the projects themselves updating this page and submitting a PR
|
||||
(or, if you prefer contact one of the maintainers of Catch directly, use the
|
||||
[forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)), or raise an [issue](https://github.com/philsquared/Catch/issues) to let us know).
|
||||
Of course users of those projects might want to update this page too. That's fine - as long you're confident the project maintainers won't mind.
|
||||
If you're an Open Source project maintainer and see your project listed here but would rather it wasn't -
|
||||
just let us know via any of the previously mentioned means - although I'm sure there won't be many who feel that way.
|
||||
As a result, Catch2 is used for testing in many different Open Source
|
||||
projects. This page lists at least some of them, even though it will
|
||||
obviously never be complete (and does not have the ambition to be
|
||||
complete). Note that the list below is intended to be in alphabetical
|
||||
order, to avoid implications of relative importance of the projects.
|
||||
|
||||
_Please only add projects here if you are their maintainer, or have the
|
||||
maintainer's explicit consent._
|
||||
|
||||
Listing a project here does not imply endorsement and the plan is to keep these ordered alphabetically to avoid an implication of relative importance.
|
||||
|
||||
## Libraries & Frameworks
|
||||
|
||||
### [alpaka](https://github.com/alpaka-group/alpaka)
|
||||
A header-only C++14 abstraction library for accelerator development.
|
||||
|
||||
### [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp)
|
||||
C++11 implementation of Approval Tests, for quick, convenient testing of legacy code.
|
||||
|
||||
@@ -53,9 +56,15 @@ Template Library of Tree Data Structures.
|
||||
### [Fuxedo](https://github.com/fuxedo/fuxedo)
|
||||
Open source Oracle Tuxedo-like XATMI middleware for C and C++.
|
||||
|
||||
### [HIP CPU Runtime](https://github.com/ROCm-Developer-Tools/HIP-CPU)
|
||||
A header-only library that allows CPUs to execute unmodified HIP code. It is generic and does not assume a particular CPU vendor or architecture.
|
||||
|
||||
### [Inja](https://github.com/pantor/inja)
|
||||
A header-only template engine for modern C++.
|
||||
|
||||
### [LLAMA](https://github.com/alpaka-group/llama)
|
||||
A C++17 template header-only library for the abstraction of memory access patterns.
|
||||
|
||||
### [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.
|
||||
|
||||
@@ -94,9 +103,15 @@ A thread-safe header-only mocking framework for C++14.
|
||||
|
||||
## Applications & Tools
|
||||
|
||||
### [App Mesh](https://github.com/laoshanxi/app-mesh)
|
||||
A high available cloud native micro-service application management platform implemented by modern C++.
|
||||
|
||||
### [ArangoDB](https://github.com/arangodb/arangodb)
|
||||
ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values.
|
||||
|
||||
### [d-SEAMS](https://github.com/d-SEAMS/seams-core)
|
||||
Open source molecular dynamics simulation structure analysis suite of tools in modern C++.
|
||||
|
||||
### [Giada - Your Hardcore Loop Machine](https://github.com/monocasual/giada)
|
||||
Minimal, open-source and cross-platform audio tool for live music production.
|
||||
|
||||
|
@@ -15,6 +15,8 @@ stringification machinery to the _expr_ and records the result. As with
|
||||
evaluates to `true`. `CHECKED_ELSE( expr )` work similarly, but the block
|
||||
is entered only if the _expr_ evaluated to `false`.
|
||||
|
||||
> `CHECKED_X` macros were changed to not count as failure in Catch2 X.Y.Z.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
int a = ...;
|
||||
@@ -57,9 +59,9 @@ TEST_CASE( "SUCCEED showcase" ) {
|
||||
}
|
||||
```
|
||||
|
||||
* `STATIC_REQUIRE`
|
||||
* `STATIC_REQUIRE` and `STATIC_CHECK`
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1362) in Catch 2.4.2.
|
||||
> `STATIC_REQUIRE` was [introduced](https://github.com/catchorg/Catch2/issues/1362) in Catch2 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
|
||||
@@ -75,6 +77,20 @@ TEST_CASE("STATIC_REQUIRE showcase", "[traits]") {
|
||||
}
|
||||
```
|
||||
|
||||
> `STATIC_CHECK` was [introduced](https://github.com/catchorg/Catch2/pull/2318) in Catch2 X.Y.Z.
|
||||
|
||||
`STATIC_CHECK( expr )` is equivalent to `STATIC_REQUIRE( expr )`, with the
|
||||
difference that when `CATCH_CONFIG_RUNTIME_STATIC_REQUIRE` is defined, it
|
||||
becomes equivalent to `CHECK` instead of `REQUIRE`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
TEST_CASE("STATIC_CHECK showcase", "[traits]") {
|
||||
STATIC_CHECK( std::is_void<void>::value );
|
||||
STATIC_CHECK_FALSE( std::is_void<int>::value );
|
||||
}
|
||||
```
|
||||
|
||||
## Test case related macros
|
||||
|
||||
* `METHOD_AS_TEST_CASE`
|
||||
@@ -117,24 +133,9 @@ is initiated. This means that it either needs to be done in a global
|
||||
constructor, or before Catch2's session is created in user's own main._
|
||||
|
||||
|
||||
* `ANON_TEST_CASE`
|
||||
|
||||
`ANON_TEST_CASE` is a `TEST_CASE` replacement that will autogenerate
|
||||
unique name. The advantage of this is that you do not have to think
|
||||
of a name for the test case,`the disadvantage is that the name doesn't
|
||||
necessarily remain stable across different links, and thus it might be
|
||||
hard to run directly.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
ANON_TEST_CASE() {
|
||||
SUCCEED("Hello from anonymous test case");
|
||||
}
|
||||
```
|
||||
|
||||
* `DYNAMIC_SECTION`
|
||||
|
||||
> Introduced in Catch 2.3.0.
|
||||
> Introduced in Catch2 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.
|
||||
|
@@ -2,63 +2,69 @@
|
||||
# Supplying main() yourself
|
||||
|
||||
**Contents**<br>
|
||||
[Let Catch take full control of args and config](#let-catch-take-full-control-of-args-and-config)<br>
|
||||
[Amending the config](#amending-the-config)<br>
|
||||
[Let Catch2 take full control of args and config](#let-catch2-take-full-control-of-args-and-config)<br>
|
||||
[Amending the Catch2 config](#amending-the-catch2-config)<br>
|
||||
[Adding your own command line options](#adding-your-own-command-line-options)<br>
|
||||
[Version detection](#version-detection)<br>
|
||||
|
||||
The easiest way to use Catch is to let it supply ```main()``` for you and handle configuring itself from the command line.
|
||||
The easiest way to use Catch2 is to use its own `main` function, and let
|
||||
it handle the command line arguments. This is done by linking against
|
||||
Catch2Main library, e.g. through the [CMake target](cmake-integration.md#cmake-targets),
|
||||
or pkg-config files.
|
||||
|
||||
This is achieved by writing ```#define CATCH_CONFIG_MAIN``` before the ```#include "catch.hpp"``` in *exactly one* source file.
|
||||
If you want to provide your own `main`, then you should link against
|
||||
the static library (target) only, without the main part. You will then
|
||||
have to write your own `main` and call into Catch2 test runner manually.
|
||||
|
||||
Sometimes, though, you need to write your own version of main(). You can do this by writing ```#define CATCH_CONFIG_RUNNER``` instead. Now you are free to write ```main()``` as normal and call into Catch yourself manually.
|
||||
Below are some basic recipes on what you can do supplying your own main.
|
||||
|
||||
You now have a lot of flexibility - but here are three recipes to get your started:
|
||||
|
||||
## Let Catch take full control of args and config
|
||||
## Let Catch2 take full control of args and config
|
||||
|
||||
If you just need to have code that executes before and/ or after Catch this is the simplest option.
|
||||
This is useful if you just need to have code that executes before/after
|
||||
Catch2 runs tests.
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
```cpp
|
||||
#include <catch2/catch_session.hpp>
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
// global setup...
|
||||
// your setup ...
|
||||
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
|
||||
// global clean-up...
|
||||
// your clean-up...
|
||||
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
## Amending the config
|
||||
_Note that if you only want to run some set up before tests are run, it
|
||||
might be simpler to use [event listeners](event-listeners.md#top) instead._
|
||||
|
||||
If you still want Catch to process the command line, but you want to programmatically tweak the config, you can do so in one of two ways:
|
||||
|
||||
## Amending the Catch2 config
|
||||
|
||||
If you want Catch2 to process command line arguments, but also want to
|
||||
programmatically change the resulting configuration of Catch2 run,
|
||||
you can do it in two ways:
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
int main( int argc, char* argv[] ) {
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
|
||||
|
||||
// writing to session.configData() here sets defaults
|
||||
// this is the preferred way to set them
|
||||
|
||||
|
||||
int returnCode = session.applyCommandLine( argc, argv );
|
||||
if( returnCode != 0 ) // Indicates a command line error
|
||||
return returnCode;
|
||||
|
||||
// writing to session.configData() or session.Config() here
|
||||
|
||||
// writing to session.configData() or session.Config() here
|
||||
// overrides command line args
|
||||
// only do this if you know you need to
|
||||
|
||||
int numFailed = session.run();
|
||||
|
||||
|
||||
// numFailed is clamped to 255 as some unices only use the lower 8 bits.
|
||||
// This clamping has already been applied, so just return it here
|
||||
// You can also do any post run clean-up here
|
||||
@@ -66,38 +72,32 @@ int main( int argc, char* argv[] )
|
||||
}
|
||||
```
|
||||
|
||||
Take a look at the definitions of Config and ConfigData to see what you can do with them.
|
||||
If you want full control of the configuration, don't call `applyCommandLine`.
|
||||
|
||||
To take full control of the config simply omit the call to ```applyCommandLine()```.
|
||||
|
||||
## Adding your own command line options
|
||||
|
||||
Catch embeds a powerful command line parser called [Clara](https://github.com/philsquared/Clara).
|
||||
As of Catch2 (and Clara 1.0) Clara allows you to write _composable_ option and argument parsers,
|
||||
so extending Catch's own command line options is now easy.
|
||||
You can add new command line options to Catch2, by composing the premade
|
||||
CLI parser (called Clara), and add your own options.
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
```cpp
|
||||
int main( int argc, char* argv[] ) {
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
|
||||
|
||||
int height = 0; // Some user variable you want to be able to set
|
||||
|
||||
// Build a new parser on top of Catch's
|
||||
using namespace Catch::clara;
|
||||
auto cli
|
||||
= session.cli() // Get Catch's composite command line parser
|
||||
|
||||
// Build a new parser on top of Catch2's
|
||||
using namespace Catch::Clara;
|
||||
auto cli
|
||||
= session.cli() // Get Catch2's command line parser
|
||||
| Opt( height, "height" ) // bind variable to a new option, with a hint string
|
||||
["-g"]["--height"] // the option names it will respond to
|
||||
("how high?"); // description string for the help output
|
||||
|
||||
// Now pass the new composite back to Catch so it uses that
|
||||
session.cli( cli );
|
||||
|
||||
// Let Catch (using Clara) parse the command line
|
||||
|
||||
// Now pass the new composite back to Catch2 so it uses that
|
||||
session.cli( cli );
|
||||
|
||||
// Let Catch2 (using Clara) parse the command line
|
||||
int returnCode = session.applyCommandLine( argc, argv );
|
||||
if( returnCode != 0 ) // Indicates a command line error
|
||||
return returnCode;
|
||||
@@ -110,12 +110,13 @@ int main( int argc, char* argv[] )
|
||||
}
|
||||
```
|
||||
|
||||
See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details.
|
||||
See the [Clara documentation](https://github.com/catchorg/Clara/blob/master/README.md)
|
||||
for more details on how to use the Clara parser.
|
||||
|
||||
|
||||
## Version detection
|
||||
|
||||
Catch provides a triplet of macros providing the header's version,
|
||||
Catch2 provides a triplet of macros providing the header's version,
|
||||
|
||||
* `CATCH_VERSION_MAJOR`
|
||||
* `CATCH_VERSION_MINOR`
|
||||
|
@@ -2,7 +2,12 @@
|
||||
|
||||
# Release notes
|
||||
**Contents**<br>
|
||||
[3.0.1](#301)<br>
|
||||
[3.0.1 (in progress)](#301-in-progress)<br>
|
||||
[2.13.7](#2137)<br>
|
||||
[2.13.6](#2136)<br>
|
||||
[2.13.5](#2135)<br>
|
||||
[2.13.4](#2134)<br>
|
||||
[2.13.3](#2133)<br>
|
||||
[2.13.2](#2132)<br>
|
||||
[2.13.1](#2131)<br>
|
||||
[2.13.0](#2130)<br>
|
||||
@@ -46,7 +51,6 @@
|
||||
|
||||
## 3.0.1 (in progress)
|
||||
|
||||
|
||||
**Catch2 now uses statically compiled library as its distribution model.
|
||||
This also means that to get all of Catch2's functionality in a test file,
|
||||
you have to include multiple headers.**
|
||||
@@ -73,12 +77,13 @@ new design.
|
||||
* Will Catch2 again distribute single-header version in the future?
|
||||
* No. But we do provide sqlite-style amalgamated distribution option. This means that you can download just 1 .cpp file and 1 header and place them next to your own sources. However, doing this has downsides similar to using the `catch_all.hpp` header.
|
||||
* Why the big breaking change caused by replacing `catch.hpp` with `catch_all.hpp`?
|
||||
* The convenience header `catch_all.hpp` exists for two reasons. One of them is to provide a way for quick migration from Catch2, the second one is to provide a simple way to test things with Catch2. Using it for migration has one drawback in that it is **big**. This means that including it _will_ cause significant compile time drag, and so using it to migrate should be a concious decision by the user, not something they can just stumble into unknowingly.
|
||||
* The convenience header `catch_all.hpp` exists for two reasons. One of them is to provide a way for quick migration from Catch2, the second one is to provide a simple way to test things with Catch2. Using it for migration has one drawback in that it is **big**. This means that including it _will_ cause significant compile time drag, and so using it to migrate should be a conscious decision by the user, not something they can just stumble into unknowingly.
|
||||
|
||||
|
||||
### (Potentially) Breaking changes
|
||||
* **Catch2 now uses statically compiled library as its distribution model**
|
||||
* **Including `catch.hpp` no longer works**
|
||||
* **Catch2 now uses C++14 as the minimum support language version**
|
||||
* `ANON_TEST_CASE` has been removed, use `TEST_CASE` with no arguments instead (#1220)
|
||||
* `--list*` commands no longer have non-zero return code (#1410)
|
||||
* `--list-test-names-only` has been removed (#1190)
|
||||
@@ -120,7 +125,18 @@ new design.
|
||||
* Event Listener interface has changed
|
||||
* `TestEventListenerBase` was renamed to `EventListenerBase`
|
||||
* `EventListenerBase` now directly derives from `IStreamingReporter`, instead of deriving from `StreamingReporterBase`
|
||||
|
||||
* `GENERATE` decays its arguments (#2012, #2040)
|
||||
* This means that `str` in `auto str = GENERATE("aa", "bb", "cc");` is inferred to `char const*` rather than `const char[2]`.
|
||||
* `--list-*` flags write their output to file specified by the `-o` flag
|
||||
* Many changes to reporter interfaces
|
||||
* With the exception of the XmlReporter, the outputs of first party reporters should remain the same
|
||||
* New pair of events were added
|
||||
* One obsolete event was removed
|
||||
* Catch2 generates a random seed if one hasn't been specified by the user
|
||||
* The short flag for `--list-tests`, `-l`, has been removed.
|
||||
* This is not a commonly used flag and does not need to use up valuable single-letter space.
|
||||
* The short flag for `--list-tags`, `-t`, has been removed.
|
||||
* This is not a commonly used flag and does not need to use up valuable single-letter space.
|
||||
|
||||
|
||||
### Improvements
|
||||
@@ -128,16 +144,62 @@ new design.
|
||||
* This includes having templated `match` member function
|
||||
* See the [rewritten Matchers documentation](matchers.md#top) for details
|
||||
* Catch2 currently provides _some_ generic matchers, but there should be more before final release of v3
|
||||
* So far, `IsEmpty`, `SizeIs`, and `Contains` are provided.
|
||||
* At least `ElementsAre` and `UnorderedElementsAre` are planned.
|
||||
* Some runtime performance improvements
|
||||
* `IsEmpty`, `SizeIs` which check that the range has specific properties
|
||||
* `Contains`, which checks whether a range contains a specific element
|
||||
* `AllMatch`, `AnyMatch`, `NoneMatch` range matchers, which apply matchers over a range of elements
|
||||
* Significant compilation time improvements
|
||||
* including `catch_test_macros.hpp` is 80% cheaper than including `catch.hpp`
|
||||
* Some runtime performance optimizations
|
||||
* In all tested cases the v3 branch was faster, so the table below shows the speedup of v3 to v2 at the same task
|
||||
<a id="v3-runtime-optimization-table"></a>
|
||||
|
||||
| task | debug build | release build |
|
||||
|:------------------------------------------- | ------------:| -------------:|
|
||||
| Run 1M `REQUIRE(true)` | 1.10 ± 0.01 | 1.02 ± 0.06 |
|
||||
| Run 100 tests, 3^3 sections, 1 REQUIRE each | 1.27 ± 0.01 | 1.04 ± 0.01 |
|
||||
| Run 3k tests, no names, no tags | 1.29 ± 0.01 | 1.05 ± 0.01 |
|
||||
| Run 3k tests, names, tags | 1.49 ± 0.01 | 1.22 ± 0.01 |
|
||||
| Run 1 out of 3k tests no names, no tags | 1.68 ± 0.02 | 1.19 ± 0.22 |
|
||||
| Run 1 out of 3k tests, names, tags | 1.79 ± 0.02 | 2.06 ± 0.23 |
|
||||
|
||||
|
||||
* POSIX platforms use `gmtime_r`, rather than `gmtime` when constructing a date string (#2008, #2165)
|
||||
* `--list-*` flags write their output to file specified by the `-o` flag (#2061, #2163)
|
||||
* `Approx::operator()` is now properly `const`
|
||||
* Catch2's internal helper variables no longer use reserved identifiers (#578)
|
||||
* `--rng-seed` now accepts string `"random-device"` to generate random seed using `std::random_device`
|
||||
* Catch2 now supports test sharding (#2257)
|
||||
* You can ask for the tests to be split into N groups and only run one of them.
|
||||
* This greatly simplifies parallelization of tests in a binary through external runner.
|
||||
* The embedded CLI parser now supports repeatedly callable lambdas
|
||||
* A lambda-based option parser can opt into being repeatedly specifiable.
|
||||
* Added `STATIC_CHECK` macro, similar to `STATIC_REQUIRE` (#2318)
|
||||
* When deferred tu runtime, it behaves like `CHECK`, and not like `REQUIRE`.
|
||||
* You can have multiple tests with the same name, as long as other parts of the test identity differ (#1915, #1999, #2175)
|
||||
* Test identity includes test's name, test's tags and and test's class name if applicable.
|
||||
* Added new warning, `UnmatchedTestSpec`, to error on test specs with no matching tests
|
||||
* The `-w`, `--warn` warning flags can now be provided multiple times to enable multiple warnings
|
||||
* The case-insensitive handling of tags is now more reliable and takes up less memory
|
||||
* Test case and assertion counting can no longer reasonably overflow on 32 bit systems
|
||||
* The count is now kept in `uint64_t` on all platforms, instead of using `size_t` type.
|
||||
* The `-o`, `--out` output destination specifiers recognize `-` as stdout
|
||||
* You have to provide it as `--out=-` to avoid CLI error about missing option
|
||||
* The new reporter specification also recognizes `-` as stdout
|
||||
* Multiple reporters can now run at the same time and write to different files (#1712, #2183)
|
||||
* To support this, the `-r`, `--reporter` flag now also accepts optional output destination
|
||||
* For full overview of the semantics of using multiple reporters, look into the reporter documentation
|
||||
|
||||
|
||||
### Fixes
|
||||
* The `INFO` macro no longer contains superfluous semicolon (#1456)
|
||||
* The `--list*` family of command line flags now return 0 on success (#1410, #1146)
|
||||
* Various ways of failing a benchmark are now counted and reporter properly
|
||||
* The ULP matcher now handles comparing numbers with different signs properly (#2152)
|
||||
* Universal ADL-found operators should no longer break decomposition (#2121)
|
||||
* Reporter selection is properly case-insensitive
|
||||
* Previously it forced lower cased name, which would fail for reporters with upper case characters in name
|
||||
* The cumulative reporter base stores benchmark results alongside assertion results
|
||||
* Catch2's SE handling should no longer interferes with ASan on Windows (#2334)
|
||||
|
||||
|
||||
### Other changes
|
||||
@@ -151,9 +213,77 @@ new design.
|
||||
* Catch2's pkg-config integration also provides 2 packages
|
||||
* `catch2` is the statically compiled implementation by itself
|
||||
* `catch2-with-main` also links in the default main
|
||||
* Passing invalid test specifications passed to Catch2 are now reported before tests are run, and are a hard error.
|
||||
* Running 0 tests (e.g. due to empty binary, or test spec not matching anything) returns non-0 exit code
|
||||
* Flag `--allow-running-no-tests` overrides this behaviour.
|
||||
* `NoTests` warning has been removed because it is fully subsumed by this change.
|
||||
|
||||
|
||||
|
||||
## 2.13.7
|
||||
|
||||
### Fixes
|
||||
* Added missing `<iterator>` include in benchmarking. (#2231)
|
||||
* Fixed noexcept build with benchmarking enabled (#2235)
|
||||
* Fixed build for compilers with C++17 support but without C++17 library support (#2195)
|
||||
* JUnit only uses 3 decimal places when reporting durations (#2221)
|
||||
* `!mayfail` tagged tests are now marked as `skipped` in JUnit reporter output (#2116)
|
||||
|
||||
|
||||
## 2.13.6
|
||||
|
||||
### Fixes
|
||||
* Disabling all signal handlers no longer breaks compilation (#2212, #2213)
|
||||
|
||||
### Miscellaneous
|
||||
* `catch_discover_tests` should handle escaped semicolon (`;`) better (#2214, #2215)
|
||||
|
||||
|
||||
## 2.13.5
|
||||
|
||||
### Improvements
|
||||
* Detection of MAC and IPHONE platforms has been improved (#2140, #2157)
|
||||
* Added workaround for bug in XLC 16.1.0.1 (#2155)
|
||||
* Add detection for LCC when it is masquerading as GCC (#2199)
|
||||
* Modified posix signal handling so it supports newer libcs (#2178)
|
||||
* `MINSIGSTKSZ` was no longer usable in constexpr context.
|
||||
|
||||
### Fixes
|
||||
* Fixed compilation of benchmarking when `min` and `max` macros are defined (#2159)
|
||||
* Including `windows.h` without `NOMINMAX` remains a really bad idea, don't do it
|
||||
|
||||
### Miscellaneous
|
||||
* The check whether Catch2 is being built as a subproject is now more reliable (#2202, #2204)
|
||||
* The problem was that if the variable name used internally was defined the project including Catch2 as subproject, it would not be properly overwritten for Catch2's CMake.
|
||||
|
||||
|
||||
## 2.13.4
|
||||
|
||||
### Improvements
|
||||
* Improved the hashing algorithm used for shuffling test cases (#2070)
|
||||
* `TEST_CASE`s that differ only in the last character should be properly shuffled
|
||||
* Note that this means that v2.13.4 gives you a different order of test cases than 2.13.3, even given the same seed.
|
||||
|
||||
### Miscellaneous
|
||||
* Deprecated `ParseAndAddCatchTests` CMake integration (#2092)
|
||||
* It is impossible to implement it properly for all the different test case variants Catch2 provides, and there are better options provided.
|
||||
* Use `catch_discover_tests` instead, which uses runtime information about available tests.
|
||||
* Fixed bug in `catch_discover_tests` that would cause it to fail when used in specific project structures (#2119)
|
||||
* Added Bazel build file
|
||||
* Added an experimental static library target to CMake
|
||||
|
||||
|
||||
## 2.13.3
|
||||
|
||||
### Fixes
|
||||
* Fixed possible infinite loop when combining generators with section filter (`-c` option) (#2025)
|
||||
|
||||
### Miscellaneous
|
||||
* Fixed `ParseAndAddCatchTests` not finding `TEST_CASE`s without tags (#2055, #2056)
|
||||
* `ParseAndAddCatchTests` supports `CMP0110` policy for changing behaviour of `add_test` (#2057)
|
||||
* This was the shortlived change in CMake 3.18.0 that temporarily broke `ParseAndAddCatchTests`
|
||||
|
||||
|
||||
## 2.13.2
|
||||
|
||||
### Improvements
|
||||
@@ -782,7 +912,7 @@ than `single_include/catch.hpp`.**
|
||||
* CLR objects (`T^`) can now be stringified (#1216)
|
||||
* This affects code compiled as C++/CLI
|
||||
* Added `PredicateMatcher`, a matcher that takes an arbitrary predicate function (#1236)
|
||||
* See [documentation for details](https://github.com/catchorg/Catch2/blob/master/docs/matchers.md)
|
||||
* See [documentation for details](https://github.com/catchorg/Catch2/blob/devel/docs/matchers.md)
|
||||
|
||||
### Others
|
||||
* Modified CMake-installed pkg-config to allow `#include <catch.hpp>`(#1239)
|
||||
@@ -810,7 +940,7 @@ than `single_include/catch.hpp`.**
|
||||
* Added an option to warn (+ exit with error) when no tests were ran (#1158)
|
||||
* Use as `-w NoTests`
|
||||
* Added provisional support for Emscripten (#1114)
|
||||
* [Added a way to override the fallback stringifier](https://github.com/catchorg/Catch2/blob/master/docs/configuration.md#fallback-stringifier) (#1024)
|
||||
* [Added a way to override the fallback stringifier](https://github.com/catchorg/Catch2/blob/devel/docs/configuration.md#fallback-stringifier) (#1024)
|
||||
* This allows project's own stringification machinery to be easily reused for Catch
|
||||
* `Catch::Session::run()` now accepts `char const * const *`, allowing it to accept array of string literals (#1031, #1178)
|
||||
* The embedded version of Clara was bumped to v1.1.3
|
||||
|
175
docs/reporter-events.md
Normal file
175
docs/reporter-events.md
Normal file
@@ -0,0 +1,175 @@
|
||||
<a id="top"></a>
|
||||
# Reporter events
|
||||
|
||||
**Contents**<br>
|
||||
[Test running events](#test-running-events)<br>
|
||||
[Benchmarking events](#benchmarking-events)<br>
|
||||
[Listings events](#listings-events)<br>
|
||||
[Miscellaneous events](#miscellaneous-events)<br>
|
||||
|
||||
Reporter events are one of the customization points for user code. They
|
||||
are used by [reporters](reporters.md#top) to customize Catch2's output,
|
||||
and by [event listeners](event-listeners.md#top) to perform in-process
|
||||
actions under some conditions.
|
||||
|
||||
There are currently 21 reporter events in Catch2, split between 4 distinct
|
||||
event groups:
|
||||
* test running events (10 events)
|
||||
* benchmarking (4 events)
|
||||
* listings (3 events)
|
||||
* miscellaneous (4 events)
|
||||
|
||||
## Test running events
|
||||
|
||||
Test running events are always paired so that for each `fooStarting` event,
|
||||
there is a `fooEnded` event. This means that the 10 test running events
|
||||
consist of 5 pairs of events:
|
||||
|
||||
* `testRunStarting` and `testRunEnded`,
|
||||
* `testCaseStarting` and `testCaseEnded`,
|
||||
* `testCasePartialStarting` and `testCasePartialEnded`,
|
||||
* `sectionStarting` and `sectionEnded`,
|
||||
* `assertionStarting` and `assertionEnded`
|
||||
|
||||
### `testRun` events
|
||||
|
||||
```cpp
|
||||
void testRunStarting( TestRunInfo const& testRunInfo );
|
||||
void testRunEnded( TestRunStats const& testRunStats );
|
||||
```
|
||||
|
||||
The `testRun` events bookend the entire test run. `testRunStarting` is
|
||||
emitted before the first test case is executed, and `testRunEnded` is
|
||||
emitted after all the test cases have been executed.
|
||||
|
||||
### `testCase` events
|
||||
|
||||
```cpp
|
||||
void testCaseStarting( TestCaseInfo const& testInfo );
|
||||
void testCaseEnded( TestCaseStats const& testCaseStats );
|
||||
```
|
||||
|
||||
The `testCase` events bookend one _full_ run of a specific test case.
|
||||
Individual runs through a test case, e.g. due to `SECTION`s or `GENERATE`s,
|
||||
are handled by a different event.
|
||||
|
||||
|
||||
### `testCasePartial` events
|
||||
|
||||
> Introduced in Catch2 X.Y.Z
|
||||
|
||||
```cpp
|
||||
void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber );
|
||||
void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber );
|
||||
```
|
||||
|
||||
`testCasePartial` events bookend one _partial_ run of a specific test case.
|
||||
This means that for any given test case, these events can be emitted
|
||||
multiple times, e.g. due to multiple leaf sections.
|
||||
|
||||
In regards to nesting with `testCase` events, `testCasePartialStarting`
|
||||
will never be emitted before the corresponding `testCaseStarting`, and
|
||||
`testCasePartialEnded` will always be emitted before the corresponding
|
||||
`testCaseEnded`.
|
||||
|
||||
|
||||
### `section` events
|
||||
|
||||
```cpp
|
||||
void sectionStarting( SectionInfo const& sectionInfo );
|
||||
void sectionEnded( SectionStats const& sectionStats );
|
||||
```
|
||||
|
||||
`section` events are emitted only for active `SECTION`s, that is, sections
|
||||
that are entered. Sections that are skipped in this test case run-through
|
||||
do not cause events to be emitted.
|
||||
|
||||
_Note that test cases always contain one implicit section. The event for
|
||||
this section is emitted after the corresponding `testCasePartialStarting`
|
||||
event._
|
||||
|
||||
|
||||
### `assertion` events
|
||||
|
||||
```cpp
|
||||
void assertionStarting( AssertionInfo const& assertionInfo );
|
||||
void assertionEnded( AssertionStats const& assertionStats );
|
||||
```
|
||||
|
||||
`assertionStarting` is called after the expression is captured, but before
|
||||
the assertion expression is evaluated. This might seem like a minor
|
||||
distinction, but what it means is that if you have assertion like
|
||||
`REQUIRE( a + b == c + d )`, then what happens is that `a + b` and `c + d`
|
||||
are evaluated before `assertionStarting` is emitted, while the `==` is
|
||||
evaluated after the event.
|
||||
|
||||
|
||||
## Benchmarking events
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
```cpp
|
||||
void benchmarkPreparing( StringRef name ) override;
|
||||
void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
|
||||
void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
|
||||
void benchmarkFailed( StringRef error ) override;
|
||||
```
|
||||
|
||||
Due to the benchmark lifecycle being bit more complicated, the benchmarking
|
||||
events have their own category, even though they could be seen as parallel
|
||||
to the `assertion*` events. You should expect running a benchmark to
|
||||
generate at least 2 of the events above.
|
||||
|
||||
To understand the explanation below, you should read the [benchmarking
|
||||
documentation](benchmarks.md#top) first.
|
||||
|
||||
* `benchmarkPreparing` event is sent after the environmental probe
|
||||
finishes, but before the user code is first estimated.
|
||||
* `benchmarkStarting` event is sent after the user code is estimated,
|
||||
but has not been benchmarked yet.
|
||||
* `benchmarkEnded` event is sent after the user code has been benchmarked,
|
||||
and contains the benchmarking results.
|
||||
* `benchmarkFailed` event is sent if either the estimation or the
|
||||
benchmarking itself fails.
|
||||
|
||||
|
||||
## Listings events
|
||||
|
||||
> Introduced in Catch2 X.Y.Z.
|
||||
|
||||
Listings events are events that correspond to the test binary being
|
||||
invoked with `--list-foo` flag.
|
||||
|
||||
There are currently 3 listing events, one for reporters, one for tests,
|
||||
and one for tags. Note that they are not exclusive to each other.
|
||||
|
||||
```cpp
|
||||
void listReporters( std::vector<ReporterDescription> const& descriptions );
|
||||
void listTests( std::vector<TestCaseHandle> const& tests );
|
||||
void listTags( std::vector<TagInfo> const& tagInfos );
|
||||
```
|
||||
|
||||
|
||||
## Miscellaneous events
|
||||
|
||||
```cpp
|
||||
void reportInvalidTestSpec( StringRef unmatchedSpec );
|
||||
void fatalErrorEncountered( StringRef error );
|
||||
void noMatchingTestCases( StringRef unmatchedSpec );
|
||||
```
|
||||
|
||||
These are one-off events that do not neatly fit into other categories.
|
||||
|
||||
`reportInvalidTestSpec` is sent for each [test specification command line
|
||||
argument](command-line.md#specifying-which-tests-to-run) that wasn't
|
||||
parsed into a valid spec.
|
||||
|
||||
`fatalErrorEncountered` is sent when Catch2's POSIX signal handling
|
||||
or Windows SE handler is called into with a fatal signal/exception.
|
||||
|
||||
`noMatchingTestCases` is sent for each user provided test specification
|
||||
that did not match any registered tests.
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -1,46 +1,187 @@
|
||||
<a id="top"></a>
|
||||
# Reporters
|
||||
|
||||
Catch has a modular reporting system and comes bundled with a handful of useful reporters built in.
|
||||
You can also write your own reporters.
|
||||
Reporters are a customization point for most of Catch2's output, e.g.
|
||||
formatting and writing out [assertions (whether passing or failing),
|
||||
sections, test cases, benchmarks, and so on](reporter-events.md#top).
|
||||
|
||||
Catch2 comes with a bunch of reporters by default (currently 8), and
|
||||
you can also write your own reporter. Because multiple reporters can
|
||||
be active at the same time, your own reporters do not even have to handle
|
||||
all reporter event, just the ones you are interested in, e.g. benchmarks.
|
||||
|
||||
|
||||
## Using different reporters
|
||||
|
||||
The reporter to use can easily be controlled from the command line.
|
||||
To specify a reporter use [`-r` or `--reporter`](command-line.md#choosing-a-reporter-to-use), followed by the name of the reporter, e.g.:
|
||||
You can see which reporters are available by running the test binary
|
||||
with `--list-reporters`. You can then pick one of them with the [`-r`,
|
||||
`--reporter` option](command-line.md#choosing-a-reporter-to-use), followed
|
||||
by the name of the desired reporter, like so:
|
||||
|
||||
```
|
||||
-r xml
|
||||
--reporter xml
|
||||
```
|
||||
|
||||
If you don't specify a reporter then the console reporter is used by default.
|
||||
There are four reporters built in to the single include:
|
||||
You can also select multiple reporters to be used at the same time.
|
||||
In that case you should read the [section on using multiple
|
||||
reporters](#multiple-reporters) to avoid any surprises from doing so.
|
||||
|
||||
* `console` writes as lines of text, formatted to a typical terminal width, with colours if a capable terminal is detected.
|
||||
* `compact` similar to `console` but optimised for minimal output - each entry on one line
|
||||
* `junit` writes xml that corresponds to Ant's [junitreport](http://help.catchsoftware.com/display/ET/JUnit+Format) target. Useful for build systems that understand Junit.
|
||||
Because of the way the junit format is structured the run must complete before anything is written.
|
||||
* `xml` writes an xml format tailored to Catch. Unlike `junit` this is a streaming format so results are delivered progressively.
|
||||
|
||||
There are a few additional reporters, for specific build systems, in the Catch repository (in `include\reporters`) which you can `#include` in your project if you would like to make use of them.
|
||||
Do this in one source file - the same one you have `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`.
|
||||
<a id="multiple-reporters"></a>
|
||||
## Using multiple reporters
|
||||
|
||||
* `teamcity` writes the native, streaming, format that [TeamCity](https://www.jetbrains.com/teamcity/) understands.
|
||||
Use this when building as part of a TeamCity build to see results as they happen ([code example](../examples/207-Rpt-TeamCityReporter.cpp)).
|
||||
* `tap` writes in the TAP ([Test Anything Protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) format.
|
||||
* `automake` writes in a format that correspond to [automake .trs](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html) files
|
||||
* `sonarqube` writes the [SonarQube Generic Test Data](https://docs.sonarqube.org/latest/analysis/generic-test/) XML format.
|
||||
> Support for having multiple parallel reporters was [introduced](https://github.com/catchorg/Catch2/pull/2183) in Catch2 X.Y.Z
|
||||
|
||||
Catch2 supports using multiple reporters at the same time while having
|
||||
them write into different destinations. The two main uses of this are
|
||||
|
||||
* having both human-friendly and machine-parseable (e.g. in JUnit format)
|
||||
output from one run of binary
|
||||
* having "partial" reporters that are highly specialized, e.g. having one
|
||||
reporter that writes out benchmark results as markdown tables and does
|
||||
nothing else, while also having standard testing output separately
|
||||
|
||||
Specifying multiple reporter looks like this:
|
||||
```
|
||||
--reporter console::- --reporter JUnit::result-junit.xml
|
||||
```
|
||||
|
||||
Using multiple reporters (or one reporter and one-or-more [event
|
||||
listeners](event-listener.md#top)) can have surprisingly complex semantics
|
||||
when using customization points provided to reporters by Catch2, namely
|
||||
capturing stdout/stderr from test cases.
|
||||
|
||||
As long as at least one reporter (or listener) asks Catch2 to capture
|
||||
stdout/stderr, captured stdout and stderr will be available to all
|
||||
reporters and listeners.
|
||||
|
||||
Because this might be surprising to the users, if at least one active
|
||||
_reporter_ is non-capturing, then Catch2 tries to roughly emulate
|
||||
non-capturing behaviour by printing out the captured stdout/stderr
|
||||
just before `testCasePartialEnded` event is sent out to the active
|
||||
reporters and listeners. This means that stdout/stderr is no longer
|
||||
printed out from tests as it is being written, but instead it is written
|
||||
out in batch after each runthrough of a test case is finished.
|
||||
|
||||
You see what reporters are available from the command line by running with `--list-reporters`.
|
||||
|
||||
By default all these reports are written to stdout, but can be redirected to a file with [`-o` or `--out`](command-line.md#sending-output-to-a-file)
|
||||
|
||||
## Writing your own reporter
|
||||
|
||||
You can write your own custom reporter and register it with Catch.
|
||||
At time of writing the interface is subject to some changes so is not, yet, documented here.
|
||||
If you are determined you shouldn't have too much trouble working it out from the existing implementations -
|
||||
but do keep in mind upcoming changes (these will be minor, simplifying, changes such as not needing to forward calls to the base class).
|
||||
You can also write your own custom reporter and tell Catch2 to use it.
|
||||
When writing your reporter, you have two options:
|
||||
|
||||
* Derive from `Catch::IStreamingReporter`. When doing this, you will have
|
||||
to provide handling for all [reporter events](reporter-events.md#top).
|
||||
* Derive from one of the provided [utility reporter bases in
|
||||
Catch2](#utility-reporter-bases).
|
||||
|
||||
Generally we recommend doing the latter, as it is less work.
|
||||
|
||||
Apart from overriding handling of the individual reporter events, reporters
|
||||
have access to some extra customization points, described below.
|
||||
|
||||
|
||||
### Utility reporter bases
|
||||
|
||||
Catch2 currently provides two utility reporter bases:
|
||||
|
||||
* `Catch::StreamingReporterBase`
|
||||
* `Catch::CumulativeReporterBase`
|
||||
|
||||
`StreamingReporterBase` is useful for reporters that can format and write
|
||||
out the events as they come in. It provides (usually empty) implementation
|
||||
for all reporter events, and if you let it handle the relevant events,
|
||||
it also handles storing information about active test run and test case.
|
||||
|
||||
`CumulativeReporterBase` is a base for reporters that need to see the whole
|
||||
test run, before they can start writing the output, such as the JUnit
|
||||
and SonarQube reporters. This post-facto approach requires the assertions
|
||||
to be stringified when it is finished, so that the assertion can be written
|
||||
out later. Because the stringification can be expensive, and not all
|
||||
cumulative reporters need the assertions, this base provides customization
|
||||
point to change whether the assertions are saved or not, separate for
|
||||
passing and failing assertions.
|
||||
|
||||
|
||||
_Generally we recommend that if you override a member function from either
|
||||
of the bases, you call into the base's implementation first. This is not
|
||||
necessarily in all cases, but it is safer and easier._
|
||||
|
||||
|
||||
Writing your own reporter then looks like this:
|
||||
|
||||
```cpp
|
||||
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class PartialReporter : public Catch::StreamingReporterBase {
|
||||
public:
|
||||
using StreamingReporterBase::StreamingReporterBase;
|
||||
|
||||
static std::string getDescription() {
|
||||
return "Reporter for testing TestCasePartialStarting/Ended events";
|
||||
}
|
||||
|
||||
void testCasePartialStarting(Catch::TestCaseInfo const& testInfo,
|
||||
uint64_t partNumber) override {
|
||||
std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n';
|
||||
}
|
||||
|
||||
void testCasePartialEnded(Catch::TestCaseStats const& testCaseStats,
|
||||
uint64_t partNumber) override {
|
||||
std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
CATCH_REGISTER_REPORTER("partial", PartialReporter)
|
||||
```
|
||||
|
||||
This create a simple reporter that responds to `testCasePartial*` events,
|
||||
and calls itself "partial" reporter, so it can be invoked with
|
||||
`--reporter partial` command line flag.
|
||||
|
||||
|
||||
### `ReporterPreferences`
|
||||
|
||||
Each reporter instance contains instance of `ReporterPreferences`, a type
|
||||
that holds flags for the behaviour of Catch2 when this reporter run.
|
||||
Currently there are two customization options:
|
||||
|
||||
* `shouldRedirectStdOut` - whether the reporter wants to handle
|
||||
writes to stdout/stderr from user code, or not. This is useful for
|
||||
reporters that output machine-parseable output, e.g. the JUnit
|
||||
reporter, or the XML reporter.
|
||||
* `shouldReportAllAssertions` - whether the reporter wants to handle
|
||||
`assertionEnded` events for passing assertions as well as failing
|
||||
assertions. Usually reporters do not report successful assertions
|
||||
and don't need them for their output, but sometimes the desired output
|
||||
format includes passing assertions even without the `-s` flag.
|
||||
|
||||
|
||||
### Other expected functionality of a reporter
|
||||
|
||||
When writing a custom reporter, there are few more things that you should
|
||||
keep in mind. These are not important for correctness, but they are
|
||||
important for the reporter to work _nicely_.
|
||||
|
||||
* Catch2 provides a simple verbosity option for users. There are three
|
||||
verbosity levels, "quiet", "normal", and "high", and if it makes sense
|
||||
for reporter's output format, it should respond to these by changing
|
||||
what, and how much, it writes out.
|
||||
|
||||
* Catch2 operates with an rng-seed. Knowing what seed a test run had
|
||||
is important if you want to replicate it, so your reporter should
|
||||
report the rng-seed, if at all possible given the target output format.
|
||||
|
||||
* Catch2 also operates with test filters, or test specs. If a filter
|
||||
is present, you should also report the filter, if at all possible given
|
||||
the target output format.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
@@ -1,72 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Why do my tests take so long to compile?
|
||||
|
||||
**Contents**<br>
|
||||
[Short answer](#short-answer)<br>
|
||||
[Long answer](#long-answer)<br>
|
||||
[Practical example](#practical-example)<br>
|
||||
[Other possible solutions](#other-possible-solutions)<br>
|
||||
|
||||
Several people have reported that test code written with Catch takes much longer to compile than they would expect. Why is that?
|
||||
|
||||
Catch is implemented entirely in headers. There is a little overhead due to this - but not as much as you might think - and you can minimise it simply by organising your test code as follows:
|
||||
|
||||
## Short answer
|
||||
Exactly one source file must ```#define``` either ```CATCH_CONFIG_MAIN``` or ```CATCH_CONFIG_RUNNER``` before ```#include```-ing Catch. In this file *do not write any test cases*! In most cases that means this file will just contain two lines (the ```#define``` and the ```#include```).
|
||||
|
||||
## Long answer
|
||||
|
||||
Usually C++ code is split between a header file, containing declarations and prototypes, and an implementation file (.cpp) containing the definition, or implementation, code. Each implementation file, along with all the headers that it includes (and which those headers include, etc), is expanded into a single entity called a translation unit - which is then passed to the compiler and compiled down to an object file.
|
||||
|
||||
But functions and methods can also be written inline in header files. The downside to this is that these definitions will then be compiled in *every* translation unit that includes the header.
|
||||
|
||||
Because Catch is implemented *entirely* in headers you might think that the whole of Catch must be compiled into every translation unit that uses it! Actually it's not quite as bad as that. Catch mitigates this situation by effectively maintaining the traditional separation between the implementation code and declarations. Internally the implementation code is protected by ```#ifdef```s and is conditionally compiled into only one translation unit. This translation unit is that one that ```#define```s ```CATCH_CONFIG_MAIN``` or ```CATCH_CONFIG_RUNNER```. Let's call this the main source file.
|
||||
|
||||
As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch.
|
||||
|
||||
## Practical example
|
||||
Assume you have the `Factorial` function from the [tutorial](tutorial.md#top) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`:
|
||||
|
||||
```cpp
|
||||
// tests-main.cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
```
|
||||
|
||||
```cpp
|
||||
// tests-factorial.cpp
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "factorial.h"
|
||||
|
||||
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
REQUIRE( Factorial(1) == 1 );
|
||||
REQUIRE( Factorial(2) == 2 );
|
||||
REQUIRE( Factorial(3) == 6 );
|
||||
REQUIRE( Factorial(10) == 3628800 );
|
||||
}
|
||||
```
|
||||
|
||||
After compiling `tests-main.cpp` once, it is enough to link it with separately compiled `tests-factorial.cpp`. This means that adding more tests to `tests-factorial.cpp`, will not result in recompiling Catch's main and the resulting compilation times will decrease substantially.
|
||||
|
||||
```
|
||||
$ g++ tests-main.cpp -c
|
||||
$ g++ factorial.cpp -c
|
||||
$ g++ tests-main.o factorial.o tests-factorial.cpp -o tests && ./tests -r compact
|
||||
Passed 1 test case with 4 assertions.
|
||||
```
|
||||
|
||||
Now, the next time we change the file `tests-factorial.cpp` (say we add `REQUIRE( Factorial(0) == 1)`), it is enough to recompile the tests instead of recompiling main as well:
|
||||
|
||||
```
|
||||
$ g++ tests-main.o factorial.o tests-factorial.cpp -o tests && ./tests -r compact
|
||||
tests-factorial.cpp:11: failed: Factorial(0) == 1 for: 0 == 1
|
||||
Failed 1 test case, failed 1 assertion.
|
||||
```
|
||||
|
||||
## Other possible solutions
|
||||
You can also opt to sacrifice some features in order to speed-up Catch's compilation times. For details see the [documentation on Catch's compile-time configuration](configuration.md#other-toggles).
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -44,7 +44,15 @@ The tag expression, ```"[widget]"``` selects A, B & D. ```"[gadget]"``` selects
|
||||
|
||||
For more detail on command line selection see [the command line docs](command-line.md#specifying-which-tests-to-run)
|
||||
|
||||
Tag names are not case sensitive and can contain any ASCII characters. This means that tags `[tag with spaces]` and `[I said "good day"]` are both allowed tags and can be filtered on. Escapes are not supported however and `[\]]` is not a valid tag.
|
||||
Tag names are not case sensitive and can contain any ASCII characters.
|
||||
This means that tags `[tag with spaces]` and `[I said "good day"]`
|
||||
are both allowed tags and can be filtered on. However, escapes are not
|
||||
supported however and `[\]]` is not a valid tag.
|
||||
|
||||
The same tag can be specified multiple times for a single test case,
|
||||
but only one of the instances of identical tags will be kept. Which one
|
||||
is kept is functionally random.
|
||||
|
||||
|
||||
### Special Tags
|
||||
|
||||
@@ -90,15 +98,65 @@ This macro maps onto ```TEST_CASE``` and works in the same way, except that the
|
||||
* **WHEN(** _something_ **)**
|
||||
* **THEN(** _something_ **)**
|
||||
|
||||
These macros map onto ```SECTION```s except that the section names are the _something_s prefixed by "given: ", "when: " or "then: " respectively.
|
||||
These macros map onto ```SECTION```s except that the section names are the _something_ texts prefixed by
|
||||
"given: ", "when: " or "then: " respectively. These macros also map onto the AAA or A<sup>3</sup> test pattern
|
||||
(standing either for [Assemble-Activate-Assert](http://wiki.c2.com/?AssembleActivateAssert) or
|
||||
[Arrange-Act-Assert](http://wiki.c2.com/?ArrangeActAssert)), and in this context, the macros provide both code
|
||||
documentation and reporting of these parts of a test case without the need for extra comments or code to do so.
|
||||
|
||||
Semantically, a `GIVEN` clause may have multiple _independent_ `WHEN` clauses within it. This allows a test
|
||||
to have, e.g., one set of "given" objects and multiple subtests using those objects in various ways in each
|
||||
of the `WHEN` clauses without repeating the initialisation from the `GIVEN` clause. When there are _dependent_
|
||||
clauses -- such as a second `WHEN` clause that should only happen _after_ the previous `WHEN` clause has been
|
||||
executed and validated -- there are additional macros starting with `AND_`:
|
||||
|
||||
* **AND_GIVEN(** _something_ **)**
|
||||
* **AND_WHEN(** _something_ **)**
|
||||
* **AND_THEN(** _something_ **)**
|
||||
|
||||
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.
|
||||
These are used to chain ```GIVEN```s, ```WHEN```s and ```THEN```s together. The `AND_*` clause is placed
|
||||
_inside_ the clause on which it depends. There can be multiple _independent_ clauses that are all _dependent_
|
||||
on a single outer clause.
|
||||
```cpp
|
||||
SCENARIO( "vector can be sized and resized" ) {
|
||||
GIVEN( "An empty vector" ) {
|
||||
auto v = std::vector<std::string>{};
|
||||
|
||||
> `AND_GIVEN` was [introduced](https://github.com/catchorg/Catch2/issues/1360) in Catch 2.4.0.
|
||||
// Validate assumption of the GIVEN clause
|
||||
THEN( "The size and capacity start at 0" ) {
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() == 0 );
|
||||
}
|
||||
|
||||
// Validate one use case for the GIVEN object
|
||||
WHEN( "push_back() is called" ) {
|
||||
v.push_back("hullo");
|
||||
|
||||
THEN( "The size changes" ) {
|
||||
REQUIRE( v.size() == 1 );
|
||||
REQUIRE( v.capacity() >= 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This code will result in two runs through the scenario:
|
||||
```
|
||||
Scenario : vector can be sized and resized
|
||||
Given : An empty vector
|
||||
Then : The size and capacity start at 0
|
||||
|
||||
Scenario : vector can be sized and resized
|
||||
Given : An empty vector
|
||||
When : push_back() is called
|
||||
Then : The size changes
|
||||
```
|
||||
|
||||
See also [runnable example on godbolt](https://godbolt.org/z/e5vPPM),
|
||||
with a more complicated (and failing) example.
|
||||
|
||||
> `AND_GIVEN` was [introduced](https://github.com/catchorg/Catch2/issues/1360) in Catch2 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.
|
||||
|
||||
@@ -112,7 +170,7 @@ 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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1437) in Catch2 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
|
||||
@@ -164,7 +222,7 @@ 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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1468) in Catch2 2.6.0.
|
||||
|
||||
_template-type1_ through _template-typen_ is list of template template
|
||||
types which should be combined with each of _template-arg1_ through
|
||||
@@ -203,13 +261,9 @@ TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities", "[template][product
|
||||
}
|
||||
```
|
||||
|
||||
_While there is an upper limit on the number of types you can specify
|
||||
in single `TEMPLATE_TEST_CASE` or `TEMPLATE_PRODUCT_TEST_CASE`, the limit
|
||||
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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1627) in Catch2 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
|
||||
@@ -229,7 +283,7 @@ 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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch2 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`.
|
||||
@@ -251,7 +305,7 @@ Currently Catch2 support up to 11 template parameters in signature
|
||||
|
||||
* **TEMPLATE_TEST_CASE_SIG(** _test name_ , _tags_, _signature_, _type1_, _type2_, ..., _typen_ **)**
|
||||
|
||||
Inside `TEMPLATE_TEST_CASE_SIG` test case you can use the names of template parameters as defined in _signature_.
|
||||
Inside `TEMPLATE_TEST_CASE_SIG` test case you can use the names of template parameters as defined in _signature_.
|
||||
|
||||
```cpp
|
||||
TEMPLATE_TEST_CASE_SIG("TemplateTestSig: arrays can be created from NTTP arguments", "[vector][template][nttp]",
|
||||
|
@@ -88,7 +88,7 @@ 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.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch2 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`,
|
||||
|
@@ -71,7 +71,7 @@ CATCH_TRANSLATE_EXCEPTION( MyType const& ex ) {
|
||||
|
||||
## Enums
|
||||
|
||||
> Introduced in Catch 2.8.0.
|
||||
> Introduced in Catch2 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.
|
||||
@@ -110,7 +110,7 @@ TEST_CASE() {
|
||||
|
||||
## Floating point precision
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1614) in Catch 2.8.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1614) in Catch2 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,
|
||||
|
233
docs/tutorial.md
233
docs/tutorial.md
@@ -3,32 +3,20 @@
|
||||
|
||||
**Contents**<br>
|
||||
[Getting Catch2](#getting-catch2)<br>
|
||||
[Where to put it?](#where-to-put-it)<br>
|
||||
[Writing tests](#writing-tests)<br>
|
||||
[Test cases and sections](#test-cases-and-sections)<br>
|
||||
[BDD-Style](#bdd-style)<br>
|
||||
[Scaling up](#scaling-up)<br>
|
||||
[Type parametrised test cases](#type-parametrised-test-cases)<br>
|
||||
[BDD style testing](#bdd-style-testing)<br>
|
||||
[Data and Type driven tests](#data-and-type-driven-tests)<br>
|
||||
[Next steps](#next-steps)<br>
|
||||
|
||||
|
||||
## Getting Catch2
|
||||
|
||||
The simplest way to get Catch2 is to download the latest [single header version](https://raw.githubusercontent.com/catchorg/Catch2/master/single_include/catch2/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file.
|
||||
Ideally you should be using Catch2 through its [CMake integration](cmake-integration.md#top).
|
||||
Catch2 also provides pkg-config files and single TU distribution, but this
|
||||
documentation will assume you are using CMake. If you are using single-TU
|
||||
distribution instead, remember to replace the included header with `catch_amalgamated.hpp`.
|
||||
|
||||
Alternative ways of getting Catch2 include using your system package
|
||||
manager, or installing it using [its CMake package](cmake-integration.md#installing-catch2-from-git-repository).
|
||||
|
||||
The full source for Catch2, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there.
|
||||
|
||||
|
||||
## Where to put it?
|
||||
|
||||
Catch2 is header only. All you need to do is drop the file somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself! This is a particularly good option for other Open-Source projects that want to use Catch for their test suite. See [this blog entry for more on that](https://levelofindirection.com/blog/unit-testing-in-cpp-and-objective-c-just-got-ridiculously-easier-still.html).
|
||||
|
||||
The rest of this tutorial will assume that the Catch2 single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
|
||||
|
||||
_If you have installed Catch2 from system package manager, or CMake
|
||||
package, you need to include the header as `#include <catch2/catch.hpp>`_
|
||||
|
||||
## Writing tests
|
||||
|
||||
@@ -40,11 +28,8 @@ unsigned int Factorial( unsigned int number ) {
|
||||
}
|
||||
```
|
||||
|
||||
To keep things simple we'll put everything in a single file (<a href="#scaling-up">see later for more on how to structure your test files</a>).
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "catch.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
unsigned int Factorial( unsigned int number ) {
|
||||
return number <= 1 ? number : Factorial(number-1)*number;
|
||||
@@ -60,13 +45,10 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
|
||||
This will compile to a complete executable which responds to [command line arguments](command-line.md#top). If you just run it with no arguments it will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: "did it work").
|
||||
|
||||
If you run this as written it will pass. Everything is good. Right?
|
||||
Well, there is still a bug here. In fact the first version of this tutorial I posted here genuinely had the bug in! So it's not completely contrived (thanks to Daryle Walker (```@CTMacUser```) for pointing this out).
|
||||
|
||||
What is the bug? Well what is the factorial of zero?
|
||||
[The factorial of zero is one](http://mathforum.org/library/drmath/view/57128.html) - which is just one of those things you have to know (and remember!).
|
||||
|
||||
Let's add that to the test case:
|
||||
Anyway, as the tests above as written will pass, but there is a bug.
|
||||
The problem is that `Factorial(0)` should return 1 (due to [its
|
||||
definition](https://en.wikipedia.org/wiki/Factorial#Factorial_of_zero)).
|
||||
Let's add that as an assertion to the test case:
|
||||
|
||||
```c++
|
||||
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
@@ -78,7 +60,8 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
}
|
||||
```
|
||||
|
||||
Now we get a failure - something like:
|
||||
After another compile & run cycle, we will see a test failure. The output
|
||||
will look something like:
|
||||
|
||||
```
|
||||
Example.cpp:9: FAILED:
|
||||
@@ -87,37 +70,51 @@ with expansion:
|
||||
0 == 1
|
||||
```
|
||||
|
||||
Note that we get the actual return value of Factorial(0) printed for us (0) - even though we used a natural expression with the == operator. That lets us immediately see what the problem is.
|
||||
|
||||
Let's change the factorial function to:
|
||||
Note that the output contains both the original expression,
|
||||
`REQUIRE( Factorial(0) == 1 )` and the actual value returned by the call
|
||||
to the `Factorial` function: `0`.
|
||||
|
||||
We can fix this bug by slightly modifying the `Factorial` function to:
|
||||
```c++
|
||||
unsigned int Factorial( unsigned int number ) {
|
||||
return number > 1 ? Factorial(number-1)*number : 1;
|
||||
}
|
||||
```
|
||||
|
||||
Now all the tests pass.
|
||||
|
||||
Of course there are still more issues to deal with. For example we'll hit problems when the return value starts to exceed the range of an unsigned int. With factorials that can happen quite quickly. You might want to add tests for such cases and decide how to handle them. We'll stop short of doing that here.
|
||||
|
||||
### What did we do here?
|
||||
|
||||
Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take a moment to consider those before we move on.
|
||||
Although this was a simple test it's been enough to demonstrate a few
|
||||
things about how Catch2 is used. Let's take a moment to consider those
|
||||
before we move on.
|
||||
|
||||
* We introduce test cases with the `TEST_CASE` macro. This macro takes
|
||||
one or two string arguments - a free form test name and, optionally,
|
||||
one or more tags (for more see [Test cases and Sections](#test-cases-and-sections)).
|
||||
* The test automatically self-registers with the test runner, and user
|
||||
does not have do anything more to ensure that it is picked up by the test
|
||||
framework. _Note that you can run specific test, or set of tests,
|
||||
through the [command line](command-line#top)._
|
||||
* The individual test assertions are written using the `REQUIRE` macro.
|
||||
It accepts a boolean expression, and uses expression templates to
|
||||
internally decompose it, so that it can be individually stringified
|
||||
on test failure.
|
||||
|
||||
On the last point, note that there are more testing macros available,
|
||||
because not all useful checks can be expressed as a simple boolean
|
||||
expression. As an example, checking that an expression throws an exception
|
||||
is done with the `REQUIRE_THROWS` macro. More on that later.
|
||||
|
||||
1. All we did was ```#define``` one identifier and ```#include``` one header and we got everything - even an implementation of ```main()``` that will [respond to command line arguments](command-line.md#top). You can only use that ```#define``` in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll just ```#include "catch.hpp"``` and go. Usually it's a good idea to have a dedicated implementation file that just has ```#define CATCH_CONFIG_MAIN``` and ```#include "catch.hpp"```. You can also provide your own implementation of main and drive Catch yourself (see [Supplying-your-own-main()](own-main.md#top)).
|
||||
2. We introduce test cases with the ```TEST_CASE``` macro. This macro takes one or two arguments - a free form test name and, optionally, one or more tags (for more see <a href="#test-cases-and-sections">Test cases and Sections</a>). The test name must be unique. You can run sets of tests by specifying a wildcarded test name or a tag expression. See the [command line docs](command-line.md#top) for more information on running tests.
|
||||
3. The name and tags arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
|
||||
4. We write our individual test assertions using the ```REQUIRE``` macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
|
||||
|
||||
<a id="test-cases-and-sections"></a>
|
||||
## Test cases and sections
|
||||
|
||||
Most test frameworks have a class-based fixture mechanism. That is, test cases map to methods on a class and common setup and teardown can be performed in ```setup()``` and ```teardown()``` methods (or constructor/ destructor in languages, like C++, that support deterministic destruction).
|
||||
Like most test frameworks, Catch2 supports a class-based fixture mechanism,
|
||||
where individual tests are methods on class and setup/teardown can be
|
||||
done in constructor/destructor of the type.
|
||||
|
||||
While Catch fully supports this way of working there are a few problems with the approach. In particular the way your code must be split up, and the blunt granularity of it, may cause problems. You can only have one setup/ teardown pair across a set of methods, but sometimes you want slightly different setup in each method, or you may even want several levels of setup (a concept which we will clarify later on in this tutorial). It was <a href="http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html">problems like these</a> that led James Newkirk, who led the team that built NUnit, to start again from scratch and <a href="http://jamesnewkirk.typepad.com/posts/2007/09/announcing-xuni.html">build xUnit</a>).
|
||||
|
||||
Catch takes a different approach (to both NUnit and xUnit) that is a more natural fit for C++ and the C family of languages. This is best explained through an example ([code](../examples/100-Fix-Section.cpp)):
|
||||
However, their use in Catch2 is rare, because idiomatic Catch2 tests
|
||||
instead use _sections_ to share setup and teardown code between test code.
|
||||
This is best explained through an example ([code](../examples/100-Fix-Section.cpp)):
|
||||
|
||||
```c++
|
||||
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
@@ -154,125 +151,75 @@ TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
}
|
||||
```
|
||||
|
||||
For each ```SECTION``` the ```TEST_CASE``` is executed from the start - so as we enter each section we know that size is 5 and capacity is at least 5. We enforced those requirements with the ```REQUIRE```s at the top level so we can be confident in them.
|
||||
This works because the ```SECTION``` macro contains an if statement that calls back into Catch to see if the section should be executed. One leaf section is executed on each run through a ```TEST_CASE```. The other sections are skipped. Next time through the next section is executed, and so on until no new sections are encountered.
|
||||
For each `SECTION` the `TEST_CASE` is executed from the start. This means
|
||||
that each section is entered with a freshly constructed vector `v`, that
|
||||
we know has size 5 and capacity at least 5, because the two assertions
|
||||
are also checked before the section is entered. Each run through a test
|
||||
case will execute one, and only one, leaf section.
|
||||
|
||||
So far so good - this is already an improvement on the setup/teardown approach because now we see our setup code inline and use the stack.
|
||||
Section can also be nested, in which case the parent section can be
|
||||
entered multiple times, once for each leaf section. Nested sections are
|
||||
most useful when you have multiple tests that share part of the set up.
|
||||
To continue on the vector example above, you could add a check that
|
||||
`std::vector::reserve` does not remove unused excess capacity, like this:
|
||||
|
||||
The power of sections really shows, however, when we need to execute a sequence of checked operations. Continuing the vector example, we might want to verify that attempting to reserve a capacity smaller than the current capacity of the vector changes nothing. We can do that, naturally, like so:
|
||||
|
||||
```c++
|
||||
```cpp
|
||||
SECTION( "reserving bigger changes capacity but not size" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
|
||||
SECTION( "reserving smaller again does not change capacity" ) {
|
||||
SECTION( "reserving down unused capacity does not change capacity" ) {
|
||||
v.reserve( 7 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Sections can be nested to an arbitrary depth (limited only by your stack size). Each leaf section (i.e. a section that contains no nested sections) will be executed exactly once, on a separate path of execution from any other leaf section (so no leaf section can interfere with another). A failure in a parent section will prevent nested sections from running - but then that's the idea.
|
||||
Another way to look at sections is that they are a way to define a tree
|
||||
of paths through the test. Each section represents a node, and the final
|
||||
tree is walked in depth-first manner, with each path only visiting only
|
||||
one leaf node.
|
||||
|
||||
## BDD-Style
|
||||
|
||||
If you name your test cases and sections appropriately you can achieve a BDD-style specification structure. This became such a useful way of working that first class support has been added to Catch. Scenarios can be specified using ```SCENARIO```, ```GIVEN```, ```WHEN``` and ```THEN``` macros, which map on to ```TEST_CASE```s and ```SECTION```s, respectively. For more details see [Test cases and sections](test-cases-and-sections.md#top).
|
||||
|
||||
The vector example can be adjusted to use these macros like so ([example code](../examples/120-Bdd-ScenarioGivenWhenThen.cpp)):
|
||||
|
||||
```c++
|
||||
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
||||
|
||||
GIVEN( "A vector with some items" ) {
|
||||
std::vector<int> v( 5 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
WHEN( "the size is increased" ) {
|
||||
v.resize( 10 );
|
||||
|
||||
THEN( "the size and capacity change" ) {
|
||||
REQUIRE( v.size() == 10 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "the size is reduced" ) {
|
||||
v.resize( 0 );
|
||||
|
||||
THEN( "the size changes but not capacity" ) {
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
WHEN( "more capacity is reserved" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
THEN( "the capacity changes but not the size" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "less capacity is reserved" ) {
|
||||
v.reserve( 0 );
|
||||
|
||||
THEN( "neither size nor capacity are changed" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Conveniently, these tests will be reported as follows when run:
|
||||
|
||||
```
|
||||
Scenario: vectors can be sized and resized
|
||||
Given: A vector with some items
|
||||
When: more capacity is reserved
|
||||
Then: the capacity changes but not the size
|
||||
```
|
||||
|
||||
<a id="scaling-up"></a>
|
||||
## Scaling up
|
||||
|
||||
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
|
||||
|
||||
The requirement is that the following block of code ([or equivalent](own-main.md#top)):
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
```
|
||||
|
||||
appears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include "catch.hpp"``` - do not repeat the ```#define```!
|
||||
|
||||
In fact it is usually a good idea to put the block with the ```#define``` [in its own source file](slow-compiles.md#top) (code example [main](../examples/020-TestCase-1.cpp), [tests](../examples/020-TestCase-2.cpp)).
|
||||
|
||||
Do not write your tests in header files!
|
||||
There is no practical limit on nesting sections, as long as your compiler
|
||||
can handle them, but keep in mind that overly nested sections can become
|
||||
unreadable. From experience, having section nest more than 3 levels is
|
||||
usually very hard to follow and not worth the removed duplication.
|
||||
|
||||
|
||||
## Type parametrised test cases
|
||||
## BDD style testing
|
||||
|
||||
Test cases in Catch2 can be also parametrised by type, via the
|
||||
`TEMPLATE_TEST_CASE` and `TEMPLATE_PRODUCT_TEST_CASE` macros,
|
||||
which behave in the same way the `TEST_CASE` macro, but are run for
|
||||
every type or type combination.
|
||||
Catch2 also provides some basic support for BDD-style testing. There are
|
||||
macro aliases for `TEST_CASE` and `SECTIONS` that you can use so that
|
||||
the resulting tests read as BDD spec. `SCENARIO` acts as a `TEST_CASE`
|
||||
with "Scenario: " name prefix. Then there are `GIVEN`, `WHEN`, `THEN`
|
||||
(and their variants with `AND_` prefix), which act as a `SECTION`,
|
||||
similarly prefixed with the macro name.
|
||||
|
||||
For more details, see our documentation on [test cases and
|
||||
sections](test-cases-and-sections.md#type-parametrised-test-cases).
|
||||
For more details on the macros look at the [test cases and
|
||||
sections](test-cases-and-sections.md#top) part of the reference docs,
|
||||
or at the [vector example done with BDD macros](../examples/120-Bdd-ScenarioGivenWhenThen.cpp).
|
||||
|
||||
|
||||
## Data and Type driven tests
|
||||
|
||||
Test cases in Catch2 can also be driven by types, input data, or both
|
||||
at the same time.
|
||||
|
||||
For more details look into the Catch2 reference, either at the
|
||||
[type parametrized test cases](test-cases-and-sections.md#type-parametrised-test-cases),
|
||||
or [data generators](generators.md#top).
|
||||
|
||||
|
||||
## Next steps
|
||||
|
||||
This has been a brief introduction to get you up and running with Catch, and to point out some of the key differences between Catch and other frameworks you may already be familiar with. This will get you going quite far already and you are now in a position to dive in and write some tests.
|
||||
This page is a brief introduction to get you up and running with Catch2,
|
||||
and to show the basic features of Catch2. The features mentioned here
|
||||
can get you quite far, but there are many more. However, you can read
|
||||
about these as you go, in the ever-growing [reference section](Readme.md#top)
|
||||
of the documentation.
|
||||
|
||||
Of course there is more to learn - most of which you should be able to page-fault in as you go. Please see the ever-growing [Reference section](Readme.md#top) for what's available.
|
||||
|
||||
---
|
||||
|
||||
|
@@ -6,40 +6,53 @@ including (but not limited to),
|
||||
[Google Test](http://code.google.com/p/googletest/),
|
||||
[Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html),
|
||||
[CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page),
|
||||
[Cute](http://www.cute-test.com),
|
||||
[Cute](http://www.cute-test.com), and
|
||||
[many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B).
|
||||
|
||||
So what does Catch bring to the party that differentiates it from these? Apart from a Catchy name, of course.
|
||||
So what does Catch2 bring to the party that differentiates it from these? Apart from the catchy name, of course.
|
||||
|
||||
|
||||
## Key Features
|
||||
|
||||
* Quick and Really easy to get started. Just download catch.hpp, `#include` it and you're away.
|
||||
* No external dependencies. As long as you can compile C++11 and have a C++ standard library available.
|
||||
* Quick and easy to get started. Just download two files, add them into your project and you're away.
|
||||
* No external dependencies. As long as you can compile C++14 and have the C++ standard library available.
|
||||
* Write test cases as, self-registering, functions (or methods, if you prefer).
|
||||
* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures).
|
||||
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
|
||||
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
|
||||
* Tests are named using free-form strings - no more couching names in legal identifiers.
|
||||
|
||||
|
||||
## Other core features
|
||||
|
||||
* Tests can be tagged for easily running ad-hoc groups of tests.
|
||||
* Failures can (optionally) break into the debugger on Windows and Mac.
|
||||
* Failures can (optionally) break into the debugger on common platforms.
|
||||
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
|
||||
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
|
||||
* A default main() function is provided, but you can supply your own for complete control (e.g. integration into your own test runner GUI).
|
||||
* A command line parser is provided and can still be used if you choose to provided your own main() function.
|
||||
* Catch can test itself.
|
||||
* Alternative assertion macro(s) report failures but don't abort the test case
|
||||
* Floating point tolerance comparisons are built in using an expressive Approx() syntax.
|
||||
* Good set of facilities for floating point comparisons (`Catch::Approx` and full set of matchers)
|
||||
* Internal and friendly macros are isolated so name clashes can be managed
|
||||
* Matchers
|
||||
* Data generators (data driven test support)
|
||||
* Hamcrest-style Matchers for testing complex properties
|
||||
* Microbenchmarking support
|
||||
|
||||
## Who else is using Catch?
|
||||
|
||||
See the list of [open source projects using Catch](opensource-users.md#top).
|
||||
## Who else is using Catch2?
|
||||
|
||||
See the [tutorial](tutorial.md#top) to get more of a taste of using Catch in practice
|
||||
A whole lot of people. According to the 2021 Jetbrains C++ ecosystem survey,
|
||||
about 11% of C++ programmers use Catch2 for unit testing, making it the
|
||||
second most popular unit testing framework.
|
||||
|
||||
You can also take a look at the (incomplete) list of [open source projects](opensource-users.md#top)
|
||||
or the (very incomplete) list of [commercial users of Catch2](commercial-users.md#top)
|
||||
for some idea on who else also uses Catch2.
|
||||
|
||||
---
|
||||
|
||||
See the [tutorial](tutorial.md#top) to get more of a taste of using
|
||||
Catch2 in practice.
|
||||
|
||||
---
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
||||
#include <catch2/catch_reporter_registrars.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <iostream>
|
||||
|
||||
@@ -22,7 +22,7 @@ std::string ws(int const level) {
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Catch::Tag t) {
|
||||
return out << "original: " << t.original << "lower cased: " << t.lowerCased;
|
||||
return out << "original: " << t.original;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
@@ -366,10 +366,9 @@ struct MyListener : Catch::EventListenerBase {
|
||||
print( std::cout, 1, "- assertionInfo", assertionInfo );
|
||||
}
|
||||
|
||||
bool assertionEnded( Catch::AssertionStats const& assertionStats ) override {
|
||||
void assertionEnded( Catch::AssertionStats const& assertionStats ) override {
|
||||
std::cout << "\nEvent: assertionEnded:\n";
|
||||
print( std::cout, 1, "- assertionStats", assertionStats );
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -48,7 +48,7 @@ TEST_CASE("Table allows pre-computed test inputs and outputs", "[example][genera
|
||||
* (technically C++17 but does not require -std in GCC/Clang). See
|
||||
* https://stackoverflow.com/questions/12436586/tuple-vector-and-initializer-list
|
||||
*
|
||||
* - In C++17 mode std::tie() and the preceeding variable delcarations can be
|
||||
* - In C++17 mode std::tie() and the preceding variable delcarations can be
|
||||
* replaced by structured bindings: auto [test_input, expected] = GENERATE(
|
||||
* table<std::string, size_t>({ ...
|
||||
*/
|
||||
|
@@ -202,4 +202,5 @@ endfunction()
|
||||
|
||||
set(_CATCH_DISCOVER_TESTS_SCRIPT
|
||||
${CMAKE_CURRENT_LIST_DIR}/CatchAddTests.cmake
|
||||
CACHE INTERNAL "Catch2 full path to CatchAddTests.cmake helper file"
|
||||
)
|
||||
|
@@ -16,7 +16,10 @@ set(tests)
|
||||
|
||||
function(add_command NAME)
|
||||
set(_args "")
|
||||
foreach(_arg ${ARGN})
|
||||
# use ARGV* instead of ARGN, because ARGN splits arrays into multiple arguments
|
||||
math(EXPR _last_arg ${ARGC}-1)
|
||||
foreach(_n RANGE 1 ${_last_arg})
|
||||
set(_arg "${ARGV${_n}}")
|
||||
if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
|
||||
set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument
|
||||
else()
|
||||
@@ -55,11 +58,7 @@ execute_process(
|
||||
RESULT_VARIABLE reporters_result
|
||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||
)
|
||||
if(${reporters_result} EQUAL 0)
|
||||
message(WARNING
|
||||
"Test executable '${TEST_EXECUTABLE}' contains no reporters!\n"
|
||||
)
|
||||
elseif(${reporters_result} LESS 0)
|
||||
if(NOT ${reporters_result} EQUAL 0)
|
||||
message(FATAL_ERROR
|
||||
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
||||
" Result: ${reporters_result}\n"
|
||||
|
@@ -108,7 +108,8 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
|
||||
ParseAndAddCatchTests_RemoveComments(Contents)
|
||||
|
||||
# Find definition of test names
|
||||
string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*,[ \t\n]*\"[^\"]*\"([^\(\)]+(\\([^\)]*\\))*)*\\)+[ \t\n]*{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
|
||||
# https://regex101.com/r/JygOND/1
|
||||
string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
|
||||
|
||||
if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
|
||||
@@ -119,6 +120,14 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
|
||||
)
|
||||
endif()
|
||||
|
||||
# check CMP0110 policy for new add_test() behavior
|
||||
if(POLICY CMP0110)
|
||||
cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior
|
||||
else()
|
||||
# just to be thorough explicitly set the variable
|
||||
set(_cmp0110_value)
|
||||
endif()
|
||||
|
||||
foreach(TestName ${Tests})
|
||||
# Strip newlines
|
||||
string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
|
||||
@@ -191,16 +200,20 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
|
||||
# Escape commas in the test spec
|
||||
string(REPLACE "," "\\," Name ${Name})
|
||||
|
||||
# Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were neccessary,
|
||||
# Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were necessary,
|
||||
# only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1
|
||||
if(NOT ${CMAKE_VERSION} VERSION_EQUAL "3.18")
|
||||
# And properly introduced in 3.19 with the CMP0110 policy
|
||||
if(_cmp0110_value STREQUAL "NEW" OR ${CMAKE_VERSION} VERSION_EQUAL "3.18")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to NEW, no need for add_test(\"\") workaround")
|
||||
else()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to OLD adding \"\" for add_test() workaround")
|
||||
set(CTestName "\"${CTestName}\"")
|
||||
endif()
|
||||
|
||||
# Handle template test cases
|
||||
if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*")
|
||||
set(Name "${Name} - *")
|
||||
endif()
|
||||
# Handle template test cases
|
||||
if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*")
|
||||
set(Name "${Name} - *")
|
||||
endif()
|
||||
|
||||
# Add the test and set its properties
|
||||
add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
|
||||
@@ -228,6 +241,7 @@ endfunction()
|
||||
|
||||
# entry point
|
||||
function(ParseAndAddCatchTests TestTarget)
|
||||
message(DEPRECATION "ParseAndAddCatchTest: function deprecated because of possibility of missed test cases. Consider using 'catch_discover_tests' from 'Catch.cmake'")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}")
|
||||
get_target_property(SourceFiles ${TestTarget} SOURCES)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}")
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
9
mdsnippets.json
Normal file
9
mdsnippets.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ReadOnly": false,
|
||||
"TocLevel": 5,
|
||||
"Exclude": [
|
||||
"cmake-build"
|
||||
],
|
||||
"WriteHeader": false,
|
||||
"Convention": "InPlaceOverwrite"
|
||||
}
|
@@ -36,6 +36,7 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/generators/catch_generators_all.hpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_all.hpp
|
||||
${SOURCES_DIR}/matchers/internal/catch_matchers_impl.hpp
|
||||
${SOURCES_DIR}/internal/catch_case_insensitive_comparisons.hpp
|
||||
${SOURCES_DIR}/internal/catch_console_width.hpp
|
||||
${SOURCES_DIR}/internal/catch_container_nonmembers.hpp
|
||||
${SOURCES_DIR}/internal/catch_noncopyable.hpp
|
||||
@@ -44,13 +45,17 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/catch_assertion_info.hpp
|
||||
${SOURCES_DIR}/catch_assertion_result.hpp
|
||||
${SOURCES_DIR}/internal/catch_test_macro_impl.hpp
|
||||
${SOURCES_DIR}/internal/catch_test_failure_exception.hpp
|
||||
${SOURCES_DIR}/internal/catch_case_sensitive.hpp
|
||||
${SOURCES_DIR}/internal/catch_clara.hpp
|
||||
${SOURCES_DIR}/internal/catch_commandline.hpp
|
||||
${SOURCES_DIR}/internal/catch_common.hpp
|
||||
${SOURCES_DIR}/internal/catch_source_line_info.hpp
|
||||
${SOURCES_DIR}/internal/catch_compiler_capabilities.hpp
|
||||
${SOURCES_DIR}/catch_config.hpp
|
||||
${SOURCES_DIR}/internal/catch_config_android_logwrite.hpp
|
||||
${SOURCES_DIR}/internal/catch_config_counter.hpp
|
||||
${SOURCES_DIR}/internal/catch_config_uncaught_exceptions.hpp
|
||||
${SOURCES_DIR}/internal/catch_config_wchar.hpp
|
||||
${SOURCES_DIR}/internal/catch_console_colour.hpp
|
||||
${SOURCES_DIR}/internal/catch_context.hpp
|
||||
${SOURCES_DIR}/internal/catch_debug_console.hpp
|
||||
@@ -61,6 +66,9 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/internal/catch_errno_guard.hpp
|
||||
${SOURCES_DIR}/internal/catch_exception_translator_registry.hpp
|
||||
${SOURCES_DIR}/internal/catch_fatal_condition_handler.hpp
|
||||
${SOURCES_DIR}/internal/catch_floating_point_helpers.hpp
|
||||
${SOURCES_DIR}/internal/catch_unique_name.hpp
|
||||
${SOURCES_DIR}/internal/catch_sharding.hpp
|
||||
${SOURCES_DIR}/generators/catch_generator_exception.hpp
|
||||
${SOURCES_DIR}/generators/catch_generators.hpp
|
||||
${SOURCES_DIR}/generators/catch_generators_adapters.hpp
|
||||
@@ -75,7 +83,6 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.hpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_factory.hpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter_registry.hpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_runner.hpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_tag_alias_registry.hpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_testcase.hpp
|
||||
${SOURCES_DIR}/internal/catch_lazy_expr.hpp
|
||||
@@ -85,21 +92,24 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/matchers/catch_matchers_container_properties.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_contains.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_exception.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_floating.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_floating_point.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_predicate.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_quantifiers.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_string.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_templated.hpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_vector.hpp
|
||||
${SOURCES_DIR}/catch_message.hpp
|
||||
${SOURCES_DIR}/internal/catch_message_info.hpp
|
||||
${SOURCES_DIR}/internal/catch_meta.hpp
|
||||
${SOURCES_DIR}/internal/catch_option.hpp
|
||||
${SOURCES_DIR}/internal/catch_move_and_forward.hpp
|
||||
${SOURCES_DIR}/internal/catch_optional.hpp
|
||||
${SOURCES_DIR}/internal/catch_output_redirect.hpp
|
||||
${SOURCES_DIR}/internal/catch_platform.hpp
|
||||
${SOURCES_DIR}/internal/catch_polyfills.hpp
|
||||
${SOURCES_DIR}/internal/catch_preprocessor.hpp
|
||||
${SOURCES_DIR}/internal/catch_random_number_generator.hpp
|
||||
${SOURCES_DIR}/catch_reporter_registrars.hpp
|
||||
${SOURCES_DIR}/internal/catch_random_seed_generation.hpp
|
||||
${SOURCES_DIR}/reporters/catch_reporter_registrars.hpp
|
||||
${SOURCES_DIR}/internal/catch_reporter_registry.hpp
|
||||
${SOURCES_DIR}/internal/catch_result_type.hpp
|
||||
${SOURCES_DIR}/internal/catch_run_context.hpp
|
||||
@@ -109,6 +119,7 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/internal/catch_singletons.hpp
|
||||
${SOURCES_DIR}/internal/catch_startup_exception_registry.hpp
|
||||
${SOURCES_DIR}/internal/catch_stream.hpp
|
||||
${SOURCES_DIR}/internal/catch_stream_end_stop.hpp
|
||||
${SOURCES_DIR}/internal/catch_string_manip.hpp
|
||||
${SOURCES_DIR}/internal/catch_stringref.hpp
|
||||
${SOURCES_DIR}/catch_tag_alias.hpp
|
||||
@@ -131,6 +142,7 @@ set(INTERNAL_HEADERS
|
||||
${SOURCES_DIR}/catch_translate_exception.hpp
|
||||
${SOURCES_DIR}/internal/catch_uncaught_exceptions.hpp
|
||||
${SOURCES_DIR}/internal/catch_unique_ptr.hpp
|
||||
${SOURCES_DIR}/internal/catch_void_type.hpp
|
||||
${SOURCES_DIR}/catch_version.hpp
|
||||
${SOURCES_DIR}/catch_version_macros.hpp
|
||||
${SOURCES_DIR}/internal/catch_wildcard_pattern.hpp
|
||||
@@ -144,8 +156,9 @@ set(IMPL_SOURCES
|
||||
${SOURCES_DIR}/matchers/internal/catch_matchers_combined_tu.cpp
|
||||
${SOURCES_DIR}/internal/catch_clara.cpp
|
||||
${SOURCES_DIR}/internal/catch_commandline.cpp
|
||||
${SOURCES_DIR}/internal/catch_common.cpp
|
||||
${SOURCES_DIR}/internal/catch_source_line_info.cpp
|
||||
${SOURCES_DIR}/catch_config.cpp
|
||||
${SOURCES_DIR}/internal/catch_case_insensitive_comparisons.cpp
|
||||
${SOURCES_DIR}/internal/catch_console_colour.cpp
|
||||
${SOURCES_DIR}/internal/catch_context.cpp
|
||||
${SOURCES_DIR}/internal/catch_debug_console.cpp
|
||||
@@ -154,11 +167,12 @@ set(IMPL_SOURCES
|
||||
${SOURCES_DIR}/internal/catch_enum_values_registry.cpp
|
||||
${SOURCES_DIR}/internal/catch_exception_translator_registry.cpp
|
||||
${SOURCES_DIR}/internal/catch_fatal_condition_handler.cpp
|
||||
${SOURCES_DIR}/internal/catch_floating_point_helpers.cpp
|
||||
${SOURCES_DIR}/generators/internal/catch_generators_combined_tu.cpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_combined_tu.cpp
|
||||
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.cpp
|
||||
${SOURCES_DIR}/internal/catch_list.cpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_floating.cpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_floating_point.cpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_string.cpp
|
||||
${SOURCES_DIR}/matchers/catch_matchers_templated.cpp
|
||||
${SOURCES_DIR}/catch_message.cpp
|
||||
@@ -166,6 +180,7 @@ set(IMPL_SOURCES
|
||||
${SOURCES_DIR}/catch_registry_hub.cpp
|
||||
${SOURCES_DIR}/internal/catch_combined_tu.cpp
|
||||
${SOURCES_DIR}/internal/catch_random_number_generator.cpp
|
||||
${SOURCES_DIR}/internal/catch_random_seed_generation.cpp
|
||||
${SOURCES_DIR}/internal/catch_reporter_registry.cpp
|
||||
${SOURCES_DIR}/internal/catch_result_type.cpp
|
||||
${SOURCES_DIR}/internal/catch_run_context.cpp
|
||||
@@ -233,12 +248,15 @@ add_library(Catch2 STATIC
|
||||
${BENCHMARK_HEADERS}
|
||||
${BENCHMARK_SOURCES}
|
||||
)
|
||||
add_build_reproducibility_settings(Catch2)
|
||||
add_library(Catch2::Catch2 ALIAS Catch2)
|
||||
|
||||
if (ANDROID)
|
||||
target_link_libraries(Catch2 INTERFACE log)
|
||||
endif()
|
||||
|
||||
set_target_properties(Catch2 PROPERTIES DEBUG_POSTFIX "d")
|
||||
|
||||
# depend on bunch of C++11 and C++14 features to have C++14 enabled by default
|
||||
target_compile_features(Catch2
|
||||
PUBLIC
|
||||
@@ -274,12 +292,14 @@ target_include_directories(Catch2
|
||||
add_library(Catch2WithMain STATIC
|
||||
${SOURCES_DIR}/internal/catch_main.cpp
|
||||
)
|
||||
add_build_reproducibility_settings(Catch2WithMain)
|
||||
add_library(Catch2::Catch2WithMain ALIAS Catch2WithMain)
|
||||
target_link_libraries(Catch2WithMain PUBLIC Catch2)
|
||||
set_target_properties(Catch2WithMain
|
||||
PROPERTIES
|
||||
OUTPUT_NAME "Catch2Main"
|
||||
)
|
||||
set_target_properties(Catch2WithMain PROPERTIES DEBUG_POSTFIX "d")
|
||||
|
||||
if (NOT_SUBPROJECT)
|
||||
# create and install an export set for catch target as Catch2::Catch
|
||||
|
@@ -11,9 +11,11 @@
|
||||
#define CATCH_BENCHMARK_HPP_INCLUDED
|
||||
|
||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_context.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
|
||||
#include <catch2/internal/catch_unique_name.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
#include <catch2/benchmark/catch_chronometer.hpp>
|
||||
#include <catch2/benchmark/catch_clock.hpp>
|
||||
#include <catch2/benchmark/catch_environment.hpp>
|
||||
@@ -34,11 +36,11 @@ namespace Catch {
|
||||
namespace Benchmark {
|
||||
struct Benchmark {
|
||||
Benchmark(std::string&& benchmarkName)
|
||||
: name(std::move(benchmarkName)) {}
|
||||
: name(CATCH_MOVE(benchmarkName)) {}
|
||||
|
||||
template <class FUN>
|
||||
Benchmark(std::string&& benchmarkName , FUN &&func)
|
||||
: fun(std::move(func)), name(std::move(benchmarkName)) {}
|
||||
: fun(CATCH_MOVE(func)), name(CATCH_MOVE(benchmarkName)) {}
|
||||
|
||||
template <typename Clock>
|
||||
ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
|
||||
@@ -80,16 +82,18 @@ namespace Catch {
|
||||
auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end());
|
||||
BenchmarkStats<FloatDuration<Clock>> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
|
||||
getResultCapture().benchmarkEnded(stats);
|
||||
|
||||
} CATCH_CATCH_ANON (TestFailureException) {
|
||||
getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr);
|
||||
} CATCH_CATCH_ALL{
|
||||
if (translateActiveException() != Detail::benchmarkErrorMsg) // benchmark errors have been reported, otherwise rethrow.
|
||||
std::rethrow_exception(std::current_exception());
|
||||
getResultCapture().benchmarkFailed(translateActiveException());
|
||||
// We let the exception go further up so that the
|
||||
// test case is marked as failed.
|
||||
std::rethrow_exception(std::current_exception());
|
||||
}
|
||||
}
|
||||
|
||||
// sets lambda to be used in fun *and* executes benchmark!
|
||||
template <typename Fun,
|
||||
typename std::enable_if<!Detail::is_related<Fun, Benchmark>::value, int>::type = 0>
|
||||
template <typename Fun, std::enable_if_t<!Detail::is_related<Fun, Benchmark>::value, int> = 0>
|
||||
Benchmark & operator=(Fun func) {
|
||||
fun = Detail::BenchmarkFunction(func);
|
||||
run();
|
||||
@@ -121,16 +125,16 @@ namespace Catch {
|
||||
#if defined(CATCH_CONFIG_PREFIX_ALL)
|
||||
|
||||
#define CATCH_BENCHMARK(...) \
|
||||
INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
|
||||
INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
|
||||
#define CATCH_BENCHMARK_ADVANCED(name) \
|
||||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name)
|
||||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name)
|
||||
|
||||
#else
|
||||
|
||||
#define BENCHMARK(...) \
|
||||
INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
|
||||
INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
|
||||
#define BENCHMARK_ADVANCED(name) \
|
||||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name)
|
||||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name)
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include <catch2/benchmark/catch_optimizer.hpp>
|
||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
||||
#include <catch2/internal/catch_meta.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
@@ -42,7 +43,7 @@ namespace Catch {
|
||||
struct Chronometer {
|
||||
public:
|
||||
template <typename Fun>
|
||||
void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(int)>()); }
|
||||
void measure(Fun&& fun) { measure(CATCH_FORWARD(fun), is_callable<Fun(int)>()); }
|
||||
|
||||
int runs() const { return repeats; }
|
||||
|
||||
|
@@ -10,6 +10,8 @@
|
||||
#ifndef CATCH_CONSTRUCTOR_HPP_INCLUDED
|
||||
#define CATCH_CONSTRUCTOR_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace Catch {
|
||||
@@ -18,7 +20,7 @@ namespace Catch {
|
||||
template <typename T, bool Destruct>
|
||||
struct ObjectStorage
|
||||
{
|
||||
using TStorage = typename std::aligned_storage<sizeof(T), std::alignment_of<T>::value>::type;
|
||||
using TStorage = std::aligned_storage_t<sizeof(T), std::alignment_of<T>::value>;
|
||||
|
||||
ObjectStorage() : data() {}
|
||||
|
||||
@@ -29,7 +31,7 @@ namespace Catch {
|
||||
|
||||
ObjectStorage(ObjectStorage&& other)
|
||||
{
|
||||
new(&data) T(std::move(other.stored_object()));
|
||||
new(&data) T(CATCH_MOVE(other.stored_object()));
|
||||
}
|
||||
|
||||
~ObjectStorage() { destruct_on_exit<T>(); }
|
||||
@@ -37,11 +39,11 @@ namespace Catch {
|
||||
template <typename... Args>
|
||||
void construct(Args&&... args)
|
||||
{
|
||||
new (&data) T(std::forward<Args>(args)...);
|
||||
new (&data) T(CATCH_FORWARD(args)...);
|
||||
}
|
||||
|
||||
template <bool AllowManualDestruction = !Destruct>
|
||||
typename std::enable_if<AllowManualDestruction>::type destruct()
|
||||
std::enable_if_t<AllowManualDestruction> destruct()
|
||||
{
|
||||
stored_object().~T();
|
||||
}
|
||||
@@ -49,10 +51,10 @@ namespace Catch {
|
||||
private:
|
||||
// If this is a constructor benchmark, destruct the underlying object
|
||||
template <typename U>
|
||||
void destruct_on_exit(typename std::enable_if<Destruct, U>::type* = 0) { destruct<true>(); }
|
||||
void destruct_on_exit(std::enable_if_t<Destruct, U>* = 0) { destruct<true>(); }
|
||||
// Otherwise, don't
|
||||
template <typename U>
|
||||
void destruct_on_exit(typename std::enable_if<!Destruct, U>::type* = 0) { }
|
||||
void destruct_on_exit(std::enable_if_t<!Destruct, U>* = 0) { }
|
||||
|
||||
T& stored_object() {
|
||||
return *static_cast<T*>(static_cast<void*>(&data));
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
|
@@ -14,8 +14,9 @@
|
||||
# include <atomic> // atomic_thread_fence
|
||||
#endif
|
||||
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
@@ -56,13 +57,13 @@ namespace Catch {
|
||||
}
|
||||
|
||||
template <typename Fn, typename... Args>
|
||||
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<!std::is_same<void, decltype(fn(args...))>::value>::type {
|
||||
deoptimize_value(std::forward<Fn>(fn) (std::forward<Args...>(args...)));
|
||||
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same<void, decltype(fn(args...))>::value> {
|
||||
deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...));
|
||||
}
|
||||
|
||||
template <typename Fn, typename... Args>
|
||||
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> typename std::enable_if<std::is_same<void, decltype(fn(args...))>::value>::type {
|
||||
std::forward<Fn>(fn) (std::forward<Args...>(args...));
|
||||
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same<void, decltype(fn(args...))>::value> {
|
||||
CATCH_FORWARD(fn) (CATCH_FORWARD(args)...);
|
||||
}
|
||||
} // namespace Benchmark
|
||||
} // namespace Catch
|
||||
|
@@ -13,10 +13,10 @@
|
||||
#include <catch2/benchmark/catch_clock.hpp>
|
||||
#include <catch2/benchmark/catch_estimate.hpp>
|
||||
#include <catch2/benchmark/catch_outlier_classification.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
|
||||
namespace Catch {
|
||||
@@ -35,7 +35,7 @@ namespace Catch {
|
||||
samples2.reserve(samples.size());
|
||||
std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
|
||||
return {
|
||||
std::move(samples2),
|
||||
CATCH_MOVE(samples2),
|
||||
mean,
|
||||
standard_deviation,
|
||||
outliers,
|
||||
|
@@ -11,8 +11,11 @@
|
||||
#define CATCH_ANALYSE_HPP_INCLUDED
|
||||
|
||||
#include <catch2/benchmark/catch_clock.hpp>
|
||||
#include <catch2/benchmark/catch_environment.hpp>
|
||||
#include <catch2/benchmark/catch_sample_analysis.hpp>
|
||||
#include <catch2/benchmark/detail/catch_stats.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
@@ -25,7 +28,7 @@ namespace Catch {
|
||||
SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) {
|
||||
if (!cfg.benchmarkNoAnalysis()) {
|
||||
std::vector<double> samples;
|
||||
samples.reserve(last - first);
|
||||
samples.reserve(static_cast<size_t>(last - first));
|
||||
std::transform(first, last, std::back_inserter(samples), [](Duration d) { return d.count(); });
|
||||
|
||||
auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end());
|
||||
@@ -43,15 +46,15 @@ namespace Catch {
|
||||
samples2.reserve(samples.size());
|
||||
std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](double d) { return Duration(d); });
|
||||
return {
|
||||
std::move(samples2),
|
||||
CATCH_MOVE(samples2),
|
||||
wrap_estimate(analysis.mean),
|
||||
wrap_estimate(analysis.standard_deviation),
|
||||
outliers,
|
||||
analysis.outlier_variance,
|
||||
};
|
||||
} else {
|
||||
std::vector<Duration> samples;
|
||||
samples.reserve(last - first);
|
||||
std::vector<Duration> samples;
|
||||
samples.reserve(static_cast<size_t>(last - first));
|
||||
|
||||
Duration mean = Duration(0);
|
||||
int i = 0;
|
||||
@@ -62,7 +65,7 @@ namespace Catch {
|
||||
mean /= i;
|
||||
|
||||
return {
|
||||
std::move(samples),
|
||||
CATCH_MOVE(samples),
|
||||
Estimate<Duration>{mean, mean, mean, 0.0},
|
||||
Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0},
|
||||
OutlierClassification{},
|
||||
|
@@ -14,19 +14,16 @@
|
||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
||||
#include <catch2/internal/catch_meta.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
namespace Detail {
|
||||
template <typename T>
|
||||
using Decay = typename std::decay<T>::type;
|
||||
template <typename T, typename U>
|
||||
struct is_related
|
||||
: std::is_same<Decay<T>, Decay<U>> {};
|
||||
: std::is_same<std::decay_t<T>, std::decay_t<U>> {};
|
||||
|
||||
/// We need to reinvent std::function because every piece of code that might add overhead
|
||||
/// in a measurement context needs to have consistent performance characteristics so that we
|
||||
@@ -39,7 +36,7 @@ namespace Catch {
|
||||
private:
|
||||
struct callable {
|
||||
virtual void call(Chronometer meter) const = 0;
|
||||
virtual callable* clone() const = 0;
|
||||
virtual Catch::Detail::unique_ptr<callable> clone() const = 0;
|
||||
virtual ~callable(); // = default;
|
||||
|
||||
callable() = default;
|
||||
@@ -48,10 +45,12 @@ namespace Catch {
|
||||
};
|
||||
template <typename Fun>
|
||||
struct model : public callable {
|
||||
model(Fun&& fun_) : fun(std::move(fun_)) {}
|
||||
model(Fun&& fun_) : fun(CATCH_MOVE(fun_)) {}
|
||||
model(Fun const& fun_) : fun(fun_) {}
|
||||
|
||||
model<Fun>* clone() const override { return new model<Fun>(*this); }
|
||||
Catch::Detail::unique_ptr<callable> clone() const override {
|
||||
return Catch::Detail::make_unique<model<Fun>>( *this );
|
||||
}
|
||||
|
||||
void call(Chronometer meter) const override {
|
||||
call(meter, is_callable<Fun(Chronometer)>());
|
||||
@@ -76,24 +75,24 @@ namespace Catch {
|
||||
: f(new model<do_nothing>{ {} }) {}
|
||||
|
||||
template <typename Fun,
|
||||
typename std::enable_if<!is_related<Fun, BenchmarkFunction>::value, int>::type = 0>
|
||||
std::enable_if_t<!is_related<Fun, BenchmarkFunction>::value, int> = 0>
|
||||
BenchmarkFunction(Fun&& fun)
|
||||
: f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
|
||||
: f(new model<std::decay_t<Fun>>(CATCH_FORWARD(fun))) {}
|
||||
|
||||
BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
|
||||
f( std::move( that.f ) ) {}
|
||||
f( CATCH_MOVE( that.f ) ) {}
|
||||
|
||||
BenchmarkFunction(BenchmarkFunction const& that)
|
||||
: f(that.f->clone()) {}
|
||||
|
||||
BenchmarkFunction&
|
||||
operator=( BenchmarkFunction&& that ) noexcept {
|
||||
f = std::move( that.f );
|
||||
f = CATCH_MOVE( that.f );
|
||||
return *this;
|
||||
}
|
||||
|
||||
BenchmarkFunction& operator=(BenchmarkFunction const& that) {
|
||||
f.reset(that.f->clone());
|
||||
f = that.f->clone();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@@ -10,13 +10,13 @@
|
||||
#ifndef CATCH_COMPLETE_INVOKE_HPP_INCLUDED
|
||||
#define CATCH_COMPLETE_INVOKE_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
#include <catch2/internal/catch_test_failure_exception.hpp>
|
||||
#include <catch2/internal/catch_meta.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
@@ -33,14 +33,14 @@ namespace Catch {
|
||||
struct CompleteInvoker {
|
||||
template <typename Fun, typename... Args>
|
||||
static Result invoke(Fun&& fun, Args&&... args) {
|
||||
return std::forward<Fun>(fun)(std::forward<Args>(args)...);
|
||||
return CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct CompleteInvoker<void> {
|
||||
template <typename Fun, typename... Args>
|
||||
static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) {
|
||||
std::forward<Fun>(fun)(std::forward<Args>(args)...);
|
||||
CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
|
||||
return {};
|
||||
}
|
||||
};
|
||||
@@ -48,20 +48,14 @@ namespace Catch {
|
||||
// invoke and not return void :(
|
||||
template <typename Fun, typename... Args>
|
||||
CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) {
|
||||
return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
|
||||
return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...);
|
||||
}
|
||||
|
||||
extern const std::string benchmarkErrorMsg;
|
||||
} // namespace Detail
|
||||
|
||||
template <typename Fun>
|
||||
Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) {
|
||||
CATCH_TRY{
|
||||
return Detail::complete_invoke(std::forward<Fun>(fun));
|
||||
} CATCH_CATCH_ALL{
|
||||
getResultCapture().benchmarkFailed(translateActiveException());
|
||||
CATCH_RUNTIME_ERROR(Detail::benchmarkErrorMsg);
|
||||
}
|
||||
return Detail::complete_invoke(CATCH_FORWARD(fun));
|
||||
}
|
||||
} // namespace Benchmark
|
||||
} // namespace Catch
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <catch2/benchmark/detail/catch_measure.hpp>
|
||||
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp>
|
||||
#include <catch2/benchmark/catch_clock.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
@@ -28,11 +29,11 @@ namespace Catch {
|
||||
template <typename Clock>
|
||||
std::vector<double> resolution(int k) {
|
||||
std::vector<TimePoint<Clock>> times;
|
||||
times.reserve(k + 1);
|
||||
times.reserve(static_cast<size_t>(k + 1));
|
||||
std::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
|
||||
|
||||
std::vector<double> deltas;
|
||||
deltas.reserve(k);
|
||||
deltas.reserve(static_cast<size_t>(k));
|
||||
std::transform(std::next(times.begin()), times.end(), times.begin(),
|
||||
std::back_inserter(deltas),
|
||||
[](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); });
|
||||
@@ -66,7 +67,9 @@ namespace Catch {
|
||||
}
|
||||
template <typename Clock>
|
||||
EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) {
|
||||
auto time_limit = std::min(resolution * clock_cost_estimation_tick_limit, FloatDuration<Clock>(clock_cost_estimation_time_limit));
|
||||
auto time_limit = (std::min)(
|
||||
resolution * clock_cost_estimation_tick_limit,
|
||||
FloatDuration<Clock>(clock_cost_estimation_time_limit));
|
||||
auto time_clock = [](int k) {
|
||||
return Detail::measure<Clock>([k] {
|
||||
for (int i = 0; i < k; ++i) {
|
||||
@@ -80,7 +83,7 @@ namespace Catch {
|
||||
auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
|
||||
std::vector<double> times;
|
||||
int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
|
||||
times.reserve(nsamples);
|
||||
times.reserve(static_cast<size_t>(nsamples));
|
||||
std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
|
||||
return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
|
||||
});
|
||||
@@ -92,7 +95,14 @@ namespace Catch {
|
||||
|
||||
template <typename Clock>
|
||||
Environment<FloatDuration<Clock>> measure_environment() {
|
||||
static Environment<FloatDuration<Clock>>* env = nullptr;
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
#endif
|
||||
static Catch::Detail::unique_ptr<Environment<FloatDuration<Clock>>> env;
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
if (env) {
|
||||
return *env;
|
||||
}
|
||||
@@ -101,7 +111,7 @@ namespace Catch {
|
||||
auto resolution = Detail::estimate_clock_resolution<Clock>(iters);
|
||||
auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean);
|
||||
|
||||
env = new Environment<FloatDuration<Clock>>{ resolution, cost };
|
||||
env = Catch::Detail::make_unique<Environment<FloatDuration<Clock>>>( Environment<FloatDuration<Clock>>{resolution, cost} );
|
||||
return *env;
|
||||
}
|
||||
} // namespace Detail
|
||||
|
@@ -13,8 +13,7 @@
|
||||
#include <catch2/benchmark/catch_clock.hpp>
|
||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
||||
#include <catch2/benchmark/detail/catch_timing.hpp>
|
||||
|
||||
#include <utility>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
@@ -22,10 +21,10 @@ namespace Catch {
|
||||
template <typename Clock, typename Fun, typename... Args>
|
||||
TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) {
|
||||
auto start = Clock::now();
|
||||
auto&& r = Detail::complete_invoke(fun, std::forward<Args>(args)...);
|
||||
auto&& r = Detail::complete_invoke(fun, CATCH_FORWARD(args)...);
|
||||
auto end = Clock::now();
|
||||
auto delta = end - start;
|
||||
return { delta, std::forward<decltype(r)>(r), 1 };
|
||||
return { delta, CATCH_FORWARD(r), 1 };
|
||||
}
|
||||
} // namespace Detail
|
||||
} // namespace Benchmark
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#define CATCH_REPEAT_HPP_INCLUDED
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
@@ -26,8 +26,8 @@ namespace Catch {
|
||||
Fun fun;
|
||||
};
|
||||
template <typename Fun>
|
||||
repeater<typename std::decay<Fun>::type> repeat(Fun&& fun) {
|
||||
return { std::forward<Fun>(fun) };
|
||||
repeater<std::decay_t<Fun>> repeat(Fun&& fun) {
|
||||
return { CATCH_FORWARD(fun) };
|
||||
}
|
||||
} // namespace Detail
|
||||
} // namespace Benchmark
|
||||
|
@@ -16,8 +16,8 @@
|
||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
||||
#include <catch2/benchmark/detail/catch_timing.hpp>
|
||||
#include <catch2/internal/catch_meta.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Catch {
|
||||
@@ -32,24 +32,27 @@ namespace Catch {
|
||||
Detail::ChronometerModel<Clock> meter;
|
||||
auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters));
|
||||
|
||||
return { meter.elapsed(), std::move(result), iters };
|
||||
return { meter.elapsed(), CATCH_MOVE(result), iters };
|
||||
}
|
||||
|
||||
template <typename Clock, typename Fun>
|
||||
using run_for_at_least_argument_t = typename std::conditional<is_callable<Fun(Chronometer)>::value, Chronometer, int>::type;
|
||||
using run_for_at_least_argument_t = std::conditional_t<is_callable<Fun(Chronometer)>::value, Chronometer, int>;
|
||||
|
||||
|
||||
[[noreturn]]
|
||||
void throw_optimized_away_error();
|
||||
|
||||
template <typename Clock, typename Fun>
|
||||
TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>> run_for_at_least(ClockDuration<Clock> how_long, int seed, Fun&& fun) {
|
||||
auto iters = seed;
|
||||
TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>>
|
||||
run_for_at_least(ClockDuration<Clock> how_long,
|
||||
const int initial_iterations,
|
||||
Fun&& fun) {
|
||||
auto iters = initial_iterations;
|
||||
while (iters < (1 << 30)) {
|
||||
auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>());
|
||||
|
||||
if (Timing.elapsed >= how_long) {
|
||||
return { Timing.elapsed, std::move(Timing.result), iters };
|
||||
return { Timing.elapsed, CATCH_MOVE(Timing.result), iters };
|
||||
}
|
||||
iters *= 2;
|
||||
}
|
||||
|
@@ -25,8 +25,8 @@ namespace {
|
||||
using Catch::Benchmark::Detail::sample;
|
||||
|
||||
template <typename URng, typename Estimator>
|
||||
sample resample(URng& rng, int resamples, std::vector<double>::iterator first, std::vector<double>::iterator last, Estimator& estimator) {
|
||||
auto n = last - first;
|
||||
sample resample(URng& rng, unsigned int resamples, std::vector<double>::iterator first, std::vector<double>::iterator last, Estimator& estimator) {
|
||||
auto n = static_cast<size_t>(last - first);
|
||||
std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
|
||||
|
||||
sample out;
|
||||
@@ -34,7 +34,7 @@ using Catch::Benchmark::Detail::sample;
|
||||
std::generate_n(std::back_inserter(out), resamples, [n, first, &estimator, &dist, &rng] {
|
||||
std::vector<double> resampled;
|
||||
resampled.reserve(n);
|
||||
std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[dist(rng)]; });
|
||||
std::generate_n(std::back_inserter(resampled), n, [first, &dist, &rng] { return first[static_cast<std::ptrdiff_t>(dist(rng))]; });
|
||||
return estimator(resampled.begin(), resampled.end());
|
||||
});
|
||||
std::sort(out.begin(), out.end());
|
||||
@@ -171,7 +171,7 @@ namespace Catch {
|
||||
double sb = stddev.point;
|
||||
double mn = mean.point / n;
|
||||
double mg_min = mn / 2.;
|
||||
double sg = std::min(mg_min / 4., sb / std::sqrt(n));
|
||||
double sg = (std::min)(mg_min / 4., sb / std::sqrt(n));
|
||||
double sg2 = sg * sg;
|
||||
double sb2 = sb * sb;
|
||||
|
||||
@@ -182,7 +182,7 @@ namespace Catch {
|
||||
double k0 = -n * nd;
|
||||
double k1 = sb2 - n * sg2 + nd;
|
||||
double det = k1 * k1 - 4 * sg2 * k0;
|
||||
return (int)(-2. * k0 / (k1 + std::sqrt(det)));
|
||||
return static_cast<int>(-2. * k0 / (k1 + std::sqrt(det)));
|
||||
};
|
||||
|
||||
auto var_out = [n, sb2, sg2](double c) {
|
||||
@@ -190,11 +190,11 @@ namespace Catch {
|
||||
return (nc / n) * (sb2 - nc * sg2);
|
||||
};
|
||||
|
||||
return std::min(var_out(1), var_out(std::min(c_max(0.), c_max(mg_min)))) / sb2;
|
||||
return (std::min)(var_out(1), var_out((std::min)(c_max(0.), c_max(mg_min)))) / sb2;
|
||||
}
|
||||
|
||||
|
||||
bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
|
||||
bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
|
||||
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
|
||||
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
|
||||
static std::random_device entropy;
|
||||
|
@@ -18,7 +18,6 @@
|
||||
#include <numeric>
|
||||
#include <tuple>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
@@ -60,7 +59,7 @@ namespace Catch {
|
||||
|
||||
template <typename Estimator, typename Iterator>
|
||||
sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
|
||||
auto n = last - first;
|
||||
auto n = static_cast<size_t>(last - first);
|
||||
auto second = first;
|
||||
++second;
|
||||
sample results;
|
||||
@@ -102,7 +101,7 @@ namespace Catch {
|
||||
|
||||
double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
|
||||
int n = static_cast<int>(resample.size());
|
||||
double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / (double)n;
|
||||
double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n);
|
||||
// degenerate case with uniform samples
|
||||
if (prob_n == 0) return { point, point, point, confidence_level };
|
||||
|
||||
@@ -116,8 +115,8 @@ namespace Catch {
|
||||
double b2 = bias - z1;
|
||||
double a1 = a(b1);
|
||||
double a2 = a(b2);
|
||||
auto lo = std::max(cumn(a1), 0);
|
||||
auto hi = std::min(cumn(a2), n - 1);
|
||||
auto lo = static_cast<size_t>((std::max)(cumn(a1), 0));
|
||||
auto hi = static_cast<size_t>((std::min)(cumn(a2), n - 1));
|
||||
|
||||
return { point, resample[lo], resample[hi], confidence_level };
|
||||
}
|
||||
@@ -130,7 +129,7 @@ namespace Catch {
|
||||
double outlier_variance;
|
||||
};
|
||||
|
||||
bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
|
||||
bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
|
||||
} // namespace Detail
|
||||
} // namespace Benchmark
|
||||
} // namespace Catch
|
||||
|
@@ -47,26 +47,6 @@ namespace Catch {
|
||||
} // namespace Catch
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// vvv formerly catch_complete_invoke.cpp vvv //
|
||||
////////////////////////////////////////////////
|
||||
|
||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
||||
|
||||
namespace Catch {
|
||||
namespace Benchmark {
|
||||
namespace Detail {
|
||||
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
|
||||
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
|
||||
const std::string benchmarkErrorMsg = "a benchmark failed to run successfully";
|
||||
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
|
||||
} // namespace Detail
|
||||
} // namespace Benchmark
|
||||
} // namespace Catch
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// vvv formerly catch_run_for_at_least.cpp vvv //
|
||||
/////////////////////////////////////////////////
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include <catch2/catch_assertion_result.hpp>
|
||||
#include <catch2/catch_config.hpp>
|
||||
#include <catch2/catch_message.hpp>
|
||||
#include <catch2/catch_reporter_registrars.hpp>
|
||||
#include <catch2/catch_section_info.hpp>
|
||||
#include <catch2/catch_session.hpp>
|
||||
#include <catch2/catch_tag_alias.hpp>
|
||||
@@ -46,12 +45,15 @@
|
||||
#include <catch2/generators/catch_generators_all.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_all.hpp>
|
||||
#include <catch2/internal/catch_assertion_handler.hpp>
|
||||
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
|
||||
#include <catch2/internal/catch_case_sensitive.hpp>
|
||||
#include <catch2/internal/catch_clara.hpp>
|
||||
#include <catch2/internal/catch_commandline.hpp>
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_config_android_logwrite.hpp>
|
||||
#include <catch2/internal/catch_config_counter.hpp>
|
||||
#include <catch2/internal/catch_config_uncaught_exceptions.hpp>
|
||||
#include <catch2/internal/catch_config_wchar.hpp>
|
||||
#include <catch2/internal/catch_console_colour.hpp>
|
||||
#include <catch2/internal/catch_console_width.hpp>
|
||||
#include <catch2/internal/catch_container_nonmembers.hpp>
|
||||
@@ -64,38 +66,47 @@
|
||||
#include <catch2/internal/catch_errno_guard.hpp>
|
||||
#include <catch2/internal/catch_exception_translator_registry.hpp>
|
||||
#include <catch2/internal/catch_fatal_condition_handler.hpp>
|
||||
#include <catch2/internal/catch_floating_point_helpers.hpp>
|
||||
#include <catch2/internal/catch_lazy_expr.hpp>
|
||||
#include <catch2/internal/catch_leak_detector.hpp>
|
||||
#include <catch2/internal/catch_list.hpp>
|
||||
#include <catch2/internal/catch_message_info.hpp>
|
||||
#include <catch2/internal/catch_meta.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
#include <catch2/internal/catch_noncopyable.hpp>
|
||||
#include <catch2/internal/catch_option.hpp>
|
||||
#include <catch2/internal/catch_optional.hpp>
|
||||
#include <catch2/internal/catch_output_redirect.hpp>
|
||||
#include <catch2/internal/catch_platform.hpp>
|
||||
#include <catch2/internal/catch_polyfills.hpp>
|
||||
#include <catch2/internal/catch_preprocessor.hpp>
|
||||
#include <catch2/internal/catch_random_number_generator.hpp>
|
||||
#include <catch2/internal/catch_random_seed_generation.hpp>
|
||||
#include <catch2/internal/catch_reporter_registry.hpp>
|
||||
#include <catch2/internal/catch_result_type.hpp>
|
||||
#include <catch2/internal/catch_run_context.hpp>
|
||||
#include <catch2/internal/catch_section.hpp>
|
||||
#include <catch2/internal/catch_sharding.hpp>
|
||||
#include <catch2/internal/catch_singletons.hpp>
|
||||
#include <catch2/internal/catch_source_line_info.hpp>
|
||||
#include <catch2/internal/catch_startup_exception_registry.hpp>
|
||||
#include <catch2/internal/catch_stream.hpp>
|
||||
#include <catch2/internal/catch_stream_end_stop.hpp>
|
||||
#include <catch2/internal/catch_string_manip.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
#include <catch2/internal/catch_tag_alias_registry.hpp>
|
||||
#include <catch2/internal/catch_template_test_registry.hpp>
|
||||
#include <catch2/internal/catch_test_case_registry_impl.hpp>
|
||||
#include <catch2/internal/catch_test_case_tracker.hpp>
|
||||
#include <catch2/internal/catch_test_failure_exception.hpp>
|
||||
#include <catch2/internal/catch_test_macro_impl.hpp>
|
||||
#include <catch2/internal/catch_test_registry.hpp>
|
||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||
#include <catch2/internal/catch_textflow.hpp>
|
||||
#include <catch2/internal/catch_to_string.hpp>
|
||||
#include <catch2/internal/catch_uncaught_exceptions.hpp>
|
||||
#include <catch2/internal/catch_unique_name.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
#include <catch2/internal/catch_void_type.hpp>
|
||||
#include <catch2/internal/catch_wildcard_pattern.hpp>
|
||||
#include <catch2/internal/catch_windows_h_proxy.hpp>
|
||||
#include <catch2/internal/catch_xmlwriter.hpp>
|
||||
|
@@ -24,7 +24,7 @@ bool marginComparison(double lhs, double rhs, double margin) {
|
||||
namespace Catch {
|
||||
|
||||
Approx::Approx ( double value )
|
||||
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
|
||||
: m_epsilon( std::numeric_limits<float>::epsilon()*100. ),
|
||||
m_margin( 0.0 ),
|
||||
m_scale( 0.0 ),
|
||||
m_value( value )
|
||||
|
@@ -30,7 +30,7 @@ namespace Catch {
|
||||
Approx operator-() const;
|
||||
|
||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
||||
Approx operator()( T const& value ) {
|
||||
Approx operator()( T const& value ) const {
|
||||
Approx approx( static_cast<double>(value) );
|
||||
approx.m_epsilon = m_epsilon;
|
||||
approx.m_margin = m_margin;
|
||||
@@ -114,8 +114,8 @@ namespace Catch {
|
||||
};
|
||||
|
||||
namespace literals {
|
||||
Approx operator "" _a(long double val);
|
||||
Approx operator "" _a(unsigned long long val);
|
||||
Approx operator ""_a(long double val);
|
||||
Approx operator ""_a(unsigned long long val);
|
||||
} // end namespace literals
|
||||
|
||||
template<>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
#define CATCH_ASSERTION_INFO_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_result_type.hpp>
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_source_line_info.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
|
||||
namespace Catch {
|
||||
|
@@ -91,7 +91,7 @@ namespace Catch {
|
||||
: expr;
|
||||
}
|
||||
|
||||
std::string AssertionResult::getMessage() const {
|
||||
StringRef AssertionResult::getMessage() const {
|
||||
return m_resultData.message;
|
||||
}
|
||||
SourceLineInfo AssertionResult::getSourceInfo() const {
|
||||
|
@@ -8,13 +8,14 @@
|
||||
#ifndef CATCH_ASSERTION_RESULT_HPP_INCLUDED
|
||||
#define CATCH_ASSERTION_RESULT_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <catch2/catch_assertion_info.hpp>
|
||||
#include <catch2/internal/catch_result_type.hpp>
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_source_line_info.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
#include <catch2/internal/catch_lazy_expr.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct AssertionResultData
|
||||
@@ -45,7 +46,7 @@ namespace Catch {
|
||||
std::string getExpressionInMacro() const;
|
||||
bool hasExpandedExpression() const;
|
||||
std::string getExpandedExpression() const;
|
||||
std::string getMessage() const;
|
||||
StringRef getMessage() const;
|
||||
SourceLineInfo getSourceInfo() const;
|
||||
StringRef getTestMacroName() const;
|
||||
|
||||
|
@@ -13,13 +13,39 @@
|
||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace Catch {
|
||||
namespace Detail {
|
||||
namespace {
|
||||
class RDBufStream : public IStream {
|
||||
mutable std::ostream m_os;
|
||||
|
||||
Config::Config( ConfigData const& data )
|
||||
: m_data( data ),
|
||||
m_stream( openStream() )
|
||||
{
|
||||
public:
|
||||
//! The streambuf `sb` must outlive the constructed object.
|
||||
RDBufStream( std::streambuf* sb ): m_os( sb ) {}
|
||||
~RDBufStream() override = default;
|
||||
|
||||
public: // IStream
|
||||
std::ostream& stream() const override { return m_os; }
|
||||
};
|
||||
} // unnamed namespace
|
||||
} // namespace Detail
|
||||
|
||||
std::ostream& operator<<( std::ostream& os,
|
||||
ConfigData::ReporterAndFile const& reporter ) {
|
||||
os << "{ " << reporter.reporterName << ", ";
|
||||
if ( reporter.outputFileName ) {
|
||||
os << *reporter.outputFileName;
|
||||
} else {
|
||||
os << "<default-output>";
|
||||
}
|
||||
return os << " }";
|
||||
}
|
||||
|
||||
Config::Config( ConfigData const& data ):
|
||||
m_data( data ),
|
||||
m_defaultStream( openStream( data.defaultOutputFilename ) ) {
|
||||
// We need to trim filter specs to avoid trouble with superfluous
|
||||
// whitespace (esp. important for bdd macros, as those are manually
|
||||
// aligned with whitespace).
|
||||
@@ -39,25 +65,37 @@ namespace Catch {
|
||||
}
|
||||
}
|
||||
m_testSpec = parser.testSpec();
|
||||
|
||||
m_reporterStreams.reserve( m_data.reporterSpecifications.size() );
|
||||
for ( auto const& reporterAndFile : m_data.reporterSpecifications ) {
|
||||
if ( reporterAndFile.outputFileName.none() ) {
|
||||
m_reporterStreams.emplace_back( new Detail::RDBufStream(
|
||||
m_defaultStream->stream().rdbuf() ) );
|
||||
} else {
|
||||
m_reporterStreams.emplace_back(
|
||||
openStream( *reporterAndFile.outputFileName ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Config::~Config() = default;
|
||||
|
||||
|
||||
std::string const& Config::getFilename() const {
|
||||
return m_data.outputFilename ;
|
||||
}
|
||||
|
||||
bool Config::listTests() const { return m_data.listTests; }
|
||||
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; }
|
||||
|
||||
std::vector<std::string> const& Config::getTestsOrTags() const { return m_data.testsOrTags; }
|
||||
std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
|
||||
|
||||
std::vector<ConfigData::ReporterAndFile> const& Config::getReportersAndOutputFiles() const {
|
||||
return m_data.reporterSpecifications;
|
||||
}
|
||||
|
||||
std::ostream& Config::getReporterOutputStream(std::size_t reporterIdx) const {
|
||||
return m_reporterStreams.at(reporterIdx)->stream();
|
||||
}
|
||||
|
||||
TestSpec const& Config::testSpec() const { return m_testSpec; }
|
||||
bool Config::hasTestFilters() const { return m_hasTestFilters; }
|
||||
|
||||
@@ -65,15 +103,22 @@ namespace Catch {
|
||||
|
||||
// IConfig interface
|
||||
bool Config::allowThrows() const { return !m_data.noThrow; }
|
||||
std::ostream& Config::stream() const { return m_stream->stream(); }
|
||||
std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
||||
std::ostream& Config::defaultStream() const { return m_defaultStream->stream(); }
|
||||
StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
||||
bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
|
||||
bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); }
|
||||
bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); }
|
||||
bool Config::warnAboutMissingAssertions() const {
|
||||
return !!( m_data.warnings & WarnAbout::NoAssertions );
|
||||
}
|
||||
bool Config::warnAboutUnmatchedTestSpecs() const {
|
||||
return !!( m_data.warnings & WarnAbout::UnmatchedTestSpec );
|
||||
}
|
||||
bool Config::zeroTestsCountAsSuccess() const { return m_data.allowZeroTests; }
|
||||
ShowDurations Config::showDurations() const { return m_data.showDurations; }
|
||||
double Config::minDuration() const { return m_data.minDuration; }
|
||||
TestRunOrder Config::runOrder() const { return m_data.runOrder; }
|
||||
unsigned int Config::rngSeed() const { return m_data.rngSeed; }
|
||||
uint32_t Config::rngSeed() const { return m_data.rngSeed; }
|
||||
unsigned int Config::shardCount() const { return m_data.shardCount; }
|
||||
unsigned int Config::shardIndex() const { return m_data.shardIndex; }
|
||||
UseColour Config::useColour() const { return m_data.useColour; }
|
||||
bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
|
||||
int Config::abortAfter() const { return m_data.abortAfter; }
|
||||
@@ -81,13 +126,13 @@ namespace Catch {
|
||||
Verbosity Config::verbosity() const { return m_data.verbosity; }
|
||||
|
||||
bool Config::benchmarkNoAnalysis() const { return m_data.benchmarkNoAnalysis; }
|
||||
int Config::benchmarkSamples() const { return m_data.benchmarkSamples; }
|
||||
unsigned int Config::benchmarkSamples() const { return m_data.benchmarkSamples; }
|
||||
double Config::benchmarkConfidenceInterval() const { return m_data.benchmarkConfidenceInterval; }
|
||||
unsigned int Config::benchmarkResamples() const { return m_data.benchmarkResamples; }
|
||||
std::chrono::milliseconds Config::benchmarkWarmupTime() const { return std::chrono::milliseconds(m_data.benchmarkWarmupTime); }
|
||||
|
||||
IStream const* Config::openStream() {
|
||||
return Catch::makeStream(m_data.outputFilename);
|
||||
Detail::unique_ptr<IStream const> Config::openStream(std::string const& outputFileName) {
|
||||
return Catch::makeStream(outputFileName);
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
@@ -11,7 +11,10 @@
|
||||
#include <catch2/catch_test_spec.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
#include <catch2/internal/catch_optional.hpp>
|
||||
#include <catch2/internal/catch_random_seed_generation.hpp>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
@@ -20,6 +23,18 @@ namespace Catch {
|
||||
struct IStream;
|
||||
|
||||
struct ConfigData {
|
||||
struct ReporterAndFile {
|
||||
std::string reporterName;
|
||||
|
||||
// If none, the output goes to the default output.
|
||||
Optional<std::string> outputFileName;
|
||||
|
||||
friend bool operator==(ReporterAndFile const& lhs, ReporterAndFile const& rhs) {
|
||||
return lhs.reporterName == rhs.reporterName && lhs.outputFileName == rhs.outputFileName;
|
||||
}
|
||||
friend std::ostream& operator<<(std::ostream &os, ReporterAndFile const& reporter);
|
||||
};
|
||||
|
||||
bool listTests = false;
|
||||
bool listTags = false;
|
||||
bool listReporters = false;
|
||||
@@ -31,9 +46,13 @@ namespace Catch {
|
||||
bool showInvisibles = false;
|
||||
bool filenamesAsTags = false;
|
||||
bool libIdentify = false;
|
||||
bool allowZeroTests = false;
|
||||
|
||||
int abortAfter = -1;
|
||||
unsigned int rngSeed = 0;
|
||||
uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
|
||||
|
||||
unsigned int shardCount = 1;
|
||||
unsigned int shardIndex = 0;
|
||||
|
||||
bool benchmarkNoAnalysis = false;
|
||||
unsigned int benchmarkSamples = 100;
|
||||
@@ -49,13 +68,17 @@ namespace Catch {
|
||||
UseColour useColour = UseColour::Auto;
|
||||
WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
|
||||
|
||||
std::string outputFilename;
|
||||
std::string defaultOutputFilename;
|
||||
std::string name;
|
||||
std::string processName;
|
||||
#ifndef CATCH_CONFIG_DEFAULT_REPORTER
|
||||
#define CATCH_CONFIG_DEFAULT_REPORTER "console"
|
||||
#endif
|
||||
std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER;
|
||||
std::vector<ReporterAndFile> reporterSpecifications = {
|
||||
{CATCH_CONFIG_DEFAULT_REPORTER, {}}
|
||||
};
|
||||
// Internal: used as parser state
|
||||
bool _nonDefaultReporterSpecifications = false;
|
||||
#undef CATCH_CONFIG_DEFAULT_REPORTER
|
||||
|
||||
std::vector<std::string> testsOrTags;
|
||||
@@ -70,14 +93,12 @@ namespace Catch {
|
||||
Config( ConfigData const& data );
|
||||
~Config() override; // = default in the cpp file
|
||||
|
||||
std::string const& getFilename() const;
|
||||
|
||||
bool listTests() const;
|
||||
bool listTags() const;
|
||||
bool listReporters() const;
|
||||
|
||||
std::string getProcessName() const;
|
||||
std::string const& getReporterName() const;
|
||||
std::vector<ConfigData::ReporterAndFile> const& getReportersAndOutputFiles() const;
|
||||
std::ostream& getReporterOutputStream(std::size_t reporterIdx) const;
|
||||
|
||||
std::vector<std::string> const& getTestsOrTags() const override;
|
||||
std::vector<std::string> const& getSectionsToRun() const override;
|
||||
@@ -89,36 +110,38 @@ namespace Catch {
|
||||
|
||||
// IConfig interface
|
||||
bool allowThrows() const override;
|
||||
std::ostream& stream() const override;
|
||||
std::string name() const override;
|
||||
std::ostream& defaultStream() const override;
|
||||
StringRef name() const override;
|
||||
bool includeSuccessfulResults() const override;
|
||||
bool warnAboutMissingAssertions() const override;
|
||||
bool warnAboutNoTests() const override;
|
||||
bool warnAboutUnmatchedTestSpecs() const override;
|
||||
bool zeroTestsCountAsSuccess() const override;
|
||||
ShowDurations showDurations() const override;
|
||||
double minDuration() const override;
|
||||
TestRunOrder runOrder() const override;
|
||||
unsigned int rngSeed() const override;
|
||||
uint32_t rngSeed() const override;
|
||||
unsigned int shardCount() const override;
|
||||
unsigned int shardIndex() const override;
|
||||
UseColour useColour() const override;
|
||||
bool shouldDebugBreak() const override;
|
||||
int abortAfter() const override;
|
||||
bool showInvisibles() const override;
|
||||
Verbosity verbosity() const override;
|
||||
bool benchmarkNoAnalysis() const override;
|
||||
int benchmarkSamples() const override;
|
||||
unsigned int benchmarkSamples() const override;
|
||||
double benchmarkConfidenceInterval() const override;
|
||||
unsigned int benchmarkResamples() const override;
|
||||
std::chrono::milliseconds benchmarkWarmupTime() const override;
|
||||
|
||||
private:
|
||||
|
||||
IStream const* openStream();
|
||||
Detail::unique_ptr<IStream const> openStream(std::string const& outputFileName);
|
||||
ConfigData m_data;
|
||||
|
||||
Detail::unique_ptr<IStream const> m_stream;
|
||||
Detail::unique_ptr<IStream const> m_defaultStream;
|
||||
std::vector<Detail::unique_ptr<IStream const>> m_reporterStreams;
|
||||
TestSpec m_testSpec;
|
||||
bool m_hasTestFilters = false;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // CATCH_CONFIG_HPP_INCLUDED
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
#include <catch2/internal/catch_uncaught_exceptions.hpp>
|
||||
#include <catch2/internal/catch_enforce.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <stack>
|
||||
@@ -17,13 +18,6 @@ namespace Catch {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Catch::MessageBuilder::MessageBuilder( StringRef const& macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
ResultWas::OfType type )
|
||||
:m_info(macroName, lineInfo, type) {}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
ScopedMessage::ScopedMessage( MessageBuilder const& builder ):
|
||||
m_info( builder.m_info ) {
|
||||
@@ -32,7 +26,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
|
||||
m_info( std::move( old.m_info ) ) {
|
||||
m_info( CATCH_MOVE( old.m_info ) ) {
|
||||
old.m_moved = true;
|
||||
}
|
||||
|
||||
|
@@ -9,8 +9,8 @@
|
||||
#define CATCH_MESSAGE_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_result_type.hpp>
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_stream.hpp>
|
||||
#include <catch2/internal/catch_stream_end_stop.hpp>
|
||||
#include <catch2/internal/catch_message_info.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
||||
#include <catch2/catch_tostring.hpp>
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
struct SourceLineInfo;
|
||||
|
||||
struct MessageStream {
|
||||
|
||||
template<typename T>
|
||||
@@ -32,9 +34,11 @@ namespace Catch {
|
||||
};
|
||||
|
||||
struct MessageBuilder : MessageStream {
|
||||
MessageBuilder( StringRef const& macroName,
|
||||
MessageBuilder( StringRef macroName,
|
||||
SourceLineInfo const& lineInfo,
|
||||
ResultWas::OfType type );
|
||||
ResultWas::OfType type ):
|
||||
m_info(macroName, lineInfo, type) {}
|
||||
|
||||
|
||||
template<typename T>
|
||||
MessageBuilder& operator << ( T const& value ) {
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <catch2/internal/catch_noncopyable.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
@@ -48,16 +49,16 @@ namespace Catch {
|
||||
|
||||
public: // IMutableRegistryHub
|
||||
void registerReporter( std::string const& name, IReporterFactoryPtr factory ) override {
|
||||
m_reporterRegistry.registerReporter( name, std::move(factory) );
|
||||
m_reporterRegistry.registerReporter( name, CATCH_MOVE(factory) );
|
||||
}
|
||||
void registerListener( IReporterFactoryPtr factory ) override {
|
||||
m_reporterRegistry.registerListener( std::move(factory) );
|
||||
m_reporterRegistry.registerListener( CATCH_MOVE(factory) );
|
||||
}
|
||||
void registerTest( Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker ) override {
|
||||
m_testCaseRegistry.registerTest( std::move(testInfo), std::move(invoker) );
|
||||
m_testCaseRegistry.registerTest( CATCH_MOVE(testInfo), CATCH_MOVE(invoker) );
|
||||
}
|
||||
void registerTranslator( const IExceptionTranslator* translator ) override {
|
||||
m_exceptionTranslatorRegistry.registerTranslator( translator );
|
||||
void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) override {
|
||||
m_exceptionTranslatorRegistry.registerTranslator( CATCH_MOVE(translator) );
|
||||
}
|
||||
void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
|
||||
m_tagAliasRegistry.add( alias, tag, lineInfo );
|
||||
|
@@ -8,7 +8,8 @@
|
||||
#ifndef CATCH_SECTION_INFO_HPP_INCLUDED
|
||||
#define CATCH_SECTION_INFO_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
#include <catch2/internal/catch_source_line_info.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
#include <catch2/catch_totals.hpp>
|
||||
|
||||
@@ -22,7 +23,7 @@ namespace Catch {
|
||||
// still use the `-c` flag comfortably.
|
||||
SectionInfo( SourceLineInfo const& _lineInfo, std::string _name,
|
||||
const char* const = nullptr ):
|
||||
name(std::move(_name)),
|
||||
name(CATCH_MOVE(_name)),
|
||||
lineInfo(_lineInfo)
|
||||
{}
|
||||
|
||||
|
@@ -16,13 +16,16 @@
|
||||
#include <catch2/catch_version.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
||||
#include <catch2/internal/catch_startup_exception_registry.hpp>
|
||||
#include <catch2/internal/catch_sharding.hpp>
|
||||
#include <catch2/internal/catch_textflow.hpp>
|
||||
#include <catch2/internal/catch_windows_h_proxy.hpp>
|
||||
#include <catch2/reporters/catch_reporter_listening.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_reporter_factory.hpp>
|
||||
#include <catch2/internal/catch_move_and_forward.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <set>
|
||||
|
||||
@@ -31,31 +34,35 @@ namespace Catch {
|
||||
namespace {
|
||||
const int MaxExitCode = 255;
|
||||
|
||||
IStreamingReporterPtr createReporter(std::string const& reporterName, IConfig const* config) {
|
||||
IStreamingReporterPtr createReporter(std::string const& reporterName, ReporterConfig const& config) {
|
||||
auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config);
|
||||
CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'");
|
||||
CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << '\'');
|
||||
|
||||
return reporter;
|
||||
}
|
||||
|
||||
IStreamingReporterPtr makeReporter(Config const* config) {
|
||||
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()) {
|
||||
return createReporter(config->getReporterName(), config);
|
||||
if (Catch::getRegistryHub().getReporterRegistry().getListeners().empty()
|
||||
&& config->getReportersAndOutputFiles().size() == 1) {
|
||||
auto& stream = config->getReporterOutputStream(0);
|
||||
return createReporter(config->getReportersAndOutputFiles()[0].reporterName, ReporterConfig(config, stream));
|
||||
}
|
||||
|
||||
// On older platforms, returning unique_ptr<ListeningReporter>
|
||||
// when the return type is unique_ptr<IStreamingReporter>
|
||||
// doesn't compile without a std::move call. However, this causes
|
||||
// a warning on newer platforms. Thus, we have to work around
|
||||
// it a bit and downcast the pointer manually.
|
||||
auto ret = Detail::unique_ptr<IStreamingReporter>(new ListeningReporter);
|
||||
auto& multi = static_cast<ListeningReporter&>(*ret);
|
||||
auto multi = Detail::make_unique<ListeningReporter>(config);
|
||||
|
||||
auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners();
|
||||
for (auto const& listener : listeners) {
|
||||
multi.addListener(listener->create(Catch::ReporterConfig(config)));
|
||||
multi->addListener(listener->create(Catch::ReporterConfig(config, config->defaultStream())));
|
||||
}
|
||||
multi.addReporter(createReporter(config->getReporterName(), config));
|
||||
return ret;
|
||||
|
||||
std::size_t reporterIdx = 0;
|
||||
for (auto const& reporterAndFile : config->getReportersAndOutputFiles()) {
|
||||
auto& stream = config->getReporterOutputStream(reporterIdx);
|
||||
multi->addReporter(createReporter(reporterAndFile.reporterName, ReporterConfig(config, stream)));
|
||||
reporterIdx++;
|
||||
}
|
||||
|
||||
return multi;
|
||||
}
|
||||
|
||||
class TestGroup {
|
||||
@@ -63,26 +70,33 @@ namespace Catch {
|
||||
explicit TestGroup(IStreamingReporterPtr&& reporter, Config const* config):
|
||||
m_reporter(reporter.get()),
|
||||
m_config{config},
|
||||
m_context{config, std::move(reporter)} {
|
||||
m_context{config, CATCH_MOVE(reporter)} {
|
||||
|
||||
assert( m_config->testSpec().getInvalidSpecs().empty() &&
|
||||
"Invalid test specs should be handled before running tests" );
|
||||
|
||||
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.getTestCaseInfo().isHidden())
|
||||
m_tests.emplace(&test);
|
||||
auto const& testSpec = m_config->testSpec();
|
||||
if ( !testSpec.hasFilters() ) {
|
||||
for ( auto const& test : allTestCases ) {
|
||||
if ( !test.getTestCaseInfo().isHidden() ) {
|
||||
m_tests.emplace( &test );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (auto const& match : m_matches)
|
||||
m_tests.insert(match.tests.begin(), match.tests.end());
|
||||
m_matches =
|
||||
testSpec.matchesByFilter( allTestCases, *m_config );
|
||||
for ( auto const& match : m_matches ) {
|
||||
m_tests.insert( match.tests.begin(),
|
||||
match.tests.end() );
|
||||
}
|
||||
}
|
||||
|
||||
m_tests = createShard(m_tests, m_config->shardCount(), m_config->shardIndex());
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -92,28 +106,26 @@ namespace Catch {
|
||||
|
||||
for (auto const& match : m_matches) {
|
||||
if (match.tests.empty()) {
|
||||
m_reporter->noMatchingTestCases(match.name);
|
||||
totals.error = -1;
|
||||
m_unmatchedTestSpecs = true;
|
||||
m_reporter->noMatchingTestCases( match.name );
|
||||
}
|
||||
}
|
||||
|
||||
if (!invalidArgs.empty()) {
|
||||
for (auto const& invalidArg: invalidArgs)
|
||||
m_reporter->reportInvalidArguments(invalidArg);
|
||||
}
|
||||
|
||||
m_context.testGroupEnded(m_config->name(), totals, 1, 1);
|
||||
return totals;
|
||||
}
|
||||
|
||||
private:
|
||||
using Tests = std::set<TestCaseHandle const*>;
|
||||
bool hadUnmatchedTestSpecs() const {
|
||||
return m_unmatchedTestSpecs;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
IStreamingReporter* m_reporter;
|
||||
Config const* m_config;
|
||||
RunContext m_context;
|
||||
Tests m_tests;
|
||||
std::set<TestCaseHandle const*> m_tests;
|
||||
TestSpec::Matches m_matches;
|
||||
bool m_unmatchedTestSpecs = false;
|
||||
};
|
||||
|
||||
void applyFilenamesAsTags() {
|
||||
@@ -161,16 +173,16 @@ namespace Catch {
|
||||
|
||||
void Session::showHelp() const {
|
||||
Catch::cout()
|
||||
<< "\nCatch v" << libraryVersion() << "\n"
|
||||
<< m_cli << std::endl
|
||||
<< "For more detailed usage please see the project docs\n" << std::endl;
|
||||
<< "\nCatch v" << libraryVersion() << '\n'
|
||||
<< m_cli << '\n'
|
||||
<< "For more detailed usage please see the project docs\n\n" << std::flush;
|
||||
}
|
||||
void Session::libIdentify() {
|
||||
Catch::cout()
|
||||
<< 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;
|
||||
<< std::left << std::setw(16) << "version: " << libraryVersion() << '\n' << std::flush;
|
||||
}
|
||||
|
||||
int Session::applyCommandLine( int argc, char const * const * argv ) {
|
||||
@@ -178,6 +190,7 @@ namespace Catch {
|
||||
return 1;
|
||||
|
||||
auto result = m_cli.parse( Clara::Args( argc, argv ) );
|
||||
|
||||
if( !result ) {
|
||||
config();
|
||||
getCurrentMutableContext().setConfig(m_config.get());
|
||||
@@ -186,7 +199,7 @@ namespace Catch {
|
||||
<< "\nError(s) in input:\n"
|
||||
<< TextFlow::Column( result.errorMessage() ).indent( 2 )
|
||||
<< "\n\n";
|
||||
Catch::cerr() << "Run with -? for usage\n" << std::endl;
|
||||
Catch::cerr() << "Run with -? for usage\n\n" << std::flush;
|
||||
return MaxExitCode;
|
||||
}
|
||||
|
||||
@@ -194,6 +207,7 @@ namespace Catch {
|
||||
showHelp();
|
||||
if( m_configData.libIdentify )
|
||||
libIdentify();
|
||||
|
||||
m_config.reset();
|
||||
return 0;
|
||||
}
|
||||
@@ -229,12 +243,12 @@ namespace Catch {
|
||||
|
||||
int Session::run() {
|
||||
if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
|
||||
Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
|
||||
Catch::cout() << "...waiting for enter/ return before starting\n" << std::flush;
|
||||
static_cast<void>(std::getchar());
|
||||
}
|
||||
int exitCode = runInternal();
|
||||
if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
|
||||
Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
|
||||
Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << '\n' << std::flush;
|
||||
static_cast<void>(std::getchar());
|
||||
}
|
||||
return exitCode;
|
||||
@@ -263,6 +277,14 @@ namespace Catch {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( m_configData.shardIndex >= m_configData.shardCount ) {
|
||||
Catch::cerr() << "The shard count (" << m_configData.shardCount
|
||||
<< ") must be greater than the shard index ("
|
||||
<< m_configData.shardIndex << ")\n"
|
||||
<< std::flush;
|
||||
return 1;
|
||||
}
|
||||
|
||||
CATCH_TRY {
|
||||
config(); // Force config to be constructed
|
||||
|
||||
@@ -278,16 +300,32 @@ namespace Catch {
|
||||
// Create reporter(s) so we can route listings through them
|
||||
auto reporter = makeReporter(m_config.get());
|
||||
|
||||
auto const& invalidSpecs = m_config->testSpec().getInvalidSpecs();
|
||||
if ( !invalidSpecs.empty() ) {
|
||||
for ( auto const& spec : invalidSpecs ) {
|
||||
reporter->reportInvalidTestSpec( spec );
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// Handle list request
|
||||
if (list(*reporter, *m_config)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TestGroup tests { std::move(reporter), m_config.get() };
|
||||
TestGroup tests { CATCH_MOVE(reporter), m_config.get() };
|
||||
auto const totals = tests.execute();
|
||||
|
||||
if( m_config->warnAboutNoTests() && totals.error == -1 )
|
||||
if ( tests.hadUnmatchedTestSpecs()
|
||||
&& m_config->warnAboutUnmatchedTestSpecs() ) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if ( totals.testCases.total() == 0
|
||||
&& !m_config->zeroTestsCountAsSuccess() ) {
|
||||
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
|
||||
@@ -296,7 +334,7 @@ namespace Catch {
|
||||
}
|
||||
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
|
||||
catch( std::exception& ex ) {
|
||||
Catch::cerr() << ex.what() << std::endl;
|
||||
Catch::cerr() << ex.what() << '\n' << std::flush;
|
||||
return MaxExitCode;
|
||||
}
|
||||
#endif
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#include <catch2/internal/catch_noncopyable.hpp>
|
||||
#include <catch2/catch_config.hpp>
|
||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_config_wchar.hpp>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#ifndef CATCH_TAG_ALIAS_HPP_INCLUDED
|
||||
#define CATCH_TAG_ALIAS_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_source_line_info.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@@ -8,7 +8,9 @@
|
||||
#ifndef CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
|
||||
#define CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_unique_name.hpp>
|
||||
#include <catch2/internal/catch_source_line_info.hpp>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include <catch2/catch_test_spec.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_testcase.hpp>
|
||||
#include <catch2/internal/catch_string_manip.hpp>
|
||||
#include <catch2/internal/catch_case_insensitive_comparisons.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
@@ -101,16 +102,25 @@ namespace Catch {
|
||||
const size_t extras = 3 + 3;
|
||||
return extractFilenamePart(filepath).size() + extras;
|
||||
}
|
||||
} // end unnamed namespace
|
||||
|
||||
bool operator<( Tag const& lhs, Tag const& rhs ) {
|
||||
Detail::CaseInsensitiveLess cmp;
|
||||
return cmp( lhs.original, rhs.original );
|
||||
}
|
||||
bool operator==( Tag const& lhs, Tag const& rhs ) {
|
||||
Detail::CaseInsensitiveEqualTo cmp;
|
||||
return cmp( lhs.original, rhs.original );
|
||||
}
|
||||
|
||||
Detail::unique_ptr<TestCaseInfo>
|
||||
makeTestCaseInfo(std::string const& _className,
|
||||
makeTestCaseInfo(StringRef _className,
|
||||
NameAndTags const& nameAndTags,
|
||||
SourceLineInfo const& _lineInfo ) {
|
||||
return Detail::unique_ptr<TestCaseInfo>(new TestCaseInfo(_className, nameAndTags, _lineInfo));
|
||||
return Detail::make_unique<TestCaseInfo>(_className, nameAndTags, _lineInfo);
|
||||
}
|
||||
|
||||
TestCaseInfo::TestCaseInfo(std::string const& _className,
|
||||
TestCaseInfo::TestCaseInfo(StringRef _className,
|
||||
NameAndTags const& _nameAndTags,
|
||||
SourceLineInfo const& _lineInfo):
|
||||
name( _nameAndTags.name.empty() ? makeDefaultName() : _nameAndTags.name ),
|
||||
@@ -122,7 +132,6 @@ namespace Catch {
|
||||
// (including optional hidden tag and filename tag)
|
||||
auto requiredSize = originalTags.size() + sizeOfExtraTags(_lineInfo.file);
|
||||
backingTags.reserve(requiredSize);
|
||||
backingLCaseTags.reserve(requiredSize);
|
||||
|
||||
// We cannot copy the tags directly, as we need to normalize
|
||||
// some tags, so that [.foo] is copied as [.][foo].
|
||||
@@ -146,6 +155,7 @@ namespace Catch {
|
||||
// it over to backing storage and actually reference the
|
||||
// backing storage in the saved tags
|
||||
StringRef tagStr = originalTags.substr(tagStart+1, tagEnd - tagStart - 1);
|
||||
CATCH_ENFORCE(!tagStr.empty(), "Empty tags are not allowed");
|
||||
enforceNotReservedTag(tagStr, lineInfo);
|
||||
properties |= parseSpecialTag(tagStr);
|
||||
// When copying a tag to the backing storage, we need to
|
||||
@@ -167,9 +177,8 @@ namespace Catch {
|
||||
}
|
||||
|
||||
// Sort and prepare tags
|
||||
toLowerInPlace(backingLCaseTags);
|
||||
std::sort(begin(tags), end(tags), [](Tag lhs, Tag rhs) { return lhs.lowerCased < rhs.lowerCased; });
|
||||
tags.erase(std::unique(begin(tags), end(tags), [](Tag lhs, Tag rhs) {return lhs.lowerCased == rhs.lowerCased; }),
|
||||
std::sort(begin(tags), end(tags));
|
||||
tags.erase(std::unique(begin(tags), end(tags)),
|
||||
end(tags));
|
||||
}
|
||||
|
||||
@@ -215,24 +224,22 @@ namespace Catch {
|
||||
backingTags += tagStr;
|
||||
const auto backingEnd = backingTags.size();
|
||||
backingTags += ']';
|
||||
backingLCaseTags += '[';
|
||||
// We append the tag to the lower-case backing storage as-is,
|
||||
// because we will perform the lower casing later, in bulk
|
||||
backingLCaseTags += tagStr;
|
||||
backingLCaseTags += ']';
|
||||
tags.emplace_back(StringRef(backingTags.c_str() + backingStart, backingEnd - backingStart),
|
||||
StringRef(backingLCaseTags.c_str() + backingStart, backingEnd - backingStart));
|
||||
tags.emplace_back(StringRef(backingTags.c_str() + backingStart, backingEnd - backingStart));
|
||||
}
|
||||
|
||||
|
||||
bool TestCaseHandle::operator == ( TestCaseHandle const& rhs ) const {
|
||||
return m_invoker == rhs.m_invoker
|
||||
&& m_info->name == rhs.m_info->name
|
||||
&& m_info->className == rhs.m_info->className;
|
||||
}
|
||||
|
||||
bool TestCaseHandle::operator < ( TestCaseHandle const& rhs ) const {
|
||||
return m_info->name < rhs.m_info->name;
|
||||
bool operator<( TestCaseInfo const& lhs, TestCaseInfo const& rhs ) {
|
||||
// We want to avoid redoing the string comparisons multiple times,
|
||||
// so we store the result of a three-way comparison before using
|
||||
// it in the actual comparison logic.
|
||||
const auto cmpName = lhs.name.compare( rhs.name );
|
||||
if ( cmpName != 0 ) {
|
||||
return cmpName < 0;
|
||||
}
|
||||
const auto cmpClassName = lhs.className.compare( rhs.className );
|
||||
if ( cmpClassName != 0 ) {
|
||||
return cmpClassName < 0;
|
||||
}
|
||||
return lhs.tags < rhs.tags;
|
||||
}
|
||||
|
||||
TestCaseInfo const& TestCaseHandle::getTestCaseInfo() const {
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#ifndef CATCH_TEST_CASE_INFO_HPP_INCLUDED
|
||||
#define CATCH_TEST_CASE_INFO_HPP_INCLUDED
|
||||
|
||||
#include <catch2/internal/catch_common.hpp>
|
||||
#include <catch2/internal/catch_source_line_info.hpp>
|
||||
#include <catch2/internal/catch_noncopyable.hpp>
|
||||
#include <catch2/internal/catch_stringref.hpp>
|
||||
#include <catch2/internal/catch_test_registry.hpp>
|
||||
@@ -25,11 +25,21 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
/**
|
||||
* A **view** of a tag string that provides case insensitive comparisons
|
||||
*
|
||||
* Note that in Catch2 internals, the square brackets around tags are
|
||||
* not a part of tag's representation, so e.g. "[cool-tag]" is represented
|
||||
* as "cool-tag" internally.
|
||||
*/
|
||||
struct Tag {
|
||||
Tag(StringRef original_, StringRef lowerCased_):
|
||||
original(original_), lowerCased(lowerCased_)
|
||||
constexpr Tag(StringRef original_):
|
||||
original(original_)
|
||||
{}
|
||||
StringRef original, lowerCased;
|
||||
StringRef original;
|
||||
|
||||
friend bool operator< ( Tag const& lhs, Tag const& rhs );
|
||||
friend bool operator==( Tag const& lhs, Tag const& rhs );
|
||||
};
|
||||
|
||||
struct ITestInvoker;
|
||||
@@ -44,10 +54,18 @@ namespace Catch {
|
||||
Benchmark = 1 << 6
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Various metadata about the test case.
|
||||
*
|
||||
* A test case is uniquely identified by its (class)name and tags
|
||||
* combination, with source location being ignored, and other properties
|
||||
* being determined from tags.
|
||||
*
|
||||
* Tags are kept sorted.
|
||||
*/
|
||||
struct TestCaseInfo : Detail::NonCopyable {
|
||||
|
||||
TestCaseInfo(std::string const& _className,
|
||||
TestCaseInfo(StringRef _className,
|
||||
NameAndTags const& _tags,
|
||||
SourceLineInfo const& _lineInfo);
|
||||
|
||||
@@ -59,13 +77,17 @@ namespace Catch {
|
||||
// Adds the tag(s) with test's filename (for the -# flag)
|
||||
void addFilenameTag();
|
||||
|
||||
//! Orders by name, classname and tags
|
||||
friend bool operator<( TestCaseInfo const& lhs,
|
||||
TestCaseInfo const& rhs );
|
||||
|
||||
|
||||
std::string tagsAsString() const;
|
||||
|
||||
std::string name;
|
||||
std::string className;
|
||||
StringRef className;
|
||||
private:
|
||||
std::string backingTags, backingLCaseTags;
|
||||
std::string backingTags;
|
||||
// Internally we copy tags to the backing storage and then add
|
||||
// refs to this storage to the tags vector.
|
||||
void internalAppendTag(StringRef tagString);
|
||||
@@ -75,6 +97,12 @@ namespace Catch {
|
||||
TestCaseProperties properties = TestCaseProperties::None;
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper over the test case information and the test case invoker
|
||||
*
|
||||
* Does not own either, and is specifically made to be cheap
|
||||
* to copy around.
|
||||
*/
|
||||
class TestCaseHandle {
|
||||
TestCaseInfo* m_info;
|
||||
ITestInvoker* m_invoker;
|
||||
@@ -87,14 +115,12 @@ namespace Catch {
|
||||
}
|
||||
|
||||
TestCaseInfo const& getTestCaseInfo() const;
|
||||
|
||||
bool operator== ( TestCaseHandle const& rhs ) const;
|
||||
bool operator < ( TestCaseHandle const& rhs ) const;
|
||||
};
|
||||
|
||||
Detail::unique_ptr<TestCaseInfo> makeTestCaseInfo( std::string const& className,
|
||||
NameAndTags const& nameAndTags,
|
||||
SourceLineInfo const& lineInfo );
|
||||
Detail::unique_ptr<TestCaseInfo>
|
||||
makeTestCaseInfo( StringRef className,
|
||||
NameAndTags const& nameAndTags,
|
||||
SourceLineInfo const& lineInfo );
|
||||
}
|
||||
|
||||
#ifdef __clang__
|
||||
|
@@ -13,6 +13,8 @@
|
||||
#include <catch2/internal/catch_preprocessor.hpp>
|
||||
#include <catch2/internal/catch_section.hpp>
|
||||
#include <catch2/internal/catch_test_registry.hpp>
|
||||
#include <catch2/internal/catch_unique_name.hpp>
|
||||
|
||||
|
||||
// All of our user-facing macros support configuration toggle, that
|
||||
// forces them to be defined prefixed with CATCH_. We also like to
|
||||
@@ -30,8 +32,8 @@
|
||||
|
||||
#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||
#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||
#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||
#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||
|
||||
#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
@@ -52,9 +54,13 @@
|
||||
#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
|
||||
#define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
|
||||
#define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
|
||||
#define CATCH_STATIC_CHECK( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
|
||||
#define CATCH_STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
|
||||
#else
|
||||
#define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ )
|
||||
#define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ )
|
||||
#define CATCH_STATIC_CHECK( ... ) CATCH_CHECK( __VA_ARGS__ )
|
||||
#define CATCH_STATIC_CHECK_FALSE( ... ) CATCH_CHECK_FALSE( __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
|
||||
@@ -87,8 +93,8 @@
|
||||
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||
#define CATCH_CHECK_NOTHROW( ... ) (void)(0)
|
||||
|
||||
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
|
||||
#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
|
||||
#define CATCH_METHOD_AS_TEST_CASE( method, ... )
|
||||
#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||
#define CATCH_SECTION( ... )
|
||||
@@ -99,10 +105,12 @@
|
||||
|
||||
#define CATCH_STATIC_REQUIRE( ... ) (void)(0)
|
||||
#define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0)
|
||||
#define CATCH_STATIC_CHECK( ... ) (void)(0)
|
||||
#define CATCH_STATIC_CHECK_FALSE( ... ) (void)(0)
|
||||
|
||||
// "BDD-style" convenience wrappers
|
||||
#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className )
|
||||
#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
|
||||
#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className )
|
||||
#define CATCH_GIVEN( desc )
|
||||
#define CATCH_AND_GIVEN( desc )
|
||||
#define CATCH_WHEN( desc )
|
||||
@@ -121,8 +129,8 @@
|
||||
|
||||
#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||
#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||
#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||
#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||
|
||||
#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||
@@ -143,9 +151,13 @@
|
||||
#if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
|
||||
#define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
|
||||
#define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
|
||||
#define STATIC_CHECK( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
|
||||
#define STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
|
||||
#else
|
||||
#define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ )
|
||||
#define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ )
|
||||
#define STATIC_CHECK( ... ) CHECK( __VA_ARGS__ )
|
||||
#define STATIC_CHECK_FALSE( ... ) CHECK_FALSE( __VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
// "BDD-style" convenience wrappers
|
||||
@@ -177,8 +189,8 @@
|
||||
#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||
#define CHECK_NOTHROW( ... ) (void)(0)
|
||||
|
||||
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__)
|
||||
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__)
|
||||
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
|
||||
#define METHOD_AS_TEST_CASE( method, ... )
|
||||
#define REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||
#define SECTION( ... )
|
||||
@@ -189,10 +201,12 @@
|
||||
|
||||
#define STATIC_REQUIRE( ... ) (void)(0)
|
||||
#define STATIC_REQUIRE_FALSE( ... ) (void)(0)
|
||||
#define STATIC_CHECK( ... ) (void)(0)
|
||||
#define STATIC_CHECK_FALSE( ... ) (void)(0)
|
||||
|
||||
// "BDD-style" convenience wrappers
|
||||
#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) )
|
||||
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className )
|
||||
#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ) )
|
||||
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className )
|
||||
|
||||
#define GIVEN( desc )
|
||||
#define AND_GIVEN( desc )
|
||||
|
@@ -38,15 +38,13 @@ namespace Catch {
|
||||
|
||||
TestSpec::TagPattern::TagPattern( std::string const& tag, std::string const& filterString )
|
||||
: Pattern( filterString )
|
||||
, m_tag( toLower( tag ) )
|
||||
, m_tag( tag )
|
||||
{}
|
||||
|
||||
bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
|
||||
return std::find_if(begin(testCase.tags),
|
||||
end(testCase.tags),
|
||||
[&](Tag const& tag) {
|
||||
return tag.lowerCased == m_tag;
|
||||
}) != end(testCase.tags);
|
||||
return std::find( begin( testCase.tags ),
|
||||
end( testCase.tags ),
|
||||
Tag( m_tag ) ) != end( testCase.tags );
|
||||
}
|
||||
|
||||
bool TestSpec::Filter::matches( TestCaseInfo const& testCase ) const {
|
||||
@@ -98,8 +96,8 @@ namespace Catch {
|
||||
return matches;
|
||||
}
|
||||
|
||||
const TestSpec::vectorStrings& TestSpec::getInvalidArgs() const{
|
||||
return (m_invalidArgs);
|
||||
const TestSpec::vectorStrings& TestSpec::getInvalidSpecs() const {
|
||||
return m_invalidSpecs;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -72,11 +72,11 @@ namespace Catch {
|
||||
bool hasFilters() const;
|
||||
bool matches( TestCaseInfo const& testCase ) const;
|
||||
Matches matchesByFilter( std::vector<TestCaseHandle> const& testCases, IConfig const& config ) const;
|
||||
const vectorStrings & getInvalidArgs() const;
|
||||
const vectorStrings & getInvalidSpecs() const;
|
||||
|
||||
private:
|
||||
std::vector<Filter> m_filters;
|
||||
std::vector<std::string> m_invalidArgs;
|
||||
std::vector<std::string> m_invalidSpecs;
|
||||
friend class TestSpecParser;
|
||||
};
|
||||
}
|
||||
|
@@ -9,49 +9,13 @@
|
||||
|
||||
#include <chrono>
|
||||
|
||||
static const uint64_t nanosecondsInSecond = 1000000000;
|
||||
|
||||
namespace Catch {
|
||||
|
||||
auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||
}
|
||||
|
||||
namespace {
|
||||
auto estimateClockResolution() -> uint64_t {
|
||||
uint64_t sum = 0;
|
||||
static const uint64_t iterations = 1000000;
|
||||
|
||||
auto startTime = getCurrentNanosecondsSinceEpoch();
|
||||
|
||||
for( std::size_t i = 0; i < iterations; ++i ) {
|
||||
|
||||
uint64_t ticks;
|
||||
uint64_t baseTicks = getCurrentNanosecondsSinceEpoch();
|
||||
do {
|
||||
ticks = getCurrentNanosecondsSinceEpoch();
|
||||
} while( ticks == baseTicks );
|
||||
|
||||
auto delta = ticks - baseTicks;
|
||||
sum += delta;
|
||||
|
||||
// If we have been calibrating for over 3 seconds -- the clock
|
||||
// is terrible and we should move on.
|
||||
// TBD: How to signal that the measured resolution is probably wrong?
|
||||
if (ticks > startTime + 3 * nanosecondsInSecond) {
|
||||
return sum / ( i + 1u );
|
||||
}
|
||||
}
|
||||
|
||||
// We're just taking the mean, here. To do better we could take the std. dev and exclude outliers
|
||||
// - and potentially do more iterations if there's a high variance.
|
||||
return sum/iterations;
|
||||
static auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
}
|
||||
auto getEstimatedClockResolution() -> uint64_t {
|
||||
static auto s_resolution = estimateClockResolution();
|
||||
return s_resolution;
|
||||
}
|
||||
} // end unnamed namespace
|
||||
|
||||
void Timer::start() {
|
||||
m_nanoseconds = getCurrentNanosecondsSinceEpoch();
|
||||
|
@@ -12,9 +12,6 @@
|
||||
|
||||
namespace Catch {
|
||||
|
||||
auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
|
||||
auto getEstimatedClockResolution() -> uint64_t;
|
||||
|
||||
class Timer {
|
||||
uint64_t m_nanoseconds = 0;
|
||||
public:
|
||||
|
@@ -5,12 +5,6 @@
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||
# pragma clang diagnostic ignored "-Wglobal-constructors"
|
||||
#endif
|
||||
|
||||
|
||||
#include <catch2/catch_tostring.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
||||
@@ -24,8 +18,6 @@ namespace Catch {
|
||||
|
||||
namespace Detail {
|
||||
|
||||
const std::string unprintableString = "{?}";
|
||||
|
||||
namespace {
|
||||
const int hexThreshold = 255;
|
||||
|
||||
@@ -62,6 +54,48 @@ namespace Detail {
|
||||
}
|
||||
} // end unnamed namespace
|
||||
|
||||
std::string convertIntoString(StringRef string, bool escape_invisibles) {
|
||||
std::string ret;
|
||||
// This is enough for the "don't escape invisibles" case, and a good
|
||||
// lower bound on the "escape invisibles" case.
|
||||
ret.reserve(string.size() + 2);
|
||||
|
||||
if (!escape_invisibles) {
|
||||
ret += '"';
|
||||
ret += string;
|
||||
ret += '"';
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret += '"';
|
||||
for (char c : string) {
|
||||
switch (c) {
|
||||
case '\r':
|
||||
ret.append("\\r");
|
||||
break;
|
||||
case '\n':
|
||||
ret.append("\\n");
|
||||
break;
|
||||
case '\t':
|
||||
ret.append("\\t");
|
||||
break;
|
||||
case '\f':
|
||||
ret.append("\\f");
|
||||
break;
|
||||
default:
|
||||
ret.push_back(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret += '"';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string convertIntoString(StringRef string) {
|
||||
return convertIntoString(string, getCurrentContext().getConfig()->showInvisibles());
|
||||
}
|
||||
|
||||
std::string rawMemoryToString( const void *object, std::size_t size ) {
|
||||
// Reverse order for little endian architectures
|
||||
int i = 0, end = static_cast<int>( size ), inc = 1;
|
||||
@@ -88,44 +122,25 @@ namespace Detail {
|
||||
//// ======================================================= ////
|
||||
|
||||
std::string StringMaker<std::string>::convert(const std::string& str) {
|
||||
if (!getCurrentContext().getConfig()->showInvisibles()) {
|
||||
return '"' + str + '"';
|
||||
}
|
||||
|
||||
std::string s("\"");
|
||||
for (char c : str) {
|
||||
switch (c) {
|
||||
case '\n':
|
||||
s.append("\\n");
|
||||
break;
|
||||
case '\t':
|
||||
s.append("\\t");
|
||||
break;
|
||||
default:
|
||||
s.push_back(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
s.append("\"");
|
||||
return s;
|
||||
return Detail::convertIntoString( str );
|
||||
}
|
||||
|
||||
#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
|
||||
std::string StringMaker<std::string_view>::convert(std::string_view str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
return Detail::convertIntoString( StringRef( str.data(), str.size() ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string StringMaker<char const*>::convert(char const* str) {
|
||||
if (str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
return Detail::convertIntoString( str );
|
||||
} else {
|
||||
return{ "{null string}" };
|
||||
}
|
||||
}
|
||||
std::string StringMaker<char*>::convert(char* str) {
|
||||
if (str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
return Detail::convertIntoString( str );
|
||||
} else {
|
||||
return{ "{null string}" };
|
||||
}
|
||||
@@ -237,8 +252,3 @@ std::string StringMaker<double>::convert(double value) {
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
|
@@ -13,8 +13,12 @@
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_config_wchar.hpp>
|
||||
#include <catch2/internal/catch_stream.hpp>
|
||||
#include <catch2/internal/catch_void_type.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_enum_values_registry.hpp>
|
||||
|
||||
#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
|
||||
@@ -26,10 +30,26 @@
|
||||
#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
|
||||
#endif
|
||||
|
||||
// We need a dummy global operator<< so we can bring it into Catch namespace later
|
||||
struct Catch_global_namespace_dummy{};
|
||||
std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
|
||||
|
||||
namespace Catch {
|
||||
// Bring in global namespace operator<< for ADL lookup in
|
||||
// `IsStreamInsertable` below.
|
||||
using ::operator<<;
|
||||
|
||||
namespace Detail {
|
||||
|
||||
extern const std::string unprintableString;
|
||||
|
||||
constexpr StringRef unprintableString = "{?}"_sr;
|
||||
|
||||
//! Encases `string in quotes, and optionally escapes invisibles
|
||||
std::string convertIntoString( StringRef string, bool escapeInvisibles );
|
||||
|
||||
//! Encases `string` in quotes, and escapes invisibles if user requested
|
||||
//! it via CLI
|
||||
std::string convertIntoString( StringRef string );
|
||||
|
||||
std::string rawMemoryToString( const void *object, std::size_t size );
|
||||
|
||||
@@ -58,7 +78,7 @@ namespace Catch {
|
||||
std::enable_if_t<
|
||||
!std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value,
|
||||
std::string> convertUnstreamable( T const& ) {
|
||||
return Detail::unprintableString;
|
||||
return std::string(Detail::unprintableString);
|
||||
}
|
||||
template<typename T>
|
||||
std::enable_if_t<
|
||||
@@ -162,7 +182,7 @@ namespace Catch {
|
||||
static std::string convert(char * str);
|
||||
};
|
||||
|
||||
#ifdef CATCH_CONFIG_WCHAR
|
||||
#if defined(CATCH_CONFIG_WCHAR)
|
||||
template<>
|
||||
struct StringMaker<std::wstring> {
|
||||
static std::string convert(const std::wstring& wstr);
|
||||
@@ -183,26 +203,33 @@ namespace Catch {
|
||||
struct StringMaker<wchar_t *> {
|
||||
static std::string convert(wchar_t * str);
|
||||
};
|
||||
#endif
|
||||
#endif // CATCH_CONFIG_WCHAR
|
||||
|
||||
// TBD: Should we use `strnlen` to ensure that we don't go out of the buffer,
|
||||
// while keeping string semantics?
|
||||
template<int SZ>
|
||||
template<size_t SZ>
|
||||
struct StringMaker<char[SZ]> {
|
||||
static std::string convert(char const* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ str });
|
||||
// Note that `strnlen` is not actually part of standard C++,
|
||||
// but both POSIX and Windows cstdlib provide it.
|
||||
return Detail::convertIntoString(
|
||||
StringRef( str, strnlen( str, SZ ) ) );
|
||||
}
|
||||
};
|
||||
template<int SZ>
|
||||
template<size_t SZ>
|
||||
struct StringMaker<signed char[SZ]> {
|
||||
static std::string convert(signed char const* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
|
||||
// See the plain `char const*` overload
|
||||
auto reinterpreted = reinterpret_cast<char const*>(str);
|
||||
return Detail::convertIntoString(
|
||||
StringRef(reinterpreted, strnlen(reinterpreted, SZ)));
|
||||
}
|
||||
};
|
||||
template<int SZ>
|
||||
template<size_t SZ>
|
||||
struct StringMaker<unsigned char[SZ]> {
|
||||
static std::string convert(unsigned char const* str) {
|
||||
return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
|
||||
// See the plain `char const*` overload
|
||||
auto reinterpreted = reinterpret_cast<char const*>(str);
|
||||
return Detail::convertIntoString(
|
||||
StringRef(reinterpreted, strnlen(reinterpreted, SZ)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -363,13 +390,11 @@ namespace Catch {
|
||||
template<typename T>
|
||||
struct StringMaker<std::optional<T> > {
|
||||
static std::string convert(const std::optional<T>& optional) {
|
||||
ReusableStringStream rss;
|
||||
if (optional.has_value()) {
|
||||
rss << ::Catch::Detail::stringify(*optional);
|
||||
return ::Catch::Detail::stringify(*optional);
|
||||
} else {
|
||||
rss << "{ }";
|
||||
return "{ }";
|
||||
}
|
||||
return rss.str();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -450,24 +475,16 @@ namespace Catch {
|
||||
using std::begin;
|
||||
using std::end;
|
||||
|
||||
namespace detail {
|
||||
template <typename...>
|
||||
struct void_type {
|
||||
using type = void;
|
||||
};
|
||||
|
||||
namespace Detail {
|
||||
template <typename T, typename = void>
|
||||
struct is_range_impl : std::false_type {
|
||||
};
|
||||
struct is_range_impl : std::false_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_range_impl<T, typename void_type<decltype(begin(std::declval<T>()))>::type> : std::true_type {
|
||||
};
|
||||
} // namespace detail
|
||||
struct is_range_impl<T, void_t<decltype(begin(std::declval<T>()))>> : std::true_type {};
|
||||
} // namespace Detail
|
||||
|
||||
template <typename T>
|
||||
struct is_range : detail::is_range_impl<T> {
|
||||
};
|
||||
struct is_range : Detail::is_range_impl<T> {};
|
||||
|
||||
#if defined(_MANAGED) // Managed types are never ranges
|
||||
template <typename T>
|
||||
@@ -505,7 +522,7 @@ namespace Catch {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, int SZ>
|
||||
template <typename T, size_t SZ>
|
||||
struct StringMaker<T[SZ]> {
|
||||
static std::string convert(T const(&arr)[SZ]) {
|
||||
return rangeToString(arr);
|
||||
@@ -535,27 +552,27 @@ struct ratio_string {
|
||||
|
||||
template <>
|
||||
struct ratio_string<std::atto> {
|
||||
static std::string symbol() { return "a"; }
|
||||
static char symbol() { return 'a'; }
|
||||
};
|
||||
template <>
|
||||
struct ratio_string<std::femto> {
|
||||
static std::string symbol() { return "f"; }
|
||||
static char symbol() { return 'f'; }
|
||||
};
|
||||
template <>
|
||||
struct ratio_string<std::pico> {
|
||||
static std::string symbol() { return "p"; }
|
||||
static char symbol() { return 'p'; }
|
||||
};
|
||||
template <>
|
||||
struct ratio_string<std::nano> {
|
||||
static std::string symbol() { return "n"; }
|
||||
static char symbol() { return 'n'; }
|
||||
};
|
||||
template <>
|
||||
struct ratio_string<std::micro> {
|
||||
static std::string symbol() { return "u"; }
|
||||
static char symbol() { return 'u'; }
|
||||
};
|
||||
template <>
|
||||
struct ratio_string<std::milli> {
|
||||
static std::string symbol() { return "m"; }
|
||||
static char symbol() { return 'm'; }
|
||||
};
|
||||
|
||||
////////////
|
||||
@@ -624,7 +641,7 @@ struct ratio_string<std::milli> {
|
||||
#else
|
||||
std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
|
||||
#endif
|
||||
return std::string(timeStamp);
|
||||
return std::string(timeStamp, timeStampSize - 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ namespace Catch {
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::size_t Counts::total() const {
|
||||
std::uint64_t Counts::total() const {
|
||||
return passed + failed + failedButOk;
|
||||
}
|
||||
bool Counts::allPassed() const {
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#define CATCH_TOTALS_HPP_INCLUDED
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
@@ -16,13 +17,13 @@ namespace Catch {
|
||||
Counts operator - ( Counts const& other ) const;
|
||||
Counts& operator += ( Counts const& other );
|
||||
|
||||
std::size_t total() const;
|
||||
std::uint64_t total() const;
|
||||
bool allPassed() const;
|
||||
bool allOk() const;
|
||||
|
||||
std::size_t passed = 0;
|
||||
std::size_t failed = 0;
|
||||
std::size_t failedButOk = 0;
|
||||
std::uint64_t passed = 0;
|
||||
std::uint64_t failed = 0;
|
||||
std::uint64_t failedButOk = 0;
|
||||
};
|
||||
|
||||
struct Totals {
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#define CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED
|
||||
|
||||
#include <catch2/interfaces/catch_interfaces_exception.hpp>
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/internal/catch_unique_name.hpp>
|
||||
|
||||
#include <exception>
|
||||
|
||||
@@ -46,8 +48,9 @@ namespace Catch {
|
||||
public:
|
||||
template<typename T>
|
||||
ExceptionTranslatorRegistrar( std::string(*translateFunction)( T const& ) ) {
|
||||
getMutableRegistryHub().registerTranslator
|
||||
( new ExceptionTranslator<T>( translateFunction ) );
|
||||
getMutableRegistryHub().registerTranslator(
|
||||
Detail::make_unique<ExceptionTranslator<T>>(translateFunction)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user