mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-16 10:05:39 +02:00
Compare commits
147 Commits
v3.0.0-pre
...
v2.13.2
Author | SHA1 | Date | |
---|---|---|---|
![]() |
87074da73e | ||
![]() |
e6f5e05ebc | ||
![]() |
44900d5371 | ||
![]() |
7c75ecaef4 | ||
![]() |
fba0feeba1 | ||
![]() |
3e8800beb1 | ||
![]() |
314a05d809 | ||
![]() |
eadf4e32b6 | ||
![]() |
f9620d11be | ||
![]() |
00db4fb497 | ||
![]() |
2fc83e7e9c | ||
![]() |
a2e5ce2418 | ||
![]() |
fd9f5ac661 | ||
![]() |
f0dc4d9be0 | ||
![]() |
284672cc84 | ||
![]() |
2b34b5c7d0 | ||
![]() |
708487d201 | ||
![]() |
6859c683e0 | ||
![]() |
de3a208e16 | ||
![]() |
229cc4823c | ||
![]() |
7f21cc6c55 | ||
![]() |
4c85248179 | ||
![]() |
b4e2237152 | ||
![]() |
40937b67c7 | ||
![]() |
0d5b131394 | ||
![]() |
ad3b90553b | ||
![]() |
b1c45652e5 | ||
![]() |
b79a83e4aa | ||
![]() |
89fe35d515 | ||
![]() |
115d6a1c40 | ||
![]() |
91576352f9 | ||
![]() |
6f7c191513 | ||
![]() |
4eb9d37e05 | ||
![]() |
53d8af8e96 | ||
![]() |
46fde0c597 | ||
![]() |
de103db696 | ||
![]() |
fedc3a7b7b | ||
![]() |
c299133a31 | ||
![]() |
09b8017ea3 | ||
![]() |
bad3c93049 | ||
![]() |
0f05c034c2 | ||
![]() |
ee4538c0c6 | ||
![]() |
dc7a20fc74 | ||
![]() |
018dc0b74f | ||
![]() |
ad1940f336 | ||
![]() |
5399921622 | ||
![]() |
e815acddf8 | ||
![]() |
e7189f1e4f | ||
![]() |
1806b21545 | ||
![]() |
288416f501 | ||
![]() |
cbbebb65b6 | ||
![]() |
fb08596b1b | ||
![]() |
0614a4acb3 | ||
![]() |
0f12995501 | ||
![]() |
0807fdb175 | ||
![]() |
9500ded83b | ||
![]() |
6c6ebe374a | ||
![]() |
b1b5cb8122 | ||
![]() |
77dc8cfc45 | ||
![]() |
ddc9f4c61d | ||
![]() |
bed47374ce | ||
![]() |
0e9bae1cdb | ||
![]() |
f133277910 | ||
![]() |
f764ee3d30 | ||
![]() |
c190061001 | ||
![]() |
b1dcdc5032 | ||
![]() |
f0e596e252 | ||
![]() |
594cab31ed | ||
![]() |
89f5f84351 | ||
![]() |
2e61d38c7c | ||
![]() |
5c9f09e94a | ||
![]() |
f4fc2dab2c | ||
![]() |
cfb6956698 | ||
![]() |
e59fc2c3b3 | ||
![]() |
4e4171420d | ||
![]() |
37cbf4a4fe | ||
![]() |
38f897c887 | ||
![]() |
fa4a93e051 | ||
![]() |
6fbe5efc71 | ||
![]() |
bad0fb51f8 | ||
![]() |
a2fc7cf8c0 | ||
![]() |
da9e3eec65 | ||
![]() |
f696ab836b | ||
![]() |
5d32ce26f4 | ||
![]() |
035a062596 | ||
![]() |
d399a308d0 | ||
![]() |
b8ce814ee6 | ||
![]() |
6260962108 | ||
![]() |
b4c8967ac5 | ||
![]() |
7900fb3abb | ||
![]() |
01bdfe3312 | ||
![]() |
e5c9a58d66 | ||
![]() |
255aa5f2af | ||
![]() |
3a33315ff8 | ||
![]() |
5f94c8dafb | ||
![]() |
695a356f93 | ||
![]() |
020b655635 | ||
![]() |
5561d0342d | ||
![]() |
3a15315a37 | ||
![]() |
b7b346c3e5 | ||
![]() |
9e09d79946 | ||
![]() |
7048c2c269 | ||
![]() |
6f77d59b16 | ||
![]() |
022b61ff92 | ||
![]() |
87b5bf77bc | ||
![]() |
81d52c4a5f | ||
![]() |
200b8b6fc0 | ||
![]() |
e70fd2a4b9 | ||
![]() |
36170d60ca | ||
![]() |
917e92c162 | ||
![]() |
f54950744f | ||
![]() |
b3b07215d1 | ||
![]() |
2652bb86e3 | ||
![]() |
1715b6b923 | ||
![]() |
f20a9dbc6e | ||
![]() |
273c3f85eb | ||
![]() |
6a3d0dc176 | ||
![]() |
ccb1f70629 | ||
![]() |
4a5bc0f39a | ||
![]() |
f96e89e016 | ||
![]() |
481f54b357 | ||
![]() |
2d172dc688 | ||
![]() |
587a20b312 | ||
![]() |
bff44f8b01 | ||
![]() |
4ea74ff966 | ||
![]() |
d10b9bd02e | ||
![]() |
55794e9b27 | ||
![]() |
fa6211bfc2 | ||
![]() |
4e90f910dc | ||
![]() |
0c59cc83cf | ||
![]() |
e4004e0adb | ||
![]() |
6c9a255dc2 | ||
![]() |
9a8963133f | ||
![]() |
cfba9dce97 | ||
![]() |
a537ccae22 | ||
![]() |
e1c9d5569d | ||
![]() |
d512decaac | ||
![]() |
f23f96883a | ||
![]() |
d7b8c3ace3 | ||
![]() |
32733e08c0 | ||
![]() |
930f49a641 | ||
![]() |
c409dccee5 | ||
![]() |
95bfb33167 | ||
![]() |
59d2d08c0f | ||
![]() |
fa6d52e2a3 | ||
![]() |
5ac348cd6e | ||
![]() |
776a4686c7 |
@@ -49,7 +49,7 @@ class BuilderSettings(object):
|
|||||||
def reference(self):
|
def reference(self):
|
||||||
""" Read project version from branch create Conan reference
|
""" Read project version from branch create Conan reference
|
||||||
"""
|
"""
|
||||||
return os.getenv("CONAN_REFERENCE", "catch2/{}".format(self._version))
|
return os.getenv("CONAN_REFERENCE", "Catch2/{}".format(self._version))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def channel(self):
|
def channel(self):
|
||||||
@@ -85,7 +85,7 @@ if __name__ == "__main__":
|
|||||||
reference=settings.reference,
|
reference=settings.reference,
|
||||||
channel=settings.channel,
|
channel=settings.channel,
|
||||||
upload=settings.upload,
|
upload=settings.upload,
|
||||||
upload_only_when_stable=False,
|
upload_only_when_stable=settings.upload_only_when_stable,
|
||||||
stable_branch_pattern=settings.stable_branch_pattern,
|
stable_branch_pattern=settings.stable_branch_pattern,
|
||||||
login_username=settings.login_username,
|
login_username=settings.login_username,
|
||||||
username=settings.username,
|
username=settings.username,
|
||||||
|
@@ -1,19 +1,11 @@
|
|||||||
cmake_minimum_required(VERSION 3.2.0)
|
cmake_minimum_required(VERSION 3.2.0)
|
||||||
project(test_package CXX)
|
project(test_package CXX)
|
||||||
|
|
||||||
# We set it only for the convenience of calling the executable
|
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
# in the package test function
|
conan_basic_setup(TARGETS)
|
||||||
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})
|
|
||||||
|
|
||||||
find_package(Catch2 REQUIRED CONFIG)
|
find_package(Catch2 REQUIRED CONFIG)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||||
# Note: Conan 1.21 doesn't support granular target generation yet.
|
target_link_libraries(${PROJECT_NAME} CONAN_PKG::Catch2)
|
||||||
# The Main library would be included into the unified target.
|
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
|
||||||
# It's controlled by the `with_main` option in the recipe.
|
|
||||||
target_link_libraries(${PROJECT_NAME} Catch2::Catch2)
|
|
||||||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 14)
|
|
||||||
|
@@ -6,7 +6,7 @@ import os
|
|||||||
|
|
||||||
class TestPackageConan(ConanFile):
|
class TestPackageConan(ConanFile):
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
settings = "os", "compiler", "build_type", "arch"
|
||||||
generators = "cmake_find_package_multi"
|
generators = "cmake"
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
cmake = CMake(self)
|
cmake = CMake(self)
|
||||||
@@ -14,6 +14,6 @@ class TestPackageConan(ConanFile):
|
|||||||
cmake.build()
|
cmake.build()
|
||||||
|
|
||||||
def test(self):
|
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")
|
bin_path = os.path.join("bin", "test_package")
|
||||||
self.run("%s -s" % bin_path, run_environment=True)
|
self.run("%s -s" % bin_path, run_environment=True)
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
#include <catch2/catch_test_macros.hpp>
|
#define CATCH_CONFIG_MAIN
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
int Factorial( int number ) {
|
int Factorial( int number ) {
|
||||||
return number <= 1 ? 1 : Factorial( number - 1 ) * number;
|
return number <= 1 ? 1 : Factorial( number - 1 ) * number;
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -29,4 +29,3 @@ cmake-build-*
|
|||||||
benchmark-dir
|
benchmark-dir
|
||||||
.conan/test_package/build
|
.conan/test_package/build
|
||||||
bazel-*
|
bazel-*
|
||||||
build-fuzzers
|
|
||||||
|
340
.travis.yml
340
.travis.yml
@@ -1,6 +1,4 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
dist: xenial
|
|
||||||
|
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
except:
|
except:
|
||||||
@@ -8,34 +6,42 @@ branches:
|
|||||||
|
|
||||||
common_sources: &all_sources
|
common_sources: &all_sources
|
||||||
- ubuntu-toolchain-r-test
|
- ubuntu-toolchain-r-test
|
||||||
- llvm-toolchain-xenial
|
- llvm-toolchain-trusty
|
||||||
- llvm-toolchain-xenial-3.8
|
- llvm-toolchain-trusty-3.9
|
||||||
- llvm-toolchain-xenial-3.9
|
- llvm-toolchain-trusty-4.0
|
||||||
- llvm-toolchain-xenial-4.0
|
|
||||||
- llvm-toolchain-xenial-5.0
|
- llvm-toolchain-xenial-5.0
|
||||||
- llvm-toolchain-xenial-6.0
|
- llvm-toolchain-xenial-6.0
|
||||||
- llvm-toolchain-xenial-7
|
|
||||||
- llvm-toolchain-xenial-8
|
|
||||||
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
# Clang builds
|
|
||||||
|
# 1/ Linux Clang Builds
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: *all_sources
|
sources: *all_sources
|
||||||
packages: ['clang-3.8']
|
packages: ['clang-3.5']
|
||||||
env: COMPILER='clang++-3.8' CPP14=1
|
env: COMPILER='clang++-3.5'
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: *all_sources
|
sources: *all_sources
|
||||||
packages: ['clang-3.8', 'lcov']
|
packages: ['clang-3.6']
|
||||||
env: COMPILER='clang++-3.8' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
env: COMPILER='clang++-3.6'
|
||||||
|
|
||||||
|
# Clang 3.7 is intentionally skipped as we cannot get it easily on
|
||||||
|
# TravisCI container
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['lcov', 'clang-3.8']
|
||||||
|
env: COMPILER='clang++-3.8'
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
@@ -43,7 +49,7 @@ matrix:
|
|||||||
apt:
|
apt:
|
||||||
sources: *all_sources
|
sources: *all_sources
|
||||||
packages: ['clang-3.9']
|
packages: ['clang-3.9']
|
||||||
env: COMPILER='clang++-3.9' CPP14=1
|
env: COMPILER='clang++-3.9'
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
@@ -51,25 +57,209 @@ matrix:
|
|||||||
apt:
|
apt:
|
||||||
sources: *all_sources
|
sources: *all_sources
|
||||||
packages: ['clang-4.0']
|
packages: ['clang-4.0']
|
||||||
env: COMPILER='clang++-4.0' CPP14=1
|
env: COMPILER='clang++-4.0'
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: *all_sources
|
sources: *all_sources
|
||||||
packages: ['clang-5.0']
|
packages: ['clang-5.0']
|
||||||
env: COMPILER='clang++-5.0' CPP14=1
|
env: COMPILER='clang++-5.0'
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['clang-6.0']
|
||||||
|
env: COMPILER='clang++-6.0'
|
||||||
|
|
||||||
|
# 2/ Linux GCC Builds
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['g++-4.8']
|
||||||
|
env: COMPILER='g++-4.8'
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['g++-4.9']
|
||||||
|
env: COMPILER='g++-4.9'
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['g++-5']
|
||||||
|
env: COMPILER='g++-5'
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: &gcc6
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['g++-6']
|
||||||
|
env: COMPILER='g++-6'
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: &gcc7
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['g++-7']
|
||||||
|
env: COMPILER='g++-7'
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: &gcc8
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['g++-8']
|
||||||
|
env: COMPILER='g++-8'
|
||||||
|
|
||||||
|
# 3b/ Linux C++14 Clang builds
|
||||||
|
# Note that we need newer libstdc++ for C++14 support
|
||||||
|
- os: linux
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages: ['clang-3.8', 'libstdc++-6-dev']
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
- llvm-toolchain-trusty
|
||||||
|
env: COMPILER='clang++-3.8' CPP14=1
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: *all_sources
|
sources: *all_sources
|
||||||
packages: ['clang-6.0']
|
packages: ['clang-3.9', 'libstdc++-6-dev']
|
||||||
env: COMPILER='clang++-6.0' CPP14=1
|
env: COMPILER='clang++-3.9' CPP14=1
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['clang-4.0', 'libstdc++-6-dev']
|
||||||
|
env: COMPILER='clang++-4.0' CPP14=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['clang-5.0', 'libstdc++-6-dev']
|
||||||
|
env: COMPILER='clang++-5.0' CPP14=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['clang-6.0', 'libstdc++-6-dev']
|
||||||
|
env: COMPILER='clang++-6.0' CPP14=1
|
||||||
|
|
||||||
|
|
||||||
|
# 4a/ Linux C++14 GCC builds
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: *gcc6
|
||||||
|
env: COMPILER='g++-6' CPP14=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: *gcc7
|
||||||
|
env: COMPILER='g++-7' CPP14=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: *gcc8
|
||||||
|
env: COMPILER='g++-8' CPP14=1
|
||||||
|
|
||||||
|
# 5/ OSX Clang Builds
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode7.3
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER='clang++'
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode8
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER='clang++'
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode9
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER='clang++'
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode9.1
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER='clang++'
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode9.1
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER='clang++' CPP14=1
|
||||||
|
|
||||||
|
# 6/ Special builds -- examples, coverage, valgrind, etc.
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['lcov', 'g++-7']
|
||||||
|
env: COMPILER='g++-7' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: clang
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages: ['clang-3.8', 'lcov']
|
||||||
|
sources:
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
- llvm-toolchain-trusty
|
||||||
|
env: COMPILER='clang++-3.8' EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources: *all_sources
|
||||||
|
packages: ['valgrind', 'lcov', 'g++-7']
|
||||||
|
env: COMPILER='g++-7' CPP14=1 VALGRIND=1
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
osx_image: xcode9.1
|
||||||
|
compiler: clang
|
||||||
|
env: COMPILER='clang++' CPP14=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||||
|
|
||||||
|
# 7/ C++17 builds
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: *gcc7
|
||||||
|
env: COMPILER='g++-7' CPP17=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
addons: *gcc7
|
||||||
|
env: COMPILER='g++-7' EXAMPLES=1 COVERAGE=1 EXTRAS=1 CPP17=1
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
@@ -78,108 +268,44 @@ matrix:
|
|||||||
env: COMPILER='clang++-6.0' CPP17=1
|
env: COMPILER='clang++-6.0' CPP17=1
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
|
dist: xenial
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
sources: *all_sources
|
sources: *all_sources
|
||||||
packages: ['clang-7']
|
packages: ['clang-6.0', 'libstdc++-8-dev']
|
||||||
env: COMPILER='clang++-7' CPP14=1
|
env: COMPILER='clang++-6.0' CPP17=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||||
|
|
||||||
- os: linux
|
# 8/ Conan
|
||||||
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
|
- language: python
|
||||||
python:
|
python:
|
||||||
- "3.7"
|
- "3.7"
|
||||||
|
dist: xenial
|
||||||
install:
|
install:
|
||||||
- pip install conan-package-tools
|
- pip install conan-package-tools
|
||||||
env:
|
env:
|
||||||
- CONAN_GCC_VERSIONS=8
|
- CONAN_GCC_VERSIONS=8
|
||||||
- CONAN_DOCKER_IMAGE=conanio/gcc8
|
- CONAN_DOCKER_IMAGE=conanio/gcc8
|
||||||
- CPP14=1
|
|
||||||
script:
|
script:
|
||||||
- python .conan/build.py
|
- python .conan/build.py
|
||||||
|
|
||||||
|
install:
|
||||||
|
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
|
||||||
|
- mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR}
|
||||||
|
- |
|
||||||
|
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
|
||||||
|
CMAKE_URL="http://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.tar.gz"
|
||||||
|
mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake
|
||||||
|
export PATH=${DEPS_DIR}/cmake/bin:${PATH}
|
||||||
|
elif [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
|
||||||
|
which cmake || brew install cmake;
|
||||||
|
fi
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- export CXX=${COMPILER}
|
- export CXX=${COMPILER}
|
||||||
- cd ${TRAVIS_BUILD_DIR}
|
- cd ${TRAVIS_BUILD_DIR}
|
||||||
# We want to regenerate the amalgamated header if the extra tests
|
# Regenerate single header file, so it is tested in the examples...
|
||||||
# are enabled.
|
- python scripts/generateSingleHeader.py
|
||||||
- |
|
|
||||||
if [[ ${EXTRAS} -eq 1 ]]; then
|
|
||||||
python3 ./tools/scripts/generateAmalgamatedFiles.py
|
|
||||||
fi
|
|
||||||
|
|
||||||
- |
|
- |
|
||||||
if [[ ${CPP17} -eq 1 ]]; then
|
if [[ ${CPP17} -eq 1 ]]; then
|
||||||
@@ -187,13 +313,13 @@ before_script:
|
|||||||
elif [[ ${CPP14} -eq 1 ]]; then
|
elif [[ ${CPP14} -eq 1 ]]; then
|
||||||
export CPP_STANDARD=14
|
export CPP_STANDARD=14
|
||||||
else
|
else
|
||||||
travis_terminate 4;
|
export CPP_STANDARD=11
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use Debug builds for running Valgrind and building examples
|
# 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
|
- 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
|
||||||
# Don't bother with release build for coverage build
|
# 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
|
- cmake -H. -BBuild-Release -DCMAKE_BUILD_TYPE=Release -Wdev -DCMAKE_CXX_STANDARD=${CPP_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=On -DCMAKE_CXX_EXTENSIONS=OFF
|
||||||
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
25
BUILD.bazel
25
BUILD.bazel
@@ -1,25 +1,10 @@
|
|||||||
# Load the cc_library rule.
|
# Load the cc_library rule.
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||||
|
|
||||||
# Static library, without main.
|
# Header-only rule to export catch2/catch.hpp.
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "catch2",
|
name = "catch2",
|
||||||
hdrs = glob(["src/catch2/**/*.hpp"]),
|
hdrs = ["single_include/catch2/catch.hpp"],
|
||||||
srcs = glob(["src/catch2/**/*.cpp"],
|
visibility = ["//visibility:public"],
|
||||||
exclude=[ "src/catch2/internal/catch_main.cpp"]),
|
includes = ["single_include/"],
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
copts = ["-std=c++14"],
|
|
||||||
linkstatic = True,
|
|
||||||
includes = ["src/"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Static library, with main.
|
|
||||||
cc_library(
|
|
||||||
name = "catch2_main",
|
|
||||||
srcs = ["src/catch2/internal/catch_main.cpp"],
|
|
||||||
deps = [":catch2"],
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
linkstatic = True,
|
|
||||||
copts = ["-std=c++14"],
|
|
||||||
includes = ["src/"],
|
|
||||||
)
|
)
|
||||||
|
@@ -1,78 +1,26 @@
|
|||||||
include(CheckCXXCompilerFlag)
|
#checks that the given hard-coded list contains all headers + sources in the given folder
|
||||||
function(add_cxx_flag_if_supported_to_targets flagname targets)
|
function(CheckFileList LIST_VAR FOLDER)
|
||||||
check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flagname})
|
set(MESSAGE " should be added to the variable ${LIST_VAR}")
|
||||||
|
set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
|
||||||
if (HAVE_FLAG_${flagname})
|
file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp"
|
||||||
foreach(target ${targets})
|
"${FOLDER}/*.hpp"
|
||||||
target_compile_options(${target} PUBLIC ${flagname})
|
"${FOLDER}/*.h")
|
||||||
endforeach()
|
list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
|
||||||
endif()
|
foreach(EXTRA_ITEM ${GLOBBED_LIST})
|
||||||
|
string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
|
||||||
|
message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
|
||||||
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# Assumes that it is only called for development builds, where warnings
|
function(CheckFileListRec LIST_VAR FOLDER)
|
||||||
# and Werror is desired, so it also enables Werror.
|
set(MESSAGE " should be added to the variable ${LIST_VAR}")
|
||||||
function(add_warnings_to_targets targets)
|
set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
|
||||||
LIST(LENGTH targets TARGETS_LEN)
|
file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp"
|
||||||
# For now we just assume 2 possibilities: msvc and msvc-like compilers,
|
"${FOLDER}/*.hpp"
|
||||||
# and other.
|
"${FOLDER}/*.h")
|
||||||
if (MSVC)
|
list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
|
||||||
foreach(target ${targets})
|
foreach(EXTRA_ITEM ${GLOBBED_LIST})
|
||||||
# Force MSVC to consider everything as encoded in utf-8
|
string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}")
|
||||||
target_compile_options( ${target} PRIVATE /utf-8 )
|
message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}")
|
||||||
# Enable Werror equivalent
|
endforeach()
|
||||||
if (CATCH_ENABLE_WERROR)
|
|
||||||
target_compile_options( ${target} PRIVATE /WX )
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# MSVC is currently handled specially
|
|
||||||
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
|
||||||
STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level
|
|
||||||
target_compile_options( ${target} PRIVATE /w44265 /w44061 /w44062 /w45038 )
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (NOT MSVC)
|
|
||||||
set(CHECKED_WARNING_FLAGS
|
|
||||||
"-Wall"
|
|
||||||
"-Wextra"
|
|
||||||
"-Wpedantic"
|
|
||||||
"-Wweak-vtables"
|
|
||||||
"-Wunreachable-code"
|
|
||||||
"-Wmissing-declarations"
|
|
||||||
"-Wexit-time-destructors"
|
|
||||||
"-Wglobal-constructors"
|
|
||||||
"-Wmissing-noreturn"
|
|
||||||
"-Wparentheses"
|
|
||||||
"-Wextra-semi-stmt"
|
|
||||||
"-Wunreachable-code"
|
|
||||||
"-Wstrict-aliasing"
|
|
||||||
"-Wreturn-std-move"
|
|
||||||
"-Wmissing-braces"
|
|
||||||
"-Wdeprecated"
|
|
||||||
"-Wvla"
|
|
||||||
"-Wundef"
|
|
||||||
"-Wmisleading-indentation"
|
|
||||||
"-Wcatch-value"
|
|
||||||
"-Wabsolute-value"
|
|
||||||
"-Wreturn-std-move"
|
|
||||||
"-Wunused-parameter"
|
|
||||||
"-Wunused-function"
|
|
||||||
"-Wcall-to-pure-virtual-from-ctor-dtor"
|
|
||||||
"-Wdeprecated-register"
|
|
||||||
"-Wsuggest-override"
|
|
||||||
"-Wshadow"
|
|
||||||
)
|
|
||||||
foreach(warning ${CHECKED_WARNING_FLAGS})
|
|
||||||
add_cxx_flag_if_supported_to_targets(${warning} "${targets}")
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
if (CATCH_ENABLE_WERROR)
|
|
||||||
foreach(target ${targets})
|
|
||||||
# Enable Werror equivalent
|
|
||||||
target_compile_options( ${target} PRIVATE -Werror )
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
@@ -1,10 +0,0 @@
|
|||||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
|
||||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
|
||||||
pkg_version=@Catch2_VERSION@
|
|
||||||
|
|
||||||
Name: Catch2-With-Main
|
|
||||||
Description: A modern, C++-native test framework for C++14 and above (links in default main)
|
|
||||||
Version: ${pkg_version}
|
|
||||||
Requires: catch2 = ${pkg_version}
|
|
||||||
Cflags: -I${includedir}
|
|
||||||
Libs: -L${libdir} -lCatch2WithMain
|
|
@@ -1,9 +1,7 @@
|
|||||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||||
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
|
||||||
|
|
||||||
Name: Catch2
|
Name: Catch2
|
||||||
Description: A modern, C++-native, test framework for C++14 and above
|
Description: A modern, C++-native, header-only, test framework for C++11
|
||||||
URL: https://github.com/catchorg/Catch2
|
URL: https://github.com/catchorg/Catch2
|
||||||
Version: @Catch2_VERSION@
|
Version: @Catch2_VERSION@
|
||||||
Cflags: -I${includedir}
|
Cflags: -I${includedir}
|
||||||
Libs: -L${libdir} -lCatch2
|
|
||||||
|
201
CMakeLists.txt
201
CMakeLists.txt
@@ -3,21 +3,9 @@ cmake_minimum_required(VERSION 3.5)
|
|||||||
# detect if Catch is being bundled,
|
# detect if Catch is being bundled,
|
||||||
# disable testsuite in that case
|
# disable testsuite in that case
|
||||||
if(NOT DEFINED PROJECT_NAME)
|
if(NOT DEFINED PROJECT_NAME)
|
||||||
set(NOT_SUBPROJECT ON)
|
set(NOT_SUBPROJECT ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
|
|
||||||
option(CATCH_INSTALL_EXTRAS "Install extras alongside library" ON)
|
|
||||||
option(CATCH_DEVELOPMENT_BUILD "Build tests, enable warnings, enable Werror, etc" OFF)
|
|
||||||
|
|
||||||
include(CMakeDependentOption)
|
|
||||||
cmake_dependent_option(CATCH_BUILD_TESTING "Build the SelfTest project" ON "CATCH_DEVELOPMENT_BUILD" OFF)
|
|
||||||
cmake_dependent_option(CATCH_BUILD_EXAMPLES "Build code examples" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
|
||||||
cmake_dependent_option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
|
||||||
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)
|
|
||||||
|
|
||||||
# Catch2's build breaks if done in-tree. You probably should not build
|
# 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
|
# things in tree anyway, but we can allow projects that include Catch2
|
||||||
# as a subproject to build in-tree as long as it is not in our tree.
|
# as a subproject to build in-tree as long as it is not in our tree.
|
||||||
@@ -26,44 +14,43 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
project(Catch2 LANGUAGES CXX VERSION 3.0.0)
|
project(Catch2 LANGUAGES CXX VERSION 2.13.2)
|
||||||
|
|
||||||
# Provide path for scripts
|
# Provide path for scripts
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
include(CMakePackageConfigHelpers)
|
|
||||||
include(CTest)
|
|
||||||
|
|
||||||
# This variable is used in some subdirectories, so we need it here, rather
|
option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
|
||||||
# than later in the install block
|
option(CATCH_BUILD_TESTING "Build SelfTest project" ON)
|
||||||
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
|
option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF)
|
||||||
|
option(CATCH_BUILD_EXTRA_TESTS "Build extra tests" OFF)
|
||||||
|
option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF)
|
||||||
|
option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON)
|
||||||
|
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
|
||||||
|
option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON)
|
||||||
|
|
||||||
# We have some Windows builds that test `wmain` entry point,
|
|
||||||
# and we need this change to be present in all binaries that
|
# define some folders
|
||||||
# are built during these tests, so this is required here, before
|
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
# the subdirectories are added.
|
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
||||||
if(CATCH_TEST_USE_WMAIN)
|
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
|
||||||
|
set(HEADER_DIR ${CATCH_DIR}/include)
|
||||||
|
|
||||||
|
if(USE_WMAIN)
|
||||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(NOT_SUBPROJECT)
|
||||||
# Basic paths
|
include(CTest)
|
||||||
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
set(SOURCES_DIR ${CATCH_DIR}/src/catch2)
|
if(BUILD_TESTING AND CATCH_BUILD_TESTING)
|
||||||
set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest)
|
find_package(PythonInterp)
|
||||||
set(BENCHMARK_DIR ${CATCH_DIR}/tests/Benchmark)
|
if (NOT PYTHONINTERP_FOUND)
|
||||||
set(EXAMPLES_DIR ${CATCH_DIR}/examples)
|
message(FATAL_ERROR "Python not found, but required for tests")
|
||||||
|
endif()
|
||||||
# We need to bring-in the variables defined there to this scope
|
add_subdirectory(projects)
|
||||||
add_subdirectory(src)
|
|
||||||
|
|
||||||
# Build tests only if requested
|
|
||||||
if (BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
|
|
||||||
find_package(PythonInterp 3 REQUIRED)
|
|
||||||
if (NOT PYTHONINTERP_FOUND)
|
|
||||||
message(FATAL_ERROR "Python not found, but required for tests")
|
|
||||||
endif()
|
endif()
|
||||||
add_subdirectory(tests)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CATCH_BUILD_EXAMPLES)
|
if(CATCH_BUILD_EXAMPLES)
|
||||||
@@ -71,31 +58,58 @@ if(CATCH_BUILD_EXAMPLES)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CATCH_BUILD_EXTRA_TESTS)
|
if(CATCH_BUILD_EXTRA_TESTS)
|
||||||
add_subdirectory(tests/ExtraTests)
|
add_subdirectory(projects/ExtraTests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CATCH_BUILD_FUZZERS)
|
# add catch as a 'linkable' target
|
||||||
add_subdirectory(fuzzing)
|
add_library(Catch2 INTERFACE)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# depend on some obvious c++11 features so the dependency is transitively added dependents
|
||||||
|
target_compile_features(Catch2
|
||||||
|
INTERFACE
|
||||||
|
cxx_alignas
|
||||||
|
cxx_alignof
|
||||||
|
cxx_attributes
|
||||||
|
cxx_auto_type
|
||||||
|
cxx_constexpr
|
||||||
|
cxx_defaulted_functions
|
||||||
|
cxx_deleted_functions
|
||||||
|
cxx_final
|
||||||
|
cxx_lambdas
|
||||||
|
cxx_noexcept
|
||||||
|
cxx_override
|
||||||
|
cxx_range_for
|
||||||
|
cxx_rvalue_references
|
||||||
|
cxx_static_assert
|
||||||
|
cxx_strong_enums
|
||||||
|
cxx_trailing_return_types
|
||||||
|
cxx_unicode_literals
|
||||||
|
cxx_user_literals
|
||||||
|
cxx_variadic_macros
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(Catch2
|
||||||
|
INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/single_include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||||
|
)
|
||||||
|
|
||||||
|
if (ANDROID)
|
||||||
|
target_link_libraries(Catch2 INTERFACE log)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (CATCH_DEVELOPMENT_BUILD)
|
# provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
|
||||||
add_warnings_to_targets("${CATCH_WARNING_TARGETS}")
|
add_library(Catch2::Catch2 ALIAS Catch2)
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
#option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
|
|
||||||
#option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON)
|
|
||||||
#
|
|
||||||
#set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# Only perform the installation steps when Catch is not being used as
|
# Only perform the installation steps when Catch is not being used as
|
||||||
# a subproject via `add_subdirectory`, or the destinations will break,
|
# a subproject via `add_subdirectory`, or the destinations will break,
|
||||||
# see https://github.com/catchorg/Catch2/issues/1373
|
# see https://github.com/catchorg/Catch2/issues/1373
|
||||||
if (NOT_SUBPROJECT)
|
if (NOT_SUBPROJECT)
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
|
||||||
|
|
||||||
configure_package_config_file(
|
configure_package_config_file(
|
||||||
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
|
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
|
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
|
||||||
@@ -103,8 +117,26 @@ if (NOT_SUBPROJECT)
|
|||||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||||
)
|
)
|
||||||
|
|
||||||
## TODO: Catch2 main target?
|
|
||||||
## Install some cpp file as well?
|
# create and install an export set for catch target as Catch2::Catch
|
||||||
|
install(
|
||||||
|
TARGETS
|
||||||
|
Catch2
|
||||||
|
EXPORT
|
||||||
|
Catch2Targets
|
||||||
|
DESTINATION
|
||||||
|
${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT
|
||||||
|
Catch2Targets
|
||||||
|
NAMESPACE
|
||||||
|
Catch2::
|
||||||
|
DESTINATION
|
||||||
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||||
|
)
|
||||||
|
|
||||||
# By default, FooConfigVersion is tied to architecture that it was
|
# By default, FooConfigVersion is tied to architecture that it was
|
||||||
# generated on. Because Catch2 is header-only, it is arch-independent
|
# generated on. Because Catch2 is header-only, it is arch-independent
|
||||||
@@ -125,6 +157,13 @@ if (NOT_SUBPROJECT)
|
|||||||
)
|
)
|
||||||
set(CMAKE_SIZEOF_VOID_P ${CATCH2_CMAKE_SIZEOF_VOID_P})
|
set(CMAKE_SIZEOF_VOID_P ${CATCH2_CMAKE_SIZEOF_VOID_P})
|
||||||
|
|
||||||
|
install(
|
||||||
|
DIRECTORY
|
||||||
|
"single_include/"
|
||||||
|
DESTINATION
|
||||||
|
"${CMAKE_INSTALL_INCLUDEDIR}"
|
||||||
|
)
|
||||||
|
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
|
||||||
@@ -143,25 +182,25 @@ if (NOT_SUBPROJECT)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CATCH_INSTALL_EXTRAS)
|
if(CATCH_INSTALL_HELPERS)
|
||||||
# Install CMake scripts
|
# Install CMake scripts
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
"extras/ParseAndAddCatchTests.cmake"
|
"contrib/ParseAndAddCatchTests.cmake"
|
||||||
"extras/Catch.cmake"
|
"contrib/Catch.cmake"
|
||||||
"extras/CatchAddTests.cmake"
|
"contrib/CatchAddTests.cmake"
|
||||||
DESTINATION
|
DESTINATION
|
||||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||||
)
|
)
|
||||||
|
|
||||||
# Install debugger helpers
|
# Install debugger helpers
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
"extras/gdbinit"
|
"contrib/gdbinit"
|
||||||
"extras/lldbinit"
|
"contrib/lldbinit"
|
||||||
DESTINATION
|
DESTINATION
|
||||||
${CMAKE_INSTALL_DATAROOTDIR}/Catch2
|
${CMAKE_INSTALL_DATAROOTDIR}/Catch2
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Provide some pkg-config integration
|
## Provide some pkg-config integration
|
||||||
@@ -174,15 +213,9 @@ if (NOT_SUBPROJECT)
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
|
${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
|
||||||
@ONLY
|
@ONLY
|
||||||
)
|
)
|
||||||
configure_file(
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc
|
|
||||||
@ONLY
|
|
||||||
)
|
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
|
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/catch2-with-main.pc"
|
|
||||||
DESTINATION
|
DESTINATION
|
||||||
${PKGCONFIG_INSTALL_DIR}
|
${PKGCONFIG_INSTALL_DIR}
|
||||||
)
|
)
|
||||||
|
12
README.md
12
README.md
@@ -1,15 +1,16 @@
|
|||||||
<a id="top"></a>
|
<a id="top"></a>
|
||||||

|

|
||||||
|
|
||||||
[](https://github.com/catchorg/catch2/releases)
|
[](https://github.com/catchorg/catch2/releases)
|
||||||
[](https://travis-ci.org/catchorg/Catch2)
|
[](https://travis-ci.org/catchorg/Catch2)
|
||||||
[](https://ci.appveyor.com/project/catchorg/catch2)
|
[](https://ci.appveyor.com/project/catchorg/catch2)
|
||||||
[](https://codecov.io/gh/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/6JUH8Eybx4CtvkJS)
|
||||||
<!-- [](https://wandbox.org/permlink/LzYWgcPrcy9yQmed) -->
|
|
||||||
[](https://discord.gg/4CWS9zD)
|
[](https://discord.gg/4CWS9zD)
|
||||||
|
|
||||||
|
|
||||||
|
<a href="https://github.com/catchorg/Catch2/releases/download/v2.13.2/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
|
||||||
|
|
||||||
## Catch2 is released!
|
## Catch2 is released!
|
||||||
|
|
||||||
If you've been using an earlier version of Catch, please see the
|
If you've been using an earlier version of Catch, please see the
|
||||||
@@ -18,7 +19,10 @@ before moving to Catch2. You might also like to read [this blog post](https://le
|
|||||||
|
|
||||||
## What's the Catch?
|
## What's the Catch?
|
||||||
|
|
||||||
Catch2 is a multi-paradigm test framework for C++.
|
Catch2 is a multi-paradigm test framework for C++. which also supports
|
||||||
|
Objective-C (and maybe C).
|
||||||
|
It is primarily distributed as a single header file, although certain
|
||||||
|
extensions may require additional headers.
|
||||||
|
|
||||||
## How to use it
|
## How to use it
|
||||||
This documentation comprises these three parts:
|
This documentation comprises these three parts:
|
||||||
|
169
appveyor.yml
169
appveyor.yml
@@ -1,34 +1,93 @@
|
|||||||
version: "{build}-{branch}"
|
# version string format -- This will be overwritten later anyway
|
||||||
|
version: "{build}"
|
||||||
|
|
||||||
|
# We need a more up to date pip because Python 2.7 is EOL soon
|
||||||
|
init:
|
||||||
|
- set PATH=C:\Python35\Scripts;%PATH%
|
||||||
|
|
||||||
# If we ever get a backlog larger than clone_depth, builds will fail
|
|
||||||
# spuriously. I do not think we will ever get 20 deep commits deep though.
|
|
||||||
clone_depth: 20
|
|
||||||
|
|
||||||
# We want to build everything, except for branches that are explicitly
|
|
||||||
# for messing around with travis.
|
|
||||||
branches:
|
branches:
|
||||||
except:
|
except:
|
||||||
- /dev-travis.+/
|
- /dev-travis.+/
|
||||||
|
|
||||||
|
os:
|
||||||
|
- Visual Studio 2017
|
||||||
|
- Visual Studio 2015
|
||||||
|
|
||||||
# We need a more up to date pip because Python 2.7 is EOL soon
|
environment:
|
||||||
init:
|
matrix:
|
||||||
- set PATH=C:\Python35;C:\Python35\Scripts;%PATH%
|
- additional_flags: "/permissive- /std:c++latest"
|
||||||
|
wmain: 0
|
||||||
|
|
||||||
|
- additional_flags: ""
|
||||||
|
wmain: 0
|
||||||
|
|
||||||
|
- additional_flags: "/D_UNICODE /DUNICODE"
|
||||||
|
wmain: 1
|
||||||
|
coverage: 0
|
||||||
|
|
||||||
|
# Have a coverage dimension
|
||||||
|
- additional_flags: ""
|
||||||
|
wmain: 0
|
||||||
|
coverage: 1
|
||||||
|
|
||||||
|
# Have an examples dimension
|
||||||
|
- additional_flags: ""
|
||||||
|
wmain: 0
|
||||||
|
examples: 1
|
||||||
|
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
exclude:
|
||||||
|
- os: Visual Studio 2015
|
||||||
|
additional_flags: "/permissive- /std:c++latest"
|
||||||
|
|
||||||
|
- os: Visual Studio 2015
|
||||||
|
additional_flags: "/D_UNICODE /DUNICODE"
|
||||||
|
|
||||||
|
# Exclude unwanted coverage configurations
|
||||||
|
- coverage: 1
|
||||||
|
platform: Win32
|
||||||
|
|
||||||
|
- coverage: 1
|
||||||
|
os: Visual Studio 2015
|
||||||
|
|
||||||
|
- coverage: 1
|
||||||
|
configuration: Release
|
||||||
|
|
||||||
|
# Exclude unwanted examples configurations
|
||||||
|
- examples: 1
|
||||||
|
platform: Win32
|
||||||
|
|
||||||
|
- examples: 1
|
||||||
|
os: Visual Studio 2015
|
||||||
|
|
||||||
|
- examples: 1
|
||||||
|
configuration: Release
|
||||||
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { pip --disable-pip-version-check install codecov }
|
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { pip --disable-pip-version-check install codecov }
|
||||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { .\tools\misc\installOpenCppCoverage.ps1 }
|
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { .\misc\installOpenCppCoverage.ps1 }
|
||||||
|
|
||||||
|
# Win32 and x64 are CMake-compatible solution platform names.
|
||||||
|
# This allows us to pass %PLATFORM% to CMake -A.
|
||||||
|
platform:
|
||||||
|
- Win32
|
||||||
|
- x64
|
||||||
|
|
||||||
|
# build Configurations, i.e. Debug, Release, etc.
|
||||||
|
configuration:
|
||||||
|
- Debug
|
||||||
|
- Release
|
||||||
|
|
||||||
|
#Cmake will autodetect the compiler, but we set the arch
|
||||||
before_build:
|
before_build:
|
||||||
- set CXXFLAGS=%additional_flags%
|
- 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 )
|
|
||||||
# Indirection because appveyor doesn't handle multiline batch scripts properly
|
# Indirection because appveyor doesn't handle multiline batch scripts properly
|
||||||
# https://stackoverflow.com/questions/37627248/how-to-split-a-command-over-multiple-lines-in-appveyor-yml/37647169#37647169
|
# https://stackoverflow.com/questions/37627248/how-to-split-a-command-over-multiple-lines-in-appveyor-yml/37647169#37647169
|
||||||
# https://help.appveyor.com/discussions/questions/3888-multi-line-cmd-or-powershell-warning-ignore
|
# https://help.appveyor.com/discussions/questions/3888-multi-line-cmd-or-powershell-warning-ignore
|
||||||
- cmd: .\tools\misc\appveyorBuildConfigurationScript.bat
|
- cmd: .\misc\appveyorBuildConfigurationScript.bat
|
||||||
|
|
||||||
|
|
||||||
# build with MSBuild
|
# build with MSBuild
|
||||||
@@ -39,86 +98,4 @@ build:
|
|||||||
|
|
||||||
test_script:
|
test_script:
|
||||||
- set CTEST_OUTPUT_ON_FAILURE=1
|
- set CTEST_OUTPUT_ON_FAILURE=1
|
||||||
- cmd: .\tools\misc\appveyorTestRunScript.bat
|
- cmd: .\misc\appveyorTestRunScript.bat
|
||||||
|
|
||||||
|
|
||||||
# Sadly we cannot use the standard "dimensions" based approach towards
|
|
||||||
# specifying the different builds, as there is no way to add one-offs
|
|
||||||
# builds afterwards. This means that we will painfully specify each
|
|
||||||
# build explicitly.
|
|
||||||
environment:
|
|
||||||
matrix:
|
|
||||||
- FLAVOR: VS 2019 x64 Debug
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
|
||||||
platform: x64
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2019 x64 Release
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
|
||||||
platform: x64
|
|
||||||
configuration: Release
|
|
||||||
|
|
||||||
- FLAVOR: VS 2019 x64 Debug Coverage Examples
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
|
||||||
examples: 1
|
|
||||||
coverage: 1
|
|
||||||
platform: x64
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2019 x64 Debug WMain
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
|
||||||
wmain: 1
|
|
||||||
additional_flags: "/D_UNICODE /DUNICODE"
|
|
||||||
platform: x64
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2019 Win32 Debug
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
|
||||||
platform: Win32
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2019 x64 Debug Latest Strict
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
|
||||||
additional_flags: "/permissive- /std:c++latest"
|
|
||||||
platform: x64
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2017 x64 Debug
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
platform: x64
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2017 x64 Release
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
platform: x64
|
|
||||||
configuration: Release
|
|
||||||
|
|
||||||
- FLAVOR: VS 2017 x64 Release Coverage
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
coverage: 1
|
|
||||||
platform: x64
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2017 Win32 Debug
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
platform: Win32
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2017 Win32 Debug Examples
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
examples: 1
|
|
||||||
platform: Win32
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2017 Win32 Debug WMain
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
wmain: 1
|
|
||||||
additional_flags: "/D_UNICODE /DUNICODE"
|
|
||||||
platform: Win32
|
|
||||||
configuration: Debug
|
|
||||||
|
|
||||||
- FLAVOR: VS 2017 x64 Debug Latest Strict
|
|
||||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
additional_flags: "/permissive- /std:c++latest"
|
|
||||||
platform: x64
|
|
||||||
configuration: Debug
|
|
||||||
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
@@ -10,13 +10,16 @@ coverage:
|
|||||||
default:
|
default:
|
||||||
target: 80%
|
target: 80%
|
||||||
ignore:
|
ignore:
|
||||||
|
- "projects/SelfTest"
|
||||||
|
- "**/catch_reporter_tap.hpp"
|
||||||
|
- "**/catch_reporter_automake.hpp"
|
||||||
|
- "**/catch_reporter_teamcity.hpp"
|
||||||
|
- "**/catch_reporter_sonarqube.hpp"
|
||||||
- "**/external/clara.hpp"
|
- "**/external/clara.hpp"
|
||||||
- "tests"
|
|
||||||
|
|
||||||
|
|
||||||
codecov:
|
codecov:
|
||||||
branch: master
|
branch: master
|
||||||
max_report_age: off
|
|
||||||
|
|
||||||
comment:
|
comment:
|
||||||
layout: "diff"
|
layout: "diff"
|
||||||
|
37
conanfile.py
37
conanfile.py
@@ -3,43 +3,28 @@ from conans import ConanFile, CMake
|
|||||||
|
|
||||||
|
|
||||||
class CatchConan(ConanFile):
|
class CatchConan(ConanFile):
|
||||||
name = "catch2"
|
name = "Catch2"
|
||||||
description = "A modern, C++-native, framework for unit-tests, TDD and BDD"
|
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
|
||||||
topics = ("conan", "catch2", "unit-test", "tdd", "bdd")
|
topics = ("conan", "catch2", "header-only", "unit-test", "tdd", "bdd")
|
||||||
url = "https://github.com/catchorg/Catch2"
|
url = "https://github.com/catchorg/Catch2"
|
||||||
homepage = url
|
homepage = url
|
||||||
license = "BSL-1.0"
|
license = "BSL-1.0"
|
||||||
|
|
||||||
exports = "LICENSE.txt"
|
exports = "LICENSE.txt"
|
||||||
exports_sources = ("src/*", "CMakeLists.txt", "CMake/*", "extras/*")
|
exports_sources = ("single_include/*", "CMakeLists.txt", "CMake/*", "contrib/*")
|
||||||
|
generators = "cmake"
|
||||||
|
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
def package(self):
|
||||||
|
|
||||||
options = {"with_main": [True, False]}
|
|
||||||
default_options = {"with_main": True}
|
|
||||||
|
|
||||||
def _configure_cmake(self):
|
|
||||||
cmake = CMake(self)
|
cmake = CMake(self)
|
||||||
cmake.definitions["BUILD_TESTING"] = "OFF"
|
cmake.definitions["BUILD_TESTING"] = "OFF"
|
||||||
cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF"
|
cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF"
|
||||||
cmake.definitions["CATCH_INSTALL_HELPERS"] = "ON"
|
cmake.definitions["CATCH_INSTALL_HELPERS"] = "ON"
|
||||||
cmake.configure(build_folder="build")
|
cmake.configure(build_folder='build')
|
||||||
return cmake
|
|
||||||
|
|
||||||
def build(self):
|
|
||||||
cmake = self._configure_cmake()
|
|
||||||
cmake.build()
|
|
||||||
|
|
||||||
def package(self):
|
|
||||||
self.copy(pattern="LICENSE.txt", dst="licenses")
|
|
||||||
cmake = self._configure_cmake()
|
|
||||||
cmake.install()
|
cmake.install()
|
||||||
|
|
||||||
|
self.copy(pattern="LICENSE.txt", dst="licenses")
|
||||||
|
|
||||||
def package_id(self):
|
def package_id(self):
|
||||||
del self.info.options.with_main
|
self.info.header_only()
|
||||||
|
|
||||||
def package_info(self):
|
def package_info(self):
|
||||||
self.cpp_info.libs = [
|
self.cpp_info.builddirs.append("lib/cmake/Catch2")
|
||||||
'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"
|
|
||||||
|
@@ -33,12 +33,17 @@ if(NOT EXISTS "${TEST_EXECUTABLE}")
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-tests --verbosity quiet
|
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only
|
||||||
OUTPUT_VARIABLE output
|
OUTPUT_VARIABLE output
|
||||||
RESULT_VARIABLE result
|
RESULT_VARIABLE result
|
||||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||||
)
|
)
|
||||||
if(NOT ${result} EQUAL 0)
|
# Catch --list-test-names-only reports the number of tests, so 0 is... surprising
|
||||||
|
if(${result} EQUAL 0)
|
||||||
|
message(WARNING
|
||||||
|
"Test executable '${TEST_EXECUTABLE}' contains no tests!\n"
|
||||||
|
)
|
||||||
|
elseif(${result} LESS 0)
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
||||||
" Result: ${result}\n"
|
" Result: ${result}\n"
|
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||||
|
|
||||||
|
_Note that benchmarking support is disabled by default and to enable it,
|
||||||
|
you need to define `CATCH_CONFIG_ENABLE_BENCHMARKING`. For more details,
|
||||||
|
see the [compile-time configuration documentation](configuration.md#top)._
|
||||||
|
|
||||||
Writing benchmarks is not easy. Catch simplifies certain aspects but you'll
|
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
|
always need to take care about various aspects. Understanding a few things about
|
||||||
the way Catch runs your code will be very helpful when writing your benchmarks.
|
the way Catch runs your code will be very helpful when writing your benchmarks.
|
||||||
|
@@ -205,7 +205,7 @@ ParseAndAddCatchTests(foo)
|
|||||||
* `PARSE_CATCH_TESTS_VERBOSE` -- When `ON`, the script prints debug
|
* `PARSE_CATCH_TESTS_VERBOSE` -- When `ON`, the script prints debug
|
||||||
messages. Defaults to `OFF`.
|
messages. Defaults to `OFF`.
|
||||||
* `PARSE_CATCH_TESTS_NO_HIDDEN_TESTS` -- When `ON`, hidden tests (tests
|
* `PARSE_CATCH_TESTS_NO_HIDDEN_TESTS` -- When `ON`, hidden tests (tests
|
||||||
tagged with either of `[.]` or `[.foo]`) will not be registered.
|
tagged with any of `[!hide]`, `[.]` or `[.foo]`) will not be registered.
|
||||||
Defaults to `OFF`.
|
Defaults to `OFF`.
|
||||||
* `PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME` -- When `ON`, adds fixture
|
* `PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME` -- When `ON`, adds fixture
|
||||||
class name to the test name in CTest. Defaults to `ON`.
|
class name to the test name in CTest. Defaults to `ON`.
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
# Compile-time configuration
|
# Compile-time configuration
|
||||||
|
|
||||||
**Contents**<br>
|
**Contents**<br>
|
||||||
|
[main()/ implementation](#main-implementation)<br>
|
||||||
|
[Reporter / Listener interfaces](#reporter--listener-interfaces)<br>
|
||||||
[Prefixing Catch macros](#prefixing-catch-macros)<br>
|
[Prefixing Catch macros](#prefixing-catch-macros)<br>
|
||||||
[Terminal colour](#terminal-colour)<br>
|
[Terminal colour](#terminal-colour)<br>
|
||||||
[Console width](#console-width)<br>
|
[Console width](#console-width)<br>
|
||||||
@@ -20,6 +22,20 @@ Catch is designed to "just work" as much as possible. For most people the only c
|
|||||||
|
|
||||||
Nonetheless there are still some occasions where finer control is needed. For these occasions Catch exposes a set of macros for configuring how it is built.
|
Nonetheless there are still some occasions where finer control is needed. For these occasions Catch exposes a set of macros for configuring how it is built.
|
||||||
|
|
||||||
|
## main()/ implementation
|
||||||
|
|
||||||
|
CATCH_CONFIG_MAIN // Designates this as implementation file and defines main()
|
||||||
|
CATCH_CONFIG_RUNNER // Designates this as implementation file
|
||||||
|
|
||||||
|
Although Catch is header only it still, internally, maintains a distinction between interface headers and headers that contain implementation. Only one source file in your test project should compile the implementation headers and this is controlled through the use of one of these macros - one of these identifiers should be defined before including Catch in *exactly one implementation file in your project*.
|
||||||
|
|
||||||
|
## Reporter / Listener interfaces
|
||||||
|
|
||||||
|
CATCH_CONFIG_EXTERNAL_INTERFACES // Brings in necessary headers for Reporter/Listener implementation
|
||||||
|
|
||||||
|
Brings in various parts of Catch that are required for user defined Reporters and Listeners. This means that new Reporters and Listeners can be defined in this file as well as in the main file.
|
||||||
|
|
||||||
|
Implied by both `CATCH_CONFIG_MAIN` and `CATCH_CONFIG_RUNNER`.
|
||||||
|
|
||||||
## Prefixing Catch macros
|
## Prefixing Catch macros
|
||||||
|
|
||||||
@@ -111,8 +127,8 @@ Catch's selection, by defining either `CATCH_CONFIG_CPP11_TO_STRING` or
|
|||||||
|
|
||||||
## C++17 toggles
|
## C++17 toggles
|
||||||
|
|
||||||
CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS // Override std::uncaught_exceptions (instead of std::uncaught_exception) support detection
|
CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS // Use std::uncaught_exceptions instead of std::uncaught_exception
|
||||||
CATCH_CONFIG_CPP17_STRING_VIEW // Override std::string_view support detection (Catch provides a StringMaker specialization by default)
|
CATCH_CONFIG_CPP17_STRING_VIEW // Override std::string_view support detection(Catch provides a StringMaker specialization by default)
|
||||||
CATCH_CONFIG_CPP17_VARIANT // Override std::variant support detection (checked by CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER)
|
CATCH_CONFIG_CPP17_VARIANT // Override std::variant support detection (checked by CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER)
|
||||||
CATCH_CONFIG_CPP17_OPTIONAL // Override std::optional support detection (checked by CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER)
|
CATCH_CONFIG_CPP17_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_BYTE // Override std::byte support detection (Catch provides a StringMaker specialization by default)
|
||||||
@@ -131,12 +147,14 @@ by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`.
|
|||||||
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
|
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
|
||||||
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
|
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
|
||||||
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed
|
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed
|
||||||
|
CATCH_CONFIG_DISABLE_MATCHERS // Do not compile Matchers in this compilation unit
|
||||||
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
|
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
|
||||||
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
||||||
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
||||||
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
||||||
CATCH_CONFIG_WCHAR // Enables use of wchart_t
|
CATCH_CONFIG_WCHAR // Enables use of wchart_t
|
||||||
CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr
|
CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr
|
||||||
|
CATCH_CONFIG_ENABLE_BENCHMARKING // Enables the integrated benchmarking features (has a significant effect on compilation speed)
|
||||||
CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking
|
CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking
|
||||||
CATCH_CONFIG_ANDROID_LOGWRITE // Use android's logging system for debug output
|
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_GLOBAL_NEXTAFTER // Use nextafter{,f,l} instead of std::nextafter
|
||||||
@@ -147,10 +165,7 @@ Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC,
|
|||||||
|
|
||||||
`CATCH_CONFIG_POSIX_SIGNALS` is on by default, except when Catch is compiled under `Cygwin`, where it is disabled by default (but can be force-enabled by defining `CATCH_CONFIG_POSIX_SIGNALS`).
|
`CATCH_CONFIG_POSIX_SIGNALS` is on by default, except when Catch is compiled under `Cygwin`, where it is disabled by default (but can be force-enabled by defining `CATCH_CONFIG_POSIX_SIGNALS`).
|
||||||
|
|
||||||
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's
|
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running.
|
||||||
CRT is used to check for memory leaks, and displays them after the tests
|
|
||||||
finish running. This option only works when linking against the default
|
|
||||||
main, and must be defined for the whole library build.
|
|
||||||
|
|
||||||
`CATCH_CONFIG_WCHAR` is on by default, but can be disabled. Currently
|
`CATCH_CONFIG_WCHAR` is on by default, but can be disabled. Currently
|
||||||
it is only used in support for DJGPP cross-compiler.
|
it is only used in support for DJGPP cross-compiler.
|
||||||
@@ -169,6 +184,11 @@ should not lead to false negatives.
|
|||||||
`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined,
|
`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined,
|
||||||
in all translation units that are linked into single test binary.
|
in all translation units that are linked into single test binary.
|
||||||
|
|
||||||
|
### `CATCH_CONFIG_DISABLE_MATCHERS`
|
||||||
|
When `CATCH_CONFIG_DISABLE_MATCHERS` is defined, all mentions of Catch's Matchers are ifdef-ed away from the translation unit. Doing so will speed up compilation of that TU.
|
||||||
|
|
||||||
|
_Note: If you define `CATCH_CONFIG_DISABLE_MATCHERS` in the same file as Catch's main is implemented, your test executable will fail to link if you use Matchers anywhere._
|
||||||
|
|
||||||
### `CATCH_CONFIG_DISABLE_STRINGIFICATION`
|
### `CATCH_CONFIG_DISABLE_STRINGIFICATION`
|
||||||
This toggle enables a workaround for VS 2017 bug. For details see [known limitations](limitations.md#visual-studio-2017----raw-string-literal-in-assert-fails-to-compile).
|
This toggle enables a workaround for VS 2017 bug. For details see [known limitations](limitations.md#visual-studio-2017----raw-string-literal-in-assert-fails-to-compile).
|
||||||
|
|
||||||
@@ -193,6 +213,7 @@ By default, Catch does not stringify some types from the standard library. This
|
|||||||
|
|
||||||
CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER // Provide StringMaker specialization for std::pair
|
CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER // Provide StringMaker specialization for std::pair
|
||||||
CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER // Provide StringMaker specialization for std::tuple
|
CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER // Provide StringMaker specialization for std::tuple
|
||||||
|
CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER // Provide StringMaker specialization for std::chrono::duration, std::chrono::timepoint
|
||||||
CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER // Provide StringMaker specialization for std::variant, std::monostate (on C++17)
|
CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER // Provide StringMaker specialization for std::variant, std::monostate (on C++17)
|
||||||
CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER // Provide StringMaker specialization for std::optional (on C++17)
|
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_ALL_STRINGMAKERS // Defines all of the above
|
||||||
|
@@ -21,8 +21,8 @@ to the codebase itself.
|
|||||||
|
|
||||||
## Using Git(Hub)
|
## Using Git(Hub)
|
||||||
|
|
||||||
Ongoing development happens in the `devel` branch for Catch2 v3, and in
|
Ongoing development happens in the `master` branch for Catch2 v2, and in
|
||||||
`v2.x` for maintenance updates to the v2 versions.
|
`dev-v3` for the next major version, v3.
|
||||||
|
|
||||||
Commits should be small and atomic. A commit is atomic when, after it is
|
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
|
applied, the codebase, tests and all, still works as expected. Small
|
||||||
@@ -30,8 +30,8 @@ commits are also prefered, as they make later operations with git history,
|
|||||||
whether it is bisecting, reverting, or something else, easier.
|
whether it is bisecting, reverting, or something else, easier.
|
||||||
|
|
||||||
_When submitting a pull request please do not include changes to the
|
_When submitting a pull request please do not include changes to the
|
||||||
amalgamated distribution files. This means do not include them in your
|
single include. This means do not include them in your git commits!_
|
||||||
git commits!_
|
|
||||||
|
|
||||||
When addressing review comments in a MR, please do not rebase/squash the
|
When addressing review comments in a MR, please do not rebase/squash the
|
||||||
commits immediately. Doing so makes it harder to review the new changes,
|
commits immediately. Doing so makes it harder to review the new changes,
|
||||||
@@ -63,13 +63,15 @@ using CTest, either as a direct command invocation + pass/fail regex,
|
|||||||
or by delegating the check to a Python script.
|
or by delegating the check to a Python script.
|
||||||
|
|
||||||
There are also two more kinds of tests, examples and "ExtraTests".
|
There are also two more kinds of tests, examples and "ExtraTests".
|
||||||
Examples present a small and self-contained snippets of code that
|
Examples serve as a compilation test on the single-header distribution,
|
||||||
use Catch2's facilities for specific purpose. Currently they are assumed
|
and present a small and self-contained snippets of using Catch2 for
|
||||||
passing if they compile. ExtraTests then are expensive tests, that we
|
writing tests. ExtraTests then are tests that either take a long time
|
||||||
do not want to run all the time. This can be either because they take
|
to run, or require separate compilation, e.g. because of testing compile
|
||||||
a long time to run, or because they take a long time to compile, e.g.
|
time configuration options, and take a long time because of that.
|
||||||
because they test compile time configuration and require separate
|
|
||||||
compilation.
|
Both of these are compiled against the single-header distribution of
|
||||||
|
Catch2, and thus might require you to regenerate it manually. This is
|
||||||
|
done by calling the `generateSingleHeader.py` script in `scripts`.
|
||||||
|
|
||||||
Examples and ExtraTests are not compiled by default. To compile them,
|
Examples and ExtraTests are not compiled by default. To compile them,
|
||||||
add `-DCATCH_BUILD_EXAMPLES=ON` and `-DCATCH_BUILD_EXTRA_TESTS=ON` to
|
add `-DCATCH_BUILD_EXAMPLES=ON` and `-DCATCH_BUILD_EXTRA_TESTS=ON` to
|
||||||
@@ -78,10 +80,10 @@ the invocation of CMake configuration step.
|
|||||||
Bringing this all together, the steps below should configure, build,
|
Bringing this all together, the steps below should configure, build,
|
||||||
and run all tests in the `Debug` compilation.
|
and run all tests in the `Debug` compilation.
|
||||||
|
|
||||||
1. Regenerate the amalgamated distribution
|
1. Regenerate the single header distribution
|
||||||
```
|
```
|
||||||
$ cd Catch2
|
$ cd Catch2
|
||||||
$ ./tools/scripts/generateAmalgamatedFiles.py
|
$ ./scripts/generateSingleHeader.py
|
||||||
```
|
```
|
||||||
2. Configure the full test build
|
2. Configure the full test build
|
||||||
```
|
```
|
||||||
@@ -97,11 +99,6 @@ $ cd debug-build
|
|||||||
$ ctest -j 4 --output-on-failure -C Debug
|
$ ctest -j 4 --output-on-failure -C Debug
|
||||||
```
|
```
|
||||||
|
|
||||||
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
|
|
||||||
in your commit.
|
|
||||||
|
|
||||||
|
|
||||||
## Writing documentation
|
## Writing documentation
|
||||||
|
|
||||||
@@ -110,7 +107,6 @@ other people can use it as well. This section collects some technical
|
|||||||
information that you will need for updating Catch2's documentation, and
|
information that you will need for updating Catch2's documentation, and
|
||||||
possibly some generic advise as well.
|
possibly some generic advise as well.
|
||||||
|
|
||||||
|
|
||||||
### Technicalities
|
### Technicalities
|
||||||
|
|
||||||
First, the technicalities:
|
First, the technicalities:
|
||||||
@@ -220,26 +216,6 @@ there is no difference is wrong, QNX and VxWorks won't compile if you
|
|||||||
include the header as `<cfoo>` and call the function unqualified.
|
include the header as `<cfoo>` and call the function unqualified.
|
||||||
|
|
||||||
|
|
||||||
### New source file template
|
|
||||||
|
|
||||||
If you are adding new source file, there is a template you should use.
|
|
||||||
Specifically, every source file should start with the licence header:
|
|
||||||
```cpp
|
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
```
|
|
||||||
|
|
||||||
The include guards for header files should follow the pattern `{FILENAME}_INCLUDED`.
|
|
||||||
This means that for file `catch_matchers_foo`, the include guard should
|
|
||||||
be `CATCH_MATCHERS_FOO_INCLUDED`, for `catch_generators_bar`, the include
|
|
||||||
guard should be `CATCH_GENERATORS_BAR_INCLUDED`, and so on.
|
|
||||||
|
|
||||||
|
|
||||||
## CoC
|
## CoC
|
||||||
|
|
||||||
This project has a [CoC](../CODE_OF_CONDUCT.md). Please adhere to it
|
This project has a [CoC](../CODE_OF_CONDUCT.md). Please adhere to it
|
||||||
|
@@ -9,9 +9,91 @@ either of these is a breaking change, and thus will not happen until
|
|||||||
at least the next major release.
|
at least the next major release.
|
||||||
|
|
||||||
|
|
||||||
|
## Deprecations
|
||||||
|
|
||||||
|
### `--list-*` return values
|
||||||
|
|
||||||
|
The return codes of the `--list-*` family of command line arguments
|
||||||
|
will no longer be equal to the number of tests/tags/etc found, instead
|
||||||
|
it will be 0 for success and non-zero for failure.
|
||||||
|
|
||||||
|
|
||||||
|
### `--list-test-names-only`
|
||||||
|
|
||||||
|
`--list-test-names-only` command line argument will be removed.
|
||||||
|
|
||||||
|
|
||||||
|
### `ANON_TEST_CASE`
|
||||||
|
|
||||||
|
`ANON_TEST_CASE` is scheduled for removal, as it can be fully replaced
|
||||||
|
by a `TEST_CASE` with no arguments.
|
||||||
|
|
||||||
|
|
||||||
|
### Secondary description amongst tags
|
||||||
|
|
||||||
|
Currently, the tags part of `TEST_CASE` (and others) macro can also
|
||||||
|
contain text that is not part of tags. This text is then separated into
|
||||||
|
a "description" of the test case, but the description is then never used
|
||||||
|
apart from writing it out for `--list-tests -v high`.
|
||||||
|
|
||||||
|
Because it isn't actually used nor documented, and brings complications
|
||||||
|
to Catch2's internals, description support will be removed.
|
||||||
|
|
||||||
|
### SourceLineInfo::empty()
|
||||||
|
|
||||||
|
There should be no reason to ever have an empty `SourceLineInfo`, so the
|
||||||
|
method will be removed.
|
||||||
|
|
||||||
|
|
||||||
|
### Composing lvalues of already composed matchers
|
||||||
|
|
||||||
|
Because a significant bug in this use case has persisted for 2+ years
|
||||||
|
without a bug report, and to simplify the implementation, code that
|
||||||
|
composes lvalues of composed matchers will not compile. That is,
|
||||||
|
this code will no longer work:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto m1 = Contains("string");
|
||||||
|
auto m2 = Contains("random");
|
||||||
|
auto composed1 = m1 || m2;
|
||||||
|
auto m3 = Contains("different");
|
||||||
|
auto composed2 = composed1 || m3;
|
||||||
|
REQUIRE_THAT(foo(), !composed1);
|
||||||
|
REQUIRE_THAT(foo(), composed2);
|
||||||
|
```
|
||||||
|
|
||||||
|
Instead you will have to write this:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto m1 = Contains("string");
|
||||||
|
auto m2 = Contains("random");
|
||||||
|
auto m3 = Contains("different");
|
||||||
|
REQUIRE_THAT(foo(), !(m1 || m2));
|
||||||
|
REQUIRE_THAT(foo(), m1 || m2 || m3);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Planned changes
|
## Planned changes
|
||||||
|
|
||||||
|
|
||||||
|
### Reporter verbosities
|
||||||
|
|
||||||
|
The current implementation of verbosities, where the reporter is checked
|
||||||
|
up-front whether it supports the requested verbosity, is fundamentally
|
||||||
|
misguided and will be changed. The new implementation will no longer check
|
||||||
|
whether the specified reporter supports the requested verbosity, instead
|
||||||
|
it will be up to the reporters to deal with verbosities as they see fit
|
||||||
|
(with an expectation that unsupported verbosities will be, at most,
|
||||||
|
warnings, but not errors).
|
||||||
|
|
||||||
|
|
||||||
|
### Output format of `--list-*` command line parameters
|
||||||
|
|
||||||
|
The various list operations will be piped through reporters. This means
|
||||||
|
that e.g. XML reporter will write the output as machine-parseable XML,
|
||||||
|
while the Console reporter will keep the current, human-oriented output.
|
||||||
|
|
||||||
|
|
||||||
### `CHECKED_IF` and `CHECKED_ELSE`
|
### `CHECKED_IF` and `CHECKED_ELSE`
|
||||||
|
|
||||||
To make the `CHECKED_IF` and `CHECKED_ELSE` macros more useful, they will
|
To make the `CHECKED_IF` and `CHECKED_ELSE` macros more useful, they will
|
||||||
@@ -20,12 +102,36 @@ will be added), which means that their failure will not fail the test,
|
|||||||
making the `else` actually useful.
|
making the `else` actually useful.
|
||||||
|
|
||||||
|
|
||||||
|
### Change semantics of `[.]` and tag exclusion
|
||||||
|
|
||||||
|
Currently, given these 2 tests
|
||||||
|
```cpp
|
||||||
|
TEST_CASE("A", "[.][foo]") {}
|
||||||
|
TEST_CASE("B", "[.][bar]") {}
|
||||||
|
```
|
||||||
|
specifying `[foo]` as the testspec will run test "A" and specifying
|
||||||
|
`~[foo]` will run test "B", even though it is hidden. Also, specifying
|
||||||
|
`~[baz]` will run both tests. This behaviour is often surprising and will
|
||||||
|
be changed so that hidden tests are included in a run only if they
|
||||||
|
positively match a testspec.
|
||||||
|
|
||||||
|
|
||||||
### Console Colour API
|
### Console Colour API
|
||||||
|
|
||||||
The API for Catch2's console colour will be changed to take an extra
|
The API for Catch2's console colour will be changed to take an extra
|
||||||
argument, the stream to which the colour code should be applied.
|
argument, the stream to which the colour code should be applied.
|
||||||
|
|
||||||
|
|
||||||
|
### Type erasure in the `PredicateMatcher`
|
||||||
|
|
||||||
|
Currently, the `PredicateMatcher` uses `std::function` for type erasure,
|
||||||
|
so that type of the matcher is always `PredicateMatcher<T>`, regardless
|
||||||
|
of the type of the predicate. Because of the high compilation overhead
|
||||||
|
of `std::function`, and the fact that the type erasure is used only rarely,
|
||||||
|
`PredicateMatcher` will no longer be type erased in the future. Instead,
|
||||||
|
the predicate type will be made part of the PredicateMatcher's type.
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md#top)
|
[Home](Readme.md#top)
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
- Fixture: [Sections](../examples/100-Fix-Section.cpp)
|
- Fixture: [Sections](../examples/100-Fix-Section.cpp)
|
||||||
- Fixture: [Class-based fixtures](../examples/110-Fix-ClassFixture.cpp)
|
- Fixture: [Class-based fixtures](../examples/110-Fix-ClassFixture.cpp)
|
||||||
- BDD: [SCENARIO, GIVEN, WHEN, THEN](../examples/120-Bdd-ScenarioGivenWhenThen.cpp)
|
- BDD: [SCENARIO, GIVEN, WHEN, THEN](../examples/120-Bdd-ScenarioGivenWhenThen.cpp)
|
||||||
|
- Report: [Catch-provided main](../examples/200-Rpt-CatchMain.cpp)
|
||||||
|
- Report: [TeamCity reporter](../examples/207-Rpt-TeamCityReporter.cpp)
|
||||||
- Listener: [Listeners](../examples/210-Evt-EventListeners.cpp)
|
- Listener: [Listeners](../examples/210-Evt-EventListeners.cpp)
|
||||||
- Configuration: [Provide your own output streams](../examples/231-Cfg-OutputStreams.cpp)
|
- Configuration: [Provide your own output streams](../examples/231-Cfg-OutputStreams.cpp)
|
||||||
- Generators: [Create your own generator](../examples/300-Gen-OwnGenerator.cpp)
|
- Generators: [Create your own generator](../examples/300-Gen-OwnGenerator.cpp)
|
||||||
|
439
docs/matchers.md
439
docs/matchers.md
@@ -1,123 +1,77 @@
|
|||||||
<a id="top"></a>
|
<a id="top"></a>
|
||||||
# Matchers
|
# Matchers
|
||||||
|
|
||||||
**Contents**<br>
|
Matchers are an alternative way to do assertions which are easily extensible and composable.
|
||||||
[Using Matchers](#using-matchers)<br>
|
This makes them well suited to use with more complex types (such as collections) or your own custom types.
|
||||||
[Built-in matchers](#built-in-matchers)<br>
|
Matchers were first popularised by the [Hamcrest](https://en.wikipedia.org/wiki/Hamcrest) family of frameworks.
|
||||||
[Writing custom matchers (old style)](#writing-custom-matchers-old-style)<br>
|
|
||||||
[Writing custom matchers (new style)](#writing-custom-matchers-new-style)<br>
|
|
||||||
|
|
||||||
Matchers, as popularized by the [Hamcrest](https://en.wikipedia.org/wiki/Hamcrest)
|
## In use
|
||||||
framework are an alternative way to write assertions, useful for tests
|
|
||||||
where you work with complex types or need to assert more complex
|
|
||||||
properties. Matchers are easily composable and users can write their
|
|
||||||
own and combine them with the Catch2-provided matchers seamlessly.
|
|
||||||
|
|
||||||
|
Matchers are introduced with the `REQUIRE_THAT` or `CHECK_THAT` macros, which take two arguments.
|
||||||
|
The first argument is the thing (object or value) under test. The second part is a match _expression_,
|
||||||
|
which consists of either a single matcher or one or more matchers combined using `&&`, `||` or `!` operators.
|
||||||
|
|
||||||
## Using Matchers
|
For example, to assert that a string ends with a certain substring:
|
||||||
|
|
||||||
Matchers are most commonly used in tandem with the `REQUIRE_THAT` or
|
```c++
|
||||||
`CHECK_THAT` macros. The `REQUIRE_THAT` macro takes two arguments,
|
using Catch::Matchers::EndsWith; // or Catch::EndsWith
|
||||||
the first one is the input (object/value) to test, the second argument
|
std::string str = getStringFromSomewhere();
|
||||||
is the matcher itself.
|
REQUIRE_THAT( str, EndsWith( "as a service" ) );
|
||||||
|
|
||||||
For example, to assert that a string ends with the "as a service"
|
|
||||||
substring, you can write the following assertion
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
using Catch::Matchers::EndsWith;
|
|
||||||
|
|
||||||
REQUIRE_THAT( getSomeString(), EndsWith("as a service") );
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Individual matchers can also be combined using the C++ logical
|
The matcher objects can take multiple arguments, allowing more fine tuning.
|
||||||
operators, that is `&&`, `||`, and `!`, like so:
|
The built-in string matchers, for example, take a second argument specifying whether the comparison is
|
||||||
|
case sensitive or not:
|
||||||
|
|
||||||
```cpp
|
```c++
|
||||||
using Catch::Matchers::EndsWith;
|
REQUIRE_THAT( str, EndsWith( "as a service", Catch::CaseSensitive::No ) );
|
||||||
using Catch::Matchers::Contains;
|
```
|
||||||
|
|
||||||
REQUIRE_THAT( getSomeString(),
|
And matchers can be combined:
|
||||||
EndsWith("as a service") && Contains("web scale"));
|
|
||||||
|
```c++
|
||||||
|
REQUIRE_THAT( str,
|
||||||
|
EndsWith( "as a service" ) ||
|
||||||
|
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
|
||||||
```
|
```
|
||||||
|
|
||||||
The example above asserts that the string returned from `getSomeString`
|
_The combining operators do not take ownership of the matcher objects.
|
||||||
_both_ ends with the suffix "as a service" _and_ contains the string
|
This means that if you store the combined object, you have to ensure that
|
||||||
"web scale" somewhere.
|
the matcher objects outlive its last use. What this means is that code
|
||||||
|
like this leads to a use-after-free and (hopefully) a crash:_
|
||||||
|
|
||||||
Both of the string matchers used in the examples above live in the
|
|
||||||
`catch_matchers_string.hpp` header, so to compile the code above also
|
|
||||||
requires `#include <catch2/matchers/catch_matchers_string.hpp>`.
|
|
||||||
|
|
||||||
**IMPORTANT**: The combining operators do not take ownership of the
|
|
||||||
matcher objects being combined. This means that if you store combined
|
|
||||||
matcher object, you have to ensure that the matchers being combined
|
|
||||||
outlive its last use. What this means is that the following code leads
|
|
||||||
to a use-after-free (UAF):
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include <catch2/catch_test_macros.hpp>
|
|
||||||
#include <catch2/matchers/catch_matchers_string.h>
|
|
||||||
|
|
||||||
TEST_CASE("Bugs, bugs, bugs", "[Bug]"){
|
TEST_CASE("Bugs, bugs, bugs", "[Bug]"){
|
||||||
std::string str = "Bugs as a service";
|
std::string str = "Bugs as a service";
|
||||||
|
|
||||||
auto match_expression = Catch::Matchers::EndsWith( "as a service" ) ||
|
auto match_expression = Catch::EndsWith( "as a service" ) ||
|
||||||
(Catch::Matchers::StartsWith( "Big data" ) && !Catch::Matchers::Contains( "web scale" ) );
|
(Catch::StartsWith( "Big data" ) && !Catch::Contains( "web scale" ) );
|
||||||
REQUIRE_THAT(str, match_expression);
|
REQUIRE_THAT(str, match_expression);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Built-in matchers
|
## Built in matchers
|
||||||
|
Catch2 provides some matchers by default. They can be found in the
|
||||||
|
`Catch::Matchers::foo` namespace and are imported into the `Catch`
|
||||||
|
namespace as well.
|
||||||
|
|
||||||
Every matcher provided by Catch2 is split into 2 parts, a factory
|
There are two parts to each of the built-in matchers, the matcher
|
||||||
function that lives in the `Catch::Matchers` namespace, and the actual
|
type itself and a helper function that provides template argument
|
||||||
matcher type that is in some deeper namespace and should not be used by
|
deduction when creating templated matchers. As an example, the matcher
|
||||||
the user. In the examples above, we used `Catch::Matchers::Contains`.
|
for checking that two instances of `std::vector` are identical is
|
||||||
This is the factory function for the
|
`EqualsMatcher<T>`, but the user is expected to use the `Equals`
|
||||||
`Catch::Matchers::StdString::ContainsMatcher` type that does the actual
|
helper function instead.
|
||||||
matching.
|
|
||||||
|
|
||||||
Out of the box, Catch2 provides the following matchers:
|
|
||||||
|
|
||||||
|
|
||||||
### `std::string` matchers
|
### String matchers
|
||||||
|
The string matchers are `StartsWith`, `EndsWith`, `Contains`, `Equals` and `Matches`. The first four match a literal (sub)string against a result, while `Matches` takes and matches an ECMAScript regex. Do note that `Matches` matches the string as a whole, meaning that "abc" will not match against "abcd", but "abc.*" will.
|
||||||
|
|
||||||
Catch2 provides 5 different matchers that work with `std::string`,
|
Each of the provided `std::string` matchers also takes an optional second argument, that decides case sensitivity (by-default, they are case sensitive).
|
||||||
* `StartsWith(std::string str, CaseSensitive)`,
|
|
||||||
* `EndsWith(std::string str, CaseSensitive)`,
|
|
||||||
* `Contains(std::string str, CaseSensitive)`,
|
|
||||||
* `Equals(std::string str, CaseSensitive)`, and
|
|
||||||
* `Matches(std::string str, CaseSensitive)`.
|
|
||||||
|
|
||||||
The first three should be fairly self-explanatory, they succeed if
|
|
||||||
the argument starts with `str`, ends with `str`, or contains `str`
|
|
||||||
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
|
|
||||||
`str` against the argument string. It is important to know that
|
|
||||||
the match is performed agains 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.
|
|
||||||
|
|
||||||
The second argument sets whether the matching should be case-sensitive
|
|
||||||
or not. By default, it is case-sensitive.
|
|
||||||
|
|
||||||
> `std::string` matchers live in `catch2/matchers/catch_matchers_string.hpp`
|
|
||||||
|
|
||||||
|
|
||||||
### Vector matchers
|
### Vector matchers
|
||||||
|
Catch2 currently provides 5 built-in matchers that work on `std::vector`.
|
||||||
_Vector matchers have been deprecated in favour of the generic
|
|
||||||
range matchers with the same functionality._
|
|
||||||
|
|
||||||
Catch2 provides 5 built-in matchers that work on `std::vector`.
|
|
||||||
|
|
||||||
These are
|
These are
|
||||||
|
|
||||||
* `Contains` which checks whether a specified vector is present in the result
|
* `Contains` which checks whether a specified vector is present in the result
|
||||||
@@ -127,82 +81,40 @@ These are
|
|||||||
* `Approx` which checks whether the result is "approx-equal" (order matters, but comparison is done via `Approx`) to a specific vector
|
* `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 Catch 2.7.2.
|
||||||
|
|
||||||
An example usage:
|
|
||||||
```cpp
|
|
||||||
std::vector<int> some_vec{ 1, 2, 3 };
|
|
||||||
REQUIRE_THAT(some_vec, Catch::Matchers::UnorderedEquals(std::vector<int>{ 3, 2, 1 }));
|
|
||||||
```
|
|
||||||
|
|
||||||
This assertions will pass, because the elements given to the matchers
|
|
||||||
are a permutation of the ones in `some_vec`.
|
|
||||||
|
|
||||||
> vector matchers live in `catch2/matchers/catch_matchers_vector.hpp`
|
|
||||||
|
|
||||||
|
|
||||||
### Floating point matchers
|
### Floating point matchers
|
||||||
|
Catch2 provides 3 matchers for working with floating point numbers. These
|
||||||
|
are `WithinAbsMatcher`, `WithinUlpsMatcher` and `WithinRelMatcher`.
|
||||||
|
|
||||||
Catch2 provides 3 matchers that target floating point numbers. These
|
The `WithinAbsMatcher` matcher accepts floating point numbers that are
|
||||||
are:
|
within a certain distance of target. It should be constructed with the
|
||||||
|
`WithinAbs(double target, double margin)` helper.
|
||||||
|
|
||||||
* `WithinAbs(double target, double margin)`,
|
The `WithinUlpsMatcher` matcher accepts floating point numbers that are
|
||||||
* `WithinUlps(FloatingPoint target, uint64_t maxUlpDiff)`, and
|
within a certain number of [ULPs](https://en.wikipedia.org/wiki/Unit_in_the_last_place)
|
||||||
* `WithinRel(FloatingPoint target, FloatingPoint eps)`.
|
of the target. Because ULP comparisons need to be done differently for
|
||||||
|
`float`s and for `double`s, there are two overloads of the helpers for
|
||||||
|
this matcher, `WithinULP(float target, int64_t ULPs)`, and
|
||||||
|
`WithinULP(double target, int64_t ULPs)`.
|
||||||
|
|
||||||
|
The `WithinRelMatcher` matcher accepts floating point numbers that are
|
||||||
|
_approximately equal_ with the target number with some specific tolerance.
|
||||||
|
In other words, it checks that `|lhs - rhs| <= epsilon * max(|lhs|, |rhs|)`,
|
||||||
|
with special casing for `INFINITY` and `NaN`. There are _4_ overloads of
|
||||||
|
the helpers for this matcher, `WithinRel(double target, double margin)`,
|
||||||
|
`WithinRel(float target, float margin)`, `WithinRel(double target)`, and
|
||||||
|
`WithinRel(float target)`. The latter two provide a default epsilon of
|
||||||
|
machine epsilon * 100.
|
||||||
|
|
||||||
> `WithinRel` matcher was introduced in Catch 2.10.0
|
> `WithinRel` matcher was introduced in Catch 2.10.0
|
||||||
|
|
||||||
|
### Generic matchers
|
||||||
|
Catch also aims to provide a set of generic matchers. Currently this set
|
||||||
|
contains only a matcher that takes arbitrary callable predicate and applies
|
||||||
|
it onto the provided object.
|
||||||
|
|
||||||
`WithinAbs` creates a matcher that accepts floating point numbers whose
|
Because of type inference limitations, the argument type of the predicate
|
||||||
difference with `target` is less than the `margin`.
|
has to be provided explicitly. Example:
|
||||||
|
|
||||||
`WithinULP` creates a matcher that accepts floating point numbers that
|
|
||||||
are no more than `maxUlpDiff`
|
|
||||||
[ULPs](https://en.wikipedia.org/wiki/Unit_in_the_last_place)
|
|
||||||
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.
|
|
||||||
|
|
||||||
`WithinRel` creates a matcher that accepts floating point numbers that
|
|
||||||
are _approximately equal_ with the `target` with tolerance of `eps.`
|
|
||||||
Specifically, it matches if
|
|
||||||
`|arg - target| <= eps * max(|arg|, |target|)` holds. If you do not
|
|
||||||
specify `eps`, `std::numeric_limits<FloatingPoint>::epsilon * 100`
|
|
||||||
is used as the default.
|
|
||||||
|
|
||||||
|
|
||||||
In practice, you will often want to combine multiple of these matchers,
|
|
||||||
together for an assertion, because all 3 options have edge cases where
|
|
||||||
they behave differently than you would expect. As an example, under
|
|
||||||
the `WithinRel` matcher, a `0.` only ever matches a `0.` (or `-0.`),
|
|
||||||
regardless of the relative tolerance specified. Thus, if you want to
|
|
||||||
handle numbers that are "close enough to 0 to be 0", you have to combine
|
|
||||||
it with the `WithinAbs` matcher.
|
|
||||||
|
|
||||||
For example, to check that our computation matches known good value
|
|
||||||
within 0.1%, or is close enough (no different to 5 decimal places)
|
|
||||||
to zero, we would write this assertion:
|
|
||||||
```cpp
|
|
||||||
REQUIRE_THAT( computation(input),
|
|
||||||
Catch::Matchers::WithinRel(expected, 0.001)
|
|
||||||
|| Catch::Matchers::WithinAbs(0, 0.000001) );
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
> floating point matchers live in `catch2/matchers/catch_matchers_floating.hpp`
|
|
||||||
|
|
||||||
|
|
||||||
### Miscellaneous matchers
|
|
||||||
|
|
||||||
Catch2 also provides some matchers and matcher utilities that do not
|
|
||||||
quite fit into other categories.
|
|
||||||
|
|
||||||
The first one of them is the `Predicate(Callable pred, std::string description)`
|
|
||||||
matcher. It creates a matcher object that calls `pred` for the provided
|
|
||||||
argument. The `description` argument allows users to set what the
|
|
||||||
resulting matcher should self-describe as if required.
|
|
||||||
|
|
||||||
Do note that you will need to explicitly specify the type of the
|
|
||||||
argument, like in this example:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
REQUIRE_THAT("Hello olleH",
|
REQUIRE_THAT("Hello olleH",
|
||||||
Predicate<std::string>(
|
Predicate<std::string>(
|
||||||
@@ -211,205 +123,84 @@ REQUIRE_THAT("Hello olleH",
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
> the predicate matcher lives in `catch2/matchers/catch_matchers_predicate.hpp`
|
The second argument is an optional description of the predicate, and is
|
||||||
|
used only during reporting of the result.
|
||||||
|
|
||||||
|
|
||||||
The other miscellaneous matcher utility is exception matching.
|
### Exception matchers
|
||||||
|
Catch2 also provides an exception matcher that can be used to verify
|
||||||
|
that an exception's message exactly matches desired string. The matcher
|
||||||
|
is `ExceptionMessageMatcher`, and we also provide a helper function
|
||||||
|
`Message`.
|
||||||
|
|
||||||
|
The matched exception must publicly derive from `std::exception` and
|
||||||
|
the message matching is done _exactly_, including case.
|
||||||
|
|
||||||
#### Matching exceptions
|
> `ExceptionMessageMatcher` was introduced in Catch 2.10.0
|
||||||
|
|
||||||
Catch2 provides an utility macro for asserting that an expression
|
|
||||||
throws exception of specific type, and that the exception has desired
|
|
||||||
properties. The macro is `REQUIRE_THROWS_MATCHES(expr, ExceptionType, Matcher)`.
|
|
||||||
|
|
||||||
> `REQUIRE_THROWS_MATCHES` macro lives in `catch2/matchers/catch_matchers.hpp`
|
|
||||||
|
|
||||||
|
|
||||||
Catch2 currently provides only one matcher for exceptions,
|
|
||||||
`Message(std::string message)`. `Message` checks that the exception's
|
|
||||||
message, as returned from `what` is exactly equal to `message`.
|
|
||||||
|
|
||||||
Example use:
|
Example use:
|
||||||
```cpp
|
```cpp
|
||||||
REQUIRE_THROWS_MATCHES(throwsDerivedException(), DerivedException, Message("DerivedException::what"));
|
REQUIRE_THROWS_MATCHES(throwsDerivedException(), DerivedException, Message("DerivedException::what"));
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that `DerivedException` in the example above has to derive from
|
## Custom matchers
|
||||||
`std::exception` for the example to work.
|
It's easy to provide your own matchers to extend Catch or just to work with your own types.
|
||||||
|
|
||||||
> the exception message matcher lives in `catch2/matchers/catch_matchers_exception.hpp`
|
You need to provide two things:
|
||||||
|
1. A matcher class, derived from `Catch::MatcherBase<T>` - where `T` is the type being tested.
|
||||||
|
The constructor takes and stores any arguments needed (e.g. something to compare against) and you must
|
||||||
|
override two methods: `match()` and `describe()`.
|
||||||
|
2. A simple builder function. This is what is actually called from the test code and allows overloading.
|
||||||
|
|
||||||
|
Here's an example for asserting that an integer falls within a given range
|
||||||
### Generic range Matchers
|
(note that it is all inline for the sake of keeping the example short):
|
||||||
|
|
||||||
> Generic range matchers were introduced in Catch X.Y.Z
|
|
||||||
|
|
||||||
Catch2 also provides some matchers that use the new style matchers
|
|
||||||
definitions to handle generic range-like types. These are:
|
|
||||||
|
|
||||||
* `IsEmpty()`
|
|
||||||
* `SizeIs(size_t target_size)`
|
|
||||||
* `SizeIs(Matcher size_matcher)`
|
|
||||||
* `Contains(T&& target_element, Comparator = std::equal_to<>{})`
|
|
||||||
* `Contains(Matcher element_matcher)`
|
|
||||||
|
|
||||||
`IsEmpty` should be self-explanatory. It successfully matches objects
|
|
||||||
that are empty according to either `std::empty`, or ADL-found `empty`
|
|
||||||
free function.
|
|
||||||
|
|
||||||
`SizeIs` checks range's size. If constructed with `size_t` arg, the
|
|
||||||
matchers accepts ranges whose size is exactly equal to the arg. If
|
|
||||||
constructed from another matcher, then the resulting matcher accepts
|
|
||||||
ranges whose size is accepted by the provided matcher.
|
|
||||||
|
|
||||||
`Contains` accepts ranges that contain specific element. There are
|
|
||||||
again two variants, one that accepts the desired element directly,
|
|
||||||
in which case a range is accepted if any of its elements is equal to
|
|
||||||
the target element. The other variant is constructed from a matcher,
|
|
||||||
in which case a range is accepted if any of its elements is accepted
|
|
||||||
by the provided matcher.
|
|
||||||
|
|
||||||
|
|
||||||
## Writing custom matchers (old style)
|
|
||||||
|
|
||||||
The old style of writing matchers has been introduced back in Catch
|
|
||||||
Classic. To create an old-style matcher, you have to create your own
|
|
||||||
type that derives from `Catch::Matchers::MatcherBase<ArgT>`, where
|
|
||||||
`ArgT` is the type your matcher works for. Your type has to override
|
|
||||||
two methods, `bool match(ArgT const&) const`,
|
|
||||||
and `std::string describe() const`.
|
|
||||||
|
|
||||||
As the name suggests, `match` decides whether the provided argument
|
|
||||||
is matched (accepted) by the matcher. `describe` then provides a
|
|
||||||
human-oriented description of what the matcher does.
|
|
||||||
|
|
||||||
We also recommend that you create factory function, just like Catch2
|
|
||||||
does, but that is mostly useful for template argument deduction for
|
|
||||||
templated matchers (assuming you do not have CTAD available).
|
|
||||||
|
|
||||||
To combine these into an example, let's say that you want to write
|
|
||||||
a matcher that decides whether the provided argument is a number
|
|
||||||
within certain range. We will call it `IsBetweenMatcher<T>`:
|
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
#include <catch2/catch_test_macros.hpp>
|
// The matcher class
|
||||||
#include <catch2/matchers/catch_matchers.h>
|
class IntRange : public Catch::MatcherBase<int> {
|
||||||
// ...
|
int m_begin, m_end;
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class IsBetweenMatcher : public Catch::Matchers::MatcherBase<T> {
|
|
||||||
T m_begin, m_end;
|
|
||||||
public:
|
public:
|
||||||
IsBetweenMatcher(T begin, T end) : m_begin(begin), m_end(end) {}
|
IntRange( int begin, int end ) : m_begin( begin ), m_end( end ) {}
|
||||||
|
|
||||||
bool match(T const& in) const override {
|
// Performs the test for this matcher
|
||||||
return in >= m_begin && in <= m_end;
|
bool match( int const& i ) const override {
|
||||||
|
return i >= m_begin && i <= m_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string describe() const override {
|
// Produces a string describing what this matcher does. It should
|
||||||
|
// include any provided data (the begin/ end in this case) and
|
||||||
|
// be written as if it were stating a fact (in the output it will be
|
||||||
|
// preceded by the value under test).
|
||||||
|
virtual std::string describe() const override {
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << "is between " << m_begin << " and " << m_end;
|
ss << "is between " << m_begin << " and " << m_end;
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
// The builder function
|
||||||
IsBetweenMatcher<T> IsBetween(T begin, T end) {
|
inline IntRange IsBetween( int begin, int end ) {
|
||||||
return { begin, end };
|
return IntRange( begin, end );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
TEST_CASE("Numbers are within range") {
|
// Usage
|
||||||
// infers `double` for the argument type of the matcher
|
TEST_CASE("Integers are within a range")
|
||||||
CHECK_THAT(3., IsBetween(1., 10.));
|
{
|
||||||
// infers `int` for the argument type of the matcher
|
CHECK_THAT( 3, IsBetween( 1, 10 ) );
|
||||||
CHECK_THAT(100, IsBetween(1, 10));
|
CHECK_THAT( 100, IsBetween( 1, 10 ) );
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Obviously, the code above can be improved somewhat, for example you
|
Running this test gives the following in the console:
|
||||||
might want to `static_assert` over the fact that `T` is an arithmetic
|
|
||||||
type... or generalize the matcher to cover any type for which the user
|
|
||||||
can provide a comparison function object.
|
|
||||||
|
|
||||||
Note that while any matcher written using the old style can also be
|
|
||||||
written using the new style, combining old style matchers should
|
|
||||||
generally compile faster. Also note that you can combine old and new
|
|
||||||
style matchers arbitrarily.
|
|
||||||
|
|
||||||
> `MatcherBase` lives in `catch2/matchers/catch_matchers.hpp`
|
|
||||||
|
|
||||||
|
|
||||||
## Writing custom matchers (new style)
|
|
||||||
|
|
||||||
> New style matchers were introduced in Catch 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
|
|
||||||
also provide two methods, `bool match( ... ) const` and overriden
|
|
||||||
`std::string describe() const`.
|
|
||||||
|
|
||||||
Unlike with old-style matchers, there are no requirements on how
|
|
||||||
the `match` member function takes its argument. This means that the
|
|
||||||
argument can be taken by value or by mutating reference, but also that
|
|
||||||
the matcher's `match` member function can be templated.
|
|
||||||
|
|
||||||
This allows you to write more complex matcher, such as a matcher that
|
|
||||||
can compare one range-like (something that responds to `begin` and
|
|
||||||
`end`) object to another, like in the following example:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
|
||||||
#include <catch2/matchers/catch_matchers_templated.hpp>
|
|
||||||
// ...
|
|
||||||
|
|
||||||
template<typename Range>
|
|
||||||
struct EqualsRangeMatcher : Catch::Matchers::MatcherGenericBase {
|
|
||||||
EqualsRangeMatcher(Range const& range):
|
|
||||||
range{ range }
|
|
||||||
{}
|
|
||||||
|
|
||||||
template<typename OtherRange>
|
|
||||||
bool match(OtherRange const& other) const {
|
|
||||||
using std::begin; using std::end;
|
|
||||||
|
|
||||||
return std::equal(begin(range), end(range), begin(other), end(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string describe() const override {
|
|
||||||
return "Equals: " + Catch::rangeToString(range);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Range const& range;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename Range>
|
|
||||||
auto EqualsRange(const Range& range) -> EqualsRangeMatcher<Range> {
|
|
||||||
return EqualsRangeMatcher<Range>{range};
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("Combining templated matchers", "[matchers][templated]") {
|
|
||||||
std::array<int, 3> container{{ 1,2,3 }};
|
|
||||||
|
|
||||||
std::array<int, 3> a{{ 1,2,3 }};
|
|
||||||
std::vector<int> b{ 0,1,2 };
|
|
||||||
std::list<int> c{ 4,5,6 };
|
|
||||||
|
|
||||||
REQUIRE_THAT(container, EqualsRange(a) || EqualsRange(b) || EqualsRange(c));
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
/**/TestFile.cpp:123: FAILED:
|
||||||
Do note that while you can rewrite any matcher from the old style to
|
CHECK_THAT( 100, IsBetween( 1, 10 ) )
|
||||||
a new style matcher, combining new style matchers is more expensive
|
with expansion:
|
||||||
in terms of compilation time. Also note that you can combine old style
|
100 is between 1 and 10
|
||||||
and new style matchers arbitrarily.
|
```
|
||||||
|
|
||||||
> `MatcherGenericBase` lives in `catch2/matchers/catch_matchers_templated.hpp`
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@@ -11,9 +11,9 @@ The easiest way to use Catch is to let it supply ```main()``` for you and handle
|
|||||||
|
|
||||||
This is achieved by writing ```#define CATCH_CONFIG_MAIN``` before the ```#include "catch.hpp"``` in *exactly one* source file.
|
This is achieved by writing ```#define CATCH_CONFIG_MAIN``` before the ```#include "catch.hpp"``` in *exactly one* source file.
|
||||||
|
|
||||||
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.
|
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. You now have a lot of flexibility - but here are three recipes to get your started:
|
||||||
|
|
||||||
You now have a lot of flexibility - but here are three recipes to get your started:
|
**Important note: you can only provide `main` in the same file you defined `CATCH_CONFIG_RUNNER`.**
|
||||||
|
|
||||||
## Let Catch take full control of args and config
|
## Let Catch take full control of args and config
|
||||||
|
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
# Release notes
|
# Release notes
|
||||||
**Contents**<br>
|
**Contents**<br>
|
||||||
[3.0.1](#301)<br>
|
|
||||||
[2.13.2](#2132)<br>
|
[2.13.2](#2132)<br>
|
||||||
[2.13.1](#2131)<br>
|
[2.13.1](#2131)<br>
|
||||||
[2.13.0](#2130)<br>
|
[2.13.0](#2130)<br>
|
||||||
@@ -44,116 +43,6 @@
|
|||||||
[Even Older versions](#even-older-versions)<br>
|
[Even Older versions](#even-older-versions)<br>
|
||||||
|
|
||||||
|
|
||||||
## 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.**
|
|
||||||
|
|
||||||
For quick'n'dirty migration, you can replace the old `#include <catch2/catch.hpp>`
|
|
||||||
with `#include <catch2/catch_all.hpp>`. This is a (one of) convenience
|
|
||||||
header(s) that brings in _all_ of headers in Catch2. By doing this,
|
|
||||||
you should be able to migrate instantly, but at the cost of (significantly)
|
|
||||||
increased compilation times. You should prefer piecemeal including
|
|
||||||
headers that are actually required by your test code.
|
|
||||||
|
|
||||||
The basic set of functionality (`TEST_CASE`, `SECTION`, `REQUIRE`) is in
|
|
||||||
`catch2/catch_test_macros.hpp`. Matchers are in `matchers` subfolder,
|
|
||||||
generators in `generators` subfolder, and so on.
|
|
||||||
|
|
||||||
Note that documentation has not yet been updated to account for the
|
|
||||||
new design.
|
|
||||||
|
|
||||||
|
|
||||||
### FAQ
|
|
||||||
|
|
||||||
* Why is Catch2 moving to separate headers?
|
|
||||||
* The short answer is future extensibility and scalability. The long answer is complex and can be found on my blog, but at the most basic level, it is that providing single-header distribution is at odds with providing variety of useful features. When Catch2 was distributed in a single header, adding a new Matcher would cause overhead for everyone, but was useful only to a subset of users. This meant that the barrier to entry for new Matchers/Generators/etc is high in single header model, but much smaller in the new model.
|
|
||||||
* 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.
|
|
||||||
|
|
||||||
|
|
||||||
### (Potentially) Breaking changes
|
|
||||||
* **Catch2 now uses statically compiled library as its distribution model**
|
|
||||||
* **Including `catch.hpp` no longer works**
|
|
||||||
* `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)
|
|
||||||
* You should use verbosity-modifiers for `--list-tests` instead
|
|
||||||
* `--list*` commands are now piped through the reporters
|
|
||||||
* The top-level reporter interface provides default implementation that works just as the old one
|
|
||||||
* XmlReporter outputs a machine-parseable XML
|
|
||||||
* `TEST_CASE` description support has been removed
|
|
||||||
* If the second argument has text outside tags, the text will be ignored.
|
|
||||||
* Hidden test cases are no longer included just because they don't match an exclusion tag
|
|
||||||
* Previously, a `TEST_CASE("A", "[.foo]")` would be included by asking for `~[bar]`.
|
|
||||||
* `PredicateMatcher` is no longer type erased.
|
|
||||||
* This means that the type of the provided predicate is part of the `PredicateMatcher`'s type
|
|
||||||
* `SectionInfo` no longer contains section description as a member (#1319)
|
|
||||||
* You can still write `SECTION("ShortName", "Long and wordy description")`, but the description is thrown away
|
|
||||||
* The description type now must be a `const char*` or be implicitly convertible to it
|
|
||||||
* The `[!hide]` tag has been removed.
|
|
||||||
* Use `[.]` or `[.foo]` instead.
|
|
||||||
* Lvalues of composed matchers cannot be composed further
|
|
||||||
* Uses of `REGISTER_TEST_CASE` macro need to be followed by a semicolon
|
|
||||||
* This does not change `TEST_CASE` and friends in any way
|
|
||||||
* `IStreamingReporter::IsMulti` member function was removed
|
|
||||||
* This is _very_ unlikely to actually affect anyone, as it was default-implemented in the interface, and only used internally
|
|
||||||
* Various classes not designed for user-extension have been made final
|
|
||||||
* `ListeningReporter` is now `final`
|
|
||||||
* Concrete Matchers (e.g. `UnorderedEquals` vector matcher) are now `final`
|
|
||||||
* All Generators are now `final`
|
|
||||||
* Matcher namespacing has been redone
|
|
||||||
* Matcher types are no longer in deeply nested namespaces
|
|
||||||
* Matcher factory functions are no longer brought into `Catch` namespace
|
|
||||||
* This means that all public-facing matcher-related functionality is now in `Catch::Matchers` namespace
|
|
||||||
* Defining `CATCH_CONFIG_MAIN` will no longer create main in that TU.
|
|
||||||
* Link with `libCatch2Main.a`, or the proper CMake/pkg-config target
|
|
||||||
* If you want to write custom main, include `catch2/catch_session.hpp`
|
|
||||||
* `CATCH_CONFIG_EXTERNAL_INTERFACES` has been removed.
|
|
||||||
* You should instead include the appropriate headers as needed.
|
|
||||||
* `CATCH_CONFIG_IMPL` has been removed.
|
|
||||||
* The implementation is now compiled into a static library.
|
|
||||||
* Event Listener interface has changed
|
|
||||||
* `TestEventListenerBase` was renamed to `EventListenerBase`
|
|
||||||
* `EventListenerBase` now directly derives from `IStreamingReporter`, instead of deriving from `StreamingReporterBase`
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Improvements
|
|
||||||
* Matchers have been extended with the ability to use different signatures of `match` (#1307, #1553, #1554, #1843)
|
|
||||||
* 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
|
|
||||||
* Significant compilation time improvements
|
|
||||||
* including `catch_test_macros.hpp` is 80% cheaper than including `catch.hpp`
|
|
||||||
|
|
||||||
|
|
||||||
### Fixes
|
|
||||||
* The `INFO` macro no longer contains superfluous semicolon (#1456)
|
|
||||||
* The `--list*` family of command line flags now return 0 on success (#1410, #1146)
|
|
||||||
|
|
||||||
|
|
||||||
### Other changes
|
|
||||||
* `CATCH_CONFIG_DISABLE_MATCHERS` no longer exists.
|
|
||||||
* If you do not want to use Matchers in a TU, do not include their header.
|
|
||||||
* `CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER` no longer exists.
|
|
||||||
* `StringMaker` specializations for `<chrono>` are always provided
|
|
||||||
* Catch2's CMake now provides 2 targets, `Catch2` and `Catch2WithMain`.
|
|
||||||
* `Catch2` is the statically compiled implementation by itself
|
|
||||||
* `Catch2WithMain` also links in the default main
|
|
||||||
* 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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 2.13.2
|
## 2.13.2
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
@@ -246,7 +135,6 @@ new design.
|
|||||||
* Added support for `^` (bitwise xor) to `CHECK` and `REQUIRE`
|
* Added support for `^` (bitwise xor) to `CHECK` and `REQUIRE`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 2.12.0
|
## 2.12.0
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
@@ -269,7 +157,6 @@ new design.
|
|||||||
* Improved detection of stdlib's support for `std::uncaught_exceptions` (#1911)
|
* Improved detection of stdlib's support for `std::uncaught_exceptions` (#1911)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 2.11.3
|
## 2.11.3
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
@@ -301,7 +188,6 @@ new design.
|
|||||||
* This bug has been present for the last ~2 years and nobody reported it
|
* This bug has been present for the last ~2 years and nobody reported it
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 2.11.1
|
## 2.11.1
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
@@ -315,7 +201,6 @@ new design.
|
|||||||
* Some more cleanups in the benchmarking support
|
* Some more cleanups in the benchmarking support
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 2.11.0
|
## 2.11.0
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
@@ -449,7 +334,6 @@ new design.
|
|||||||
### Fixes
|
### Fixes
|
||||||
* Fix benchmarking compilation failure in files without `CATCH_CONFIG_EXTERNAL_INTERFACES` (or implementation)
|
* Fix benchmarking compilation failure in files without `CATCH_CONFIG_EXTERNAL_INTERFACES` (or implementation)
|
||||||
|
|
||||||
|
|
||||||
## 2.9.0
|
## 2.9.0
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<a id="top"></a>
|
<a id="top"></a>
|
||||||
# How to release
|
# How to release
|
||||||
|
|
||||||
When enough changes have accumulated, it is time to release new version of Catch. This document describes the process in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `tools/scripts/` directory.
|
When enough changes have accumulated, it is time to release new version of Catch. This document describes the process in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `scripts/` directory.
|
||||||
|
|
||||||
## Necessary steps
|
## Necessary steps
|
||||||
|
|
||||||
@@ -67,6 +67,7 @@ $ gpg2 --armor --output catch.hpp.asc --detach-sig catch.hpp
|
|||||||
$ gpg2 --armor --output catch_reporter_automake.hpp.asc --detach-sig catch_reporter_automake.hpp
|
$ gpg2 --armor --output catch_reporter_automake.hpp.asc --detach-sig catch_reporter_automake.hpp
|
||||||
$ gpg2 --armor --output catch_reporter_teamcity.hpp.asc --detach-sig catch_reporter_teamcity.hpp
|
$ gpg2 --armor --output catch_reporter_teamcity.hpp.asc --detach-sig catch_reporter_teamcity.hpp
|
||||||
$ gpg2 --armor --output catch_reporter_tap.hpp.asc --detach-sig catch_reporter_tap.hpp
|
$ gpg2 --armor --output catch_reporter_tap.hpp.asc --detach-sig catch_reporter_tap.hpp
|
||||||
|
$ gpg2 --armor --output catch_reporter_sonarqube.hpp.asc --detach-sig catch_reporter_sonarqube.hpp
|
||||||
```
|
```
|
||||||
|
|
||||||
_GPG does not support signing multiple files in single invocation._
|
_GPG does not support signing multiple files in single invocation._
|
||||||
|
@@ -15,17 +15,9 @@ Instead Catch provides a powerful mechanism for nesting test case sections withi
|
|||||||
Test cases and sections are very easy to use in practice:
|
Test cases and sections are very easy to use in practice:
|
||||||
|
|
||||||
* **TEST_CASE(** _test name_ \[, _tags_ \] **)**
|
* **TEST_CASE(** _test name_ \[, _tags_ \] **)**
|
||||||
* **SECTION(** _section name_, \[, _section description_ \] **)**
|
* **SECTION(** _section name_ **)**
|
||||||
|
|
||||||
|
_test name_ and _section name_ are free form, quoted, strings. The optional _tags_ argument is a quoted string containing one or more tags enclosed in square brackets. Tags are discussed below. Test names must be unique within the Catch executable.
|
||||||
_test name_ and _section name_ are free form, quoted, strings.
|
|
||||||
The optional _tags_ argument is a quoted string containing one or more
|
|
||||||
tags enclosed in square brackets, and are discussed below.
|
|
||||||
_section description_ can be used to provide long form description
|
|
||||||
of a section while keeping the _section name_ short for use with the
|
|
||||||
[`-c` command line parameter](command-line.md#specify-the-section-to-run).
|
|
||||||
|
|
||||||
**Test names must be unique within the Catch executable.**
|
|
||||||
|
|
||||||
For examples see the [Tutorial](tutorial.md#top)
|
For examples see the [Tutorial](tutorial.md#top)
|
||||||
|
|
||||||
@@ -50,7 +42,7 @@ Tag names are not case sensitive and can contain any ASCII characters. This mean
|
|||||||
|
|
||||||
All tag names beginning with non-alphanumeric characters are reserved by Catch. Catch defines a number of "special" tags, which have meaning to the test runner itself. These special tags all begin with a symbol character. Following is a list of currently defined special tags and their meanings.
|
All tag names beginning with non-alphanumeric characters are reserved by Catch. Catch defines a number of "special" tags, which have meaning to the test runner itself. These special tags all begin with a symbol character. Following is a list of currently defined special tags and their meanings.
|
||||||
|
|
||||||
* `[.]` - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`.
|
* `[!hide]` or `[.]` - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`. Because the hide tag has evolved to have several forms, all forms are added as tags if you use one of them.
|
||||||
|
|
||||||
* `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
|
* `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
|
||||||
|
|
||||||
|
@@ -64,7 +64,7 @@ namespace Catch {
|
|||||||
By default all exceptions deriving from `std::exception` will be translated to strings by calling the `what()` method. For exception types that do not derive from `std::exception` - or if `what()` does not return a suitable string - use `CATCH_TRANSLATE_EXCEPTION`. This defines a function that takes your exception type, by reference, and returns a string. It can appear anywhere in the code - it doesn't have to be in the same translation unit. For example:
|
By default all exceptions deriving from `std::exception` will be translated to strings by calling the `what()` method. For exception types that do not derive from `std::exception` - or if `what()` does not return a suitable string - use `CATCH_TRANSLATE_EXCEPTION`. This defines a function that takes your exception type, by reference, and returns a string. It can appear anywhere in the code - it doesn't have to be in the same translation unit. For example:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
CATCH_TRANSLATE_EXCEPTION( MyType const& ex ) {
|
CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
|
||||||
return ex.message();
|
return ex.message();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
// 000-CatchMain.cpp
|
// 000-CatchMain.cpp
|
||||||
|
|
||||||
// It is generally recommended to have a single file provide the main
|
// In a Catch project with multiple files, dedicate one file to compile the
|
||||||
// of a testing binary, and other test files to link against it.
|
// source code of Catch itself and reuse the resulting object file for linking.
|
||||||
|
|
||||||
// Let Catch provide main():
|
// Let Catch provide main():
|
||||||
#include <catch2/internal/catch_default_main.hpp>
|
#define CATCH_CONFIG_MAIN
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
// That's it
|
// That's it
|
||||||
|
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
// 010-TestCase.cpp
|
// 010-TestCase.cpp
|
||||||
// And write tests in the same file:
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
|
||||||
|
|
||||||
static int Factorial( int number ) {
|
// Let Catch provide main():
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
int Factorial( int number ) {
|
||||||
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
|
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
|
||||||
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
|
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,12 @@
|
|||||||
// 020-TestCase-1.cpp
|
// 020-TestCase-1.cpp
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
// In a Catch project with multiple files, dedicate one file to compile the
|
||||||
|
// source code of Catch itself and reuse the resulting object file for linking.
|
||||||
|
|
||||||
|
// Let Catch provide main():
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:1]" ) {
|
TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:1]" ) {
|
||||||
}
|
}
|
||||||
|
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
// main() provided by Catch in file 020-TestCase-1.cpp.
|
// main() provided by Catch in file 020-TestCase-1.cpp.
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
static int Factorial( int number ) {
|
int Factorial( int number ) {
|
||||||
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
|
return number <= 1 ? number : Factorial( number - 1 ) * number; // fail
|
||||||
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
|
// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass
|
||||||
}
|
}
|
||||||
|
@@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
// main() provided in 000-CatchMain.cpp
|
// main() provided in 000-CatchMain.cpp
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
static std::string one() {
|
std::string one() {
|
||||||
return "1";
|
return "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,8 +6,7 @@
|
|||||||
|
|
||||||
// main() provided in 000-CatchMain.cpp
|
// main() provided in 000-CatchMain.cpp
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
// main() provided in 000-CatchMain.cpp
|
// main() provided in 000-CatchMain.cpp
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
class DBConnection
|
class DBConnection
|
||||||
{
|
{
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// main() provided in 000-CatchMain.cpp
|
// main() provided in 000-CatchMain.cpp
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
||||||
|
|
||||||
|
27
examples/200-Rpt-CatchMain.cpp
Normal file
27
examples/200-Rpt-CatchMain.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// 200-Rpt-CatchMain.cpp
|
||||||
|
|
||||||
|
// In a Catch project with multiple files, dedicate one file to compile the
|
||||||
|
// source code of Catch itself and reuse the resulting object file for linking.
|
||||||
|
|
||||||
|
// Let Catch provide main():
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
#ifdef CATCH_EXAMPLE_RPT_1
|
||||||
|
#include CATCH_EXAMPLE_RPT_1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CATCH_EXAMPLE_RPT_2
|
||||||
|
#include CATCH_EXAMPLE_RPT_2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CATCH_EXAMPLE_RPT_3
|
||||||
|
#include CATCH_EXAMPLE_RPT_3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// That's it
|
||||||
|
|
||||||
|
// Compile implementation of Catch for use with files that do contain tests:
|
||||||
|
// - g++ -std=c++11 -Wall -I$(CATCH_ROOT) -DCATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_teamcity.hpp\" -o 200-Rpt-CatchMainTeamCity.o -c 200-Rpt-CatchMain.cpp
|
||||||
|
// cl -EHsc -I%CATCH_ROOT% -DCATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_teamcity.hpp\" -Fo200-Rpt-CatchMainTeamCity.obj -c 200-Rpt-CatchMain.cpp
|
171
examples/207-Rpt-TeamCityReporter.cpp
Normal file
171
examples/207-Rpt-TeamCityReporter.cpp
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
// 207-Rpt-TeamCityReporter.cpp
|
||||||
|
|
||||||
|
// Catch has built-in and external reporters:
|
||||||
|
// Built-in:
|
||||||
|
// - compact
|
||||||
|
// - console
|
||||||
|
// - junit
|
||||||
|
// - xml
|
||||||
|
// External:
|
||||||
|
// - automake
|
||||||
|
// - tap
|
||||||
|
// - teamcity (this example)
|
||||||
|
|
||||||
|
// main() and reporter code provided in 200-Rpt-CatchMain.cpp
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# pragma warning (disable : 4702) // Disable warning: unreachable code
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity passes unconditionally succeeding assertion", "[teamcity]" ) {
|
||||||
|
|
||||||
|
SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports unconditionally failing assertion", "[teamcity]" ) {
|
||||||
|
|
||||||
|
FAIL();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports failing check", "[teamcity]" ) {
|
||||||
|
|
||||||
|
REQUIRE( 3 == 7 );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports failing check-false", "[teamcity]" ) {
|
||||||
|
|
||||||
|
REQUIRE_FALSE( 3 == 3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports failing check-that", "[teamcity]" ) {
|
||||||
|
|
||||||
|
using namespace Catch;
|
||||||
|
|
||||||
|
REQUIRE_THAT( "hello", Contains( "world" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports unexpected exception", "[teamcity]" ) {
|
||||||
|
|
||||||
|
REQUIRE( (throw std::runtime_error("surprise!"), true) );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports undesired exception", "[teamcity]" ) {
|
||||||
|
|
||||||
|
REQUIRE_NOTHROW( (throw std::runtime_error("surprise!"), true) );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports missing expected exception", "[teamcity]" ) {
|
||||||
|
|
||||||
|
REQUIRE_THROWS( true );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports missing specific expected exception", "[teamcity]" ) {
|
||||||
|
|
||||||
|
REQUIRE_THROWS_AS( throw std::bad_alloc(), std::runtime_error );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity reports unexpected message in expected exception", "[teamcity]" ) {
|
||||||
|
|
||||||
|
using namespace Catch;
|
||||||
|
|
||||||
|
CHECK_THROWS_WITH( throw std::runtime_error("hello"), "world" );
|
||||||
|
CHECK_THROWS_WITH( throw std::runtime_error("hello"), Contains("world") );
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MyException: public std::runtime_error
|
||||||
|
{
|
||||||
|
MyException( char const * text )
|
||||||
|
: std::runtime_error( text ) {}
|
||||||
|
|
||||||
|
~MyException() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
// prevent -Wweak-vtables:
|
||||||
|
MyException::~MyException() = default;
|
||||||
|
|
||||||
|
struct MyExceptionMatcher : Catch::MatcherBase< std::runtime_error >
|
||||||
|
{
|
||||||
|
std::string m_text;
|
||||||
|
|
||||||
|
MyExceptionMatcher( char const * text )
|
||||||
|
: m_text( text )
|
||||||
|
{}
|
||||||
|
|
||||||
|
~MyExceptionMatcher() override;
|
||||||
|
|
||||||
|
bool match( std::runtime_error const & arg ) const override
|
||||||
|
{
|
||||||
|
return m_text == arg.what() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string describe() const override
|
||||||
|
{
|
||||||
|
return "it's me";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// prevent -Wweak-vtables:
|
||||||
|
MyExceptionMatcher::~MyExceptionMatcher() = default;
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity failing check-throws-matches", "[teamcity]" ) {
|
||||||
|
|
||||||
|
CHECK_THROWS_MATCHES( throw MyException("hello"), MyException, MyExceptionMatcher("world") );
|
||||||
|
}
|
||||||
|
|
||||||
|
// [!throws] - lets Catch know that this test is likely to throw an exception even if successful.
|
||||||
|
// This causes the test to be excluded when running with -e or --nothrow.
|
||||||
|
|
||||||
|
// No special effects for the reporter.
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity throwing exception with tag [!throws]", "[teamcity][!throws]" ) {
|
||||||
|
|
||||||
|
REQUIRE_THROWS( throw std::runtime_error("unsurprisingly") );
|
||||||
|
}
|
||||||
|
|
||||||
|
// [!mayfail] - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in your tests.
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity failing assertion with tag [!mayfail]", "[teamcity][!mayfail] " ) {
|
||||||
|
|
||||||
|
REQUIRE( 3 == 7 ); // doesn't fail test case this time, reports: testIgnored
|
||||||
|
REQUIRE( 3 == 3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// [!shouldfail] - like [!mayfail] but fails the test if it passes.
|
||||||
|
// This can be useful if you want to be notified of accidental, or third-party, fixes.
|
||||||
|
|
||||||
|
TEST_CASE( "TeamCity succeeding assertion with tag [!shouldfail]", "[teamcity][!shouldfail]" ) {
|
||||||
|
|
||||||
|
SUCCEED( "Marked [!shouldfail]" );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile & run:
|
||||||
|
// - g++ -std=c++11 -Wall -I$(CATCH_ROOT) -DCATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_teamcity.hpp\" -o 200-Rpt-CatchMainTeamCity.o -c 200-Rpt-CatchMain.cpp
|
||||||
|
// - g++ -std=c++11 -Wall -I$(CATCH_ROOT) -o 207-Rpt-TeamCityReporter 207-Rpt-TeamCityReporter.cpp 200-Rpt-CatchMainTeamCity.o && 207-Rpt-TeamCityReporter --list-reporters
|
||||||
|
//
|
||||||
|
// - cl -EHsc -I%CATCH_ROOT% -DCATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_teamcity.hpp\" -Fo200-Rpt-CatchMainTeamCity.obj -c 200-Rpt-CatchMain.cpp
|
||||||
|
// - cl -EHsc -I%CATCH_ROOT% 207-Rpt-TeamCityReporter.cpp 200-Rpt-CatchMainTeamCity.o && 207-Rpt-TeamCityReporter --list-reporters
|
||||||
|
|
||||||
|
// Compilation output (--list-reporters):
|
||||||
|
// Available reporters:
|
||||||
|
// compact: Reports test results on a single line, suitable for IDEs
|
||||||
|
// console: Reports test results as plain lines of text
|
||||||
|
// junit: Reports test results in an XML format that looks like Ant's
|
||||||
|
// junitreport target
|
||||||
|
// teamcity: Reports test results as TeamCity service messages
|
||||||
|
// xml: Reports test results as an XML document
|
||||||
|
|
||||||
|
// Expected output (abbreviated and broken into shorter lines):
|
||||||
|
//
|
||||||
|
// prompt> 207-Rpt-TeamCityReporter.exe --reporter teamcity
|
||||||
|
// ##teamcity[testSuiteStarted name='207-Rpt-TeamCityReporter.exe']
|
||||||
|
// ##teamcity[testStarted name='TeamCity passes unconditionally succeeding assertion']
|
||||||
|
// ##teamcity[testFinished name='TeamCity passes unconditionally succeeding assertion' duration='1']
|
||||||
|
// ##teamcity[testStarted name='TeamCity reports unconditionally failing assertion']
|
||||||
|
// ##teamcity[testFailed name='TeamCity reports unconditionally failing assertion' /
|
||||||
|
// message='.../examples/207-Rpt-TeamCityReporter.cpp:23|n/
|
||||||
|
// ...............................................................................|n|n/
|
||||||
|
// .../examples/207-Rpt-TeamCityReporter.cpp:25|nexplicit failure']
|
||||||
|
// ##teamcity[testFinished name='TeamCity reports unconditionally failing assertion' duration='3']
|
||||||
|
// ...
|
@@ -5,26 +5,22 @@
|
|||||||
// 2. My listener and registration
|
// 2. My listener and registration
|
||||||
// 3. Test cases
|
// 3. Test cases
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
// main() provided in 000-CatchMain.cpp
|
||||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
|
||||||
#include <catch2/catch_reporter_registrars.hpp>
|
// Let Catch provide the required interfaces:
|
||||||
#include <catch2/catch_test_case_info.hpp>
|
#define CATCH_CONFIG_EXTERNAL_INTERFACES
|
||||||
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// 1. Printing of listener data:
|
// 1. Printing of listener data:
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
std::string ws(int const level) {
|
std::string ws(int const level) {
|
||||||
return std::string( 2 * level, ' ' );
|
return std::string( 2 * level, ' ' );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, Catch::Tag t) {
|
|
||||||
return out << "original: " << t.original << "lower cased: " << t.lowerCased;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename T >
|
template< typename T >
|
||||||
std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
||||||
os << "{ ";
|
os << "{ ";
|
||||||
@@ -32,6 +28,7 @@ std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
|||||||
os << x << ", ";
|
os << x << ", ";
|
||||||
return os << "}";
|
return os << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct SourceLineInfo {
|
// struct SourceLineInfo {
|
||||||
// char const* file;
|
// char const* file;
|
||||||
// std::size_t line;
|
// std::size_t line;
|
||||||
@@ -122,36 +119,32 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
|||||||
os << ws(level+1) << "- aborting: " << info.aborting << "\n";
|
os << ws(level+1) << "- aborting: " << info.aborting << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct Tag {
|
// struct TestCaseInfo {
|
||||||
// StringRef original, lowerCased;
|
// enum SpecialProperties{
|
||||||
// };
|
// None = 0,
|
||||||
|
// IsHidden = 1 << 1,
|
||||||
|
// ShouldFail = 1 << 2,
|
||||||
|
// MayFail = 1 << 3,
|
||||||
|
// Throws = 1 << 4,
|
||||||
|
// NonPortable = 1 << 5,
|
||||||
|
// Benchmark = 1 << 6
|
||||||
|
// };
|
||||||
//
|
//
|
||||||
|
// bool isHidden() const;
|
||||||
|
// bool throws() const;
|
||||||
|
// bool okToFail() const;
|
||||||
|
// bool expectedToFail() const;
|
||||||
//
|
//
|
||||||
// enum class TestCaseProperties : uint8_t {
|
// std::string tagsAsString() const;
|
||||||
// None = 0,
|
|
||||||
// IsHidden = 1 << 1,
|
|
||||||
// ShouldFail = 1 << 2,
|
|
||||||
// MayFail = 1 << 3,
|
|
||||||
// Throws = 1 << 4,
|
|
||||||
// NonPortable = 1 << 5,
|
|
||||||
// Benchmark = 1 << 6
|
|
||||||
// };
|
|
||||||
//
|
//
|
||||||
//
|
// std::string name;
|
||||||
// struct TestCaseInfo : NonCopyable {
|
// std::string className;
|
||||||
//
|
// std::string description;
|
||||||
// bool isHidden() const;
|
// std::vector<std::string> tags;
|
||||||
// bool throws() const;
|
// std::vector<std::string> lcaseTags;
|
||||||
// bool okToFail() const;
|
// SourceLineInfo lineInfo;
|
||||||
// bool expectedToFail() const;
|
// SpecialProperties properties;
|
||||||
//
|
// };
|
||||||
//
|
|
||||||
// std::string name;
|
|
||||||
// std::string className;
|
|
||||||
// std::vector<Tag> tags;
|
|
||||||
// SourceLineInfo lineInfo;
|
|
||||||
// TestCaseProperties properties = TestCaseProperties::None;
|
|
||||||
// };
|
|
||||||
|
|
||||||
void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseInfo const& info ) {
|
void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseInfo const& info ) {
|
||||||
os << ws(level ) << title << ":\n"
|
os << ws(level ) << title << ":\n"
|
||||||
@@ -162,9 +155,11 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
|||||||
<< ws(level+1) << "- tagsAsString(): '" << info.tagsAsString() << "'\n"
|
<< ws(level+1) << "- tagsAsString(): '" << info.tagsAsString() << "'\n"
|
||||||
<< ws(level+1) << "- name: '" << info.name << "'\n"
|
<< ws(level+1) << "- name: '" << info.name << "'\n"
|
||||||
<< ws(level+1) << "- className: '" << info.className << "'\n"
|
<< ws(level+1) << "- className: '" << info.className << "'\n"
|
||||||
<< ws(level+1) << "- tags: " << info.tags << "\n";
|
<< ws(level+1) << "- description: '" << info.description << "'\n"
|
||||||
|
<< ws(level+1) << "- tags: " << info.tags << "\n"
|
||||||
|
<< ws(level+1) << "- lcaseTags: " << info.lcaseTags << "\n";
|
||||||
print( os, level+1 , "- lineInfo", info.lineInfo );
|
print( os, level+1 , "- lineInfo", info.lineInfo );
|
||||||
os << ws(level+1) << "- properties (flags): 0x" << std::hex << static_cast<uint32_t>(info.properties) << std::dec << "\n";
|
os << ws(level+1) << "- properties (flags): 0x" << std::hex << info.properties << std::dec << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct TestCaseStats {
|
// struct TestCaseStats {
|
||||||
@@ -177,7 +172,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
|||||||
|
|
||||||
void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseStats const& info ) {
|
void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseStats const& info ) {
|
||||||
os << ws(level ) << title << ":\n";
|
os << ws(level ) << title << ":\n";
|
||||||
print( os, level+1 , "- testInfo", *info.testInfo );
|
print( os, level+1 , "- testInfo", info.testInfo );
|
||||||
print( os, level+1 , "- totals" , info.totals );
|
print( os, level+1 , "- totals" , info.totals );
|
||||||
os << ws(level+1) << "- stdOut: " << info.stdOut << "\n"
|
os << ws(level+1) << "- stdOut: " << info.stdOut << "\n"
|
||||||
<< ws(level+1) << "- stdErr: " << info.stdErr << "\n"
|
<< ws(level+1) << "- stdErr: " << info.stdErr << "\n"
|
||||||
@@ -278,8 +273,8 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
|||||||
print( os, level+1 , "- getSourceInfo(): ", info.getSourceInfo() );
|
print( os, level+1 , "- getSourceInfo(): ", info.getSourceInfo() );
|
||||||
os << ws(level+1) << "- getTestMacroName(): '" << info.getTestMacroName() << "'\n";
|
os << ws(level+1) << "- getTestMacroName(): '" << info.getTestMacroName() << "'\n";
|
||||||
|
|
||||||
print( os, level+1 , "- *** m_info (AssertionInfo)", info.m_info );
|
// print( os, level+1 , "- *** m_info (AssertionInfo)", info.m_info );
|
||||||
print( os, level+1 , "- *** m_resultData (AssertionResultData)", info.m_resultData );
|
// print( os, level+1 , "- *** m_resultData (AssertionResultData)", info.m_resultData );
|
||||||
}
|
}
|
||||||
|
|
||||||
// struct AssertionStats {
|
// struct AssertionStats {
|
||||||
@@ -302,10 +297,9 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
|||||||
char const * dashed_line =
|
char const * dashed_line =
|
||||||
"--------------------------------------------------------------------------";
|
"--------------------------------------------------------------------------";
|
||||||
|
|
||||||
|
struct MyListener : Catch::TestEventListenerBase {
|
||||||
|
|
||||||
struct MyListener : Catch::EventListenerBase {
|
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
|
||||||
|
|
||||||
using EventListenerBase::EventListenerBase; // inherit constructor
|
|
||||||
|
|
||||||
// Get rid of Wweak-tables
|
// Get rid of Wweak-tables
|
||||||
~MyListener();
|
~MyListener();
|
||||||
@@ -373,8 +367,6 @@ struct MyListener : Catch::EventListenerBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
CATCH_REGISTER_LISTENER( MyListener )
|
CATCH_REGISTER_LISTENER( MyListener )
|
||||||
|
|
||||||
// Get rid of Wweak-tables
|
// Get rid of Wweak-tables
|
||||||
|
@@ -5,10 +5,11 @@
|
|||||||
// semantic, because it buffers the output. For most uses however,
|
// semantic, because it buffers the output. For most uses however,
|
||||||
// there is no important difference between having `std::cerr` buffered
|
// there is no important difference between having `std::cerr` buffered
|
||||||
// or unbuffered.
|
// or unbuffered.
|
||||||
#include <catch2/catch_test_macros.hpp>
|
|
||||||
|
|
||||||
#include <sstream>
|
#define CATCH_CONFIG_NOSTDOUT
|
||||||
#include <cstdio>
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
|
||||||
class out_buff : public std::stringbuf {
|
class out_buff : public std::stringbuf {
|
||||||
std::FILE* m_stream;
|
std::FILE* m_stream;
|
||||||
|
@@ -4,14 +4,10 @@
|
|||||||
// Specifically we will implement a random number generator for integers
|
// Specifically we will implement a random number generator for integers
|
||||||
// It will have infinite capacity and settable lower/upper bound
|
// It will have infinite capacity and settable lower/upper bound
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <catch2/generators/catch_generators.hpp>
|
|
||||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
|
||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// This class shows how to implement a simple generator for Catch tests
|
// This class shows how to implement a simple generator for Catch tests
|
||||||
class RandomIntGenerator : public Catch::Generators::IGenerator<int> {
|
class RandomIntGenerator : public Catch::Generators::IGenerator<int> {
|
||||||
std::minstd_rand m_rand;
|
std::minstd_rand m_rand;
|
||||||
@@ -42,15 +38,9 @@ int const& RandomIntGenerator::get() const {
|
|||||||
// Notice that it returns an instance of GeneratorWrapper<int>, which
|
// Notice that it returns an instance of GeneratorWrapper<int>, which
|
||||||
// is a value-wrapper around std::unique_ptr<IGenerator<int>>.
|
// is a value-wrapper around std::unique_ptr<IGenerator<int>>.
|
||||||
Catch::Generators::GeneratorWrapper<int> random(int low, int high) {
|
Catch::Generators::GeneratorWrapper<int> random(int low, int high) {
|
||||||
return Catch::Generators::GeneratorWrapper<int>(
|
return Catch::Generators::GeneratorWrapper<int>(std::unique_ptr<Catch::Generators::IGenerator<int>>(new RandomIntGenerator(low, high)));
|
||||||
new RandomIntGenerator(low, high)
|
|
||||||
// Another possibility:
|
|
||||||
// Catch::Detail::make_unique<RandomIntGenerator>(low, high)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end anonymous namespaces
|
|
||||||
|
|
||||||
// The two sections in this test case are equivalent, but the first one
|
// The two sections in this test case are equivalent, but the first one
|
||||||
// is much more readable/nicer to use
|
// is much more readable/nicer to use
|
||||||
TEST_CASE("Generating random ints", "[example][generator]") {
|
TEST_CASE("Generating random ints", "[example][generator]") {
|
||||||
@@ -60,7 +50,7 @@ TEST_CASE("Generating random ints", "[example][generator]") {
|
|||||||
REQUIRE(i <= 100);
|
REQUIRE(i <= 100);
|
||||||
}
|
}
|
||||||
SECTION("Creating the random generator directly") {
|
SECTION("Creating the random generator directly") {
|
||||||
auto i = GENERATE(take(100, GeneratorWrapper<int>(Catch::Detail::make_unique<RandomIntGenerator>(-100, 100))));
|
auto i = GENERATE(take(100, GeneratorWrapper<int>(std::unique_ptr<IGenerator<int>>(new RandomIntGenerator(-100, 100)))));
|
||||||
REQUIRE(i >= -100);
|
REQUIRE(i >= -100);
|
||||||
REQUIRE(i <= 100);
|
REQUIRE(i <= 100);
|
||||||
}
|
}
|
||||||
|
@@ -5,14 +5,11 @@
|
|||||||
// that converts the strings using stoi, so the returned type is actually
|
// that converts the strings using stoi, so the returned type is actually
|
||||||
// an int.
|
// an int.
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// Returns a line from a stream. You could have it e.g. read lines from
|
// Returns a line from a stream. You could have it e.g. read lines from
|
||||||
// a file, but to avoid problems with paths in examples, we will use
|
// a file, but to avoid problems with paths in examples, we will use
|
||||||
// a fixed stringstream.
|
// a fixed stringstream.
|
||||||
@@ -23,12 +20,12 @@ public:
|
|||||||
LineGenerator() {
|
LineGenerator() {
|
||||||
m_stream.str("1\n2\n3\n4\n");
|
m_stream.str("1\n2\n3\n4\n");
|
||||||
if (!next()) {
|
if (!next()) {
|
||||||
Catch::Generators::Detail::throw_generator_exception("Couldn't read a single line");
|
throw Catch::GeneratorException("Couldn't read a single line");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const& get() const override;
|
std::string const& get() const override;
|
||||||
|
|
||||||
bool next() override {
|
bool next() override {
|
||||||
return !!std::getline(m_stream, m_line);
|
return !!std::getline(m_stream, m_line);
|
||||||
}
|
}
|
||||||
@@ -43,17 +40,18 @@ std::string const& LineGenerator::get() const {
|
|||||||
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
|
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
|
||||||
Catch::Generators::GeneratorWrapper<std::string> lines(std::string /* ignored for example */) {
|
Catch::Generators::GeneratorWrapper<std::string> lines(std::string /* ignored for example */) {
|
||||||
return Catch::Generators::GeneratorWrapper<std::string>(
|
return Catch::Generators::GeneratorWrapper<std::string>(
|
||||||
new LineGenerator()
|
std::unique_ptr<Catch::Generators::IGenerator<std::string>>(
|
||||||
|
new LineGenerator()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
|
|
||||||
TEST_CASE("filter can convert types inside the generator expression", "[example][generator]") {
|
TEST_CASE("filter can convert types inside the generator expression", "[example][generator]") {
|
||||||
auto num = GENERATE(map<int>([](std::string const& line) { return std::stoi(line); },
|
auto num = GENERATE(map<int>([](std::string const& line) { return std::stoi(line); },
|
||||||
lines("fake-file")));
|
lines("fake-file")));
|
||||||
|
|
||||||
REQUIRE(num > 0);
|
REQUIRE(num > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,8 +2,7 @@
|
|||||||
// Shows how to use table to run a test many times with different inputs. Lifted from examples on
|
// Shows how to use table to run a test many times with different inputs. Lifted from examples on
|
||||||
// issue #850.
|
// issue #850.
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <catch2/generators/catch_generators.hpp>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
struct TestSubject {
|
struct TestSubject {
|
||||||
|
@@ -6,9 +6,7 @@
|
|||||||
// _WILL_ outlive the variables -- thus they should be either captured
|
// _WILL_ outlive the variables -- thus they should be either captured
|
||||||
// by value directly, or copied by the generators during construction.
|
// by value directly, or copied by the generators during construction.
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
|
||||||
#include <catch2/generators/catch_generators_random.hpp>
|
|
||||||
|
|
||||||
TEST_CASE("Generate random doubles across different ranges",
|
TEST_CASE("Generate random doubles across different ranges",
|
||||||
"[generator][example][advanced]") {
|
"[generator][example][advanced]") {
|
||||||
|
@@ -9,9 +9,7 @@
|
|||||||
// per-variable custom capture list, this example shows how to achieve
|
// per-variable custom capture list, this example shows how to achieve
|
||||||
// that.
|
// that.
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
|
||||||
#include <catch2/generators/catch_generators_random.hpp>
|
|
||||||
|
|
||||||
TEST_CASE("Generate random doubles across different ranges",
|
TEST_CASE("Generate random doubles across different ranges",
|
||||||
"[generator][example][advanced]") {
|
"[generator][example][advanced]") {
|
||||||
|
@@ -1,30 +1,44 @@
|
|||||||
cmake_minimum_required( VERSION 3.5 )
|
#
|
||||||
|
# Build examples.
|
||||||
|
#
|
||||||
|
# Requires CATCH_BUILD_EXAMPLES to be defined 'true', see ../CMakeLists.txt.
|
||||||
|
#
|
||||||
|
|
||||||
project( Catch2Examples LANGUAGES CXX )
|
cmake_minimum_required( VERSION 3.0 )
|
||||||
|
|
||||||
|
project( CatchExamples CXX )
|
||||||
|
|
||||||
message( STATUS "Examples included" )
|
message( STATUS "Examples included" )
|
||||||
|
|
||||||
|
# define folders used:
|
||||||
|
|
||||||
# Some one-offs first:
|
set( EXAMPLES_DIR ${CATCH_DIR}/examples )
|
||||||
# 1) Tests and main in one file
|
set( HEADER_DIR ${CATCH_DIR}/single_include )
|
||||||
add_executable( 010-TestCase
|
set( REPORTER_HEADER_DIR ${CATCH_DIR}/include/reporters )
|
||||||
010-TestCase.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
# 2) Tests and main across two files
|
# single-file sources:
|
||||||
add_executable( 020-MultiFile
|
|
||||||
020-TestCase-1.cpp
|
|
||||||
020-TestCase-2.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_executable(231-Cfg_OutputStreams
|
set( SOURCES_SINGLE_FILE
|
||||||
|
010-TestCase.cpp
|
||||||
231-Cfg-OutputStreams.cpp
|
231-Cfg-OutputStreams.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(231-Cfg_OutputStreams Catch2_buildall_interface)
|
|
||||||
target_compile_definitions(231-Cfg_OutputStreams PUBLIC CATCH_CONFIG_NOSTDOUT)
|
|
||||||
|
|
||||||
# These examples use the standard separate compilation
|
# multiple-file modules:
|
||||||
set( SOURCES_IDIOMATIC_EXAMPLES
|
|
||||||
|
set( SOURCES_020
|
||||||
|
020-TestCase-1.cpp
|
||||||
|
020-TestCase-2.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# main for idiomatic test sources:
|
||||||
|
|
||||||
|
set( SOURCES_IDIOMATIC_MAIN
|
||||||
|
000-CatchMain.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# sources to combine with 000-CatchMain.cpp:
|
||||||
|
|
||||||
|
set( SOURCES_IDIOMATIC_TESTS
|
||||||
030-Asn-Require-Check.cpp
|
030-Asn-Require-Check.cpp
|
||||||
100-Fix-Section.cpp
|
100-Fix-Section.cpp
|
||||||
110-Fix-ClassFixture.cpp
|
110-Fix-ClassFixture.cpp
|
||||||
@@ -37,27 +51,108 @@ set( SOURCES_IDIOMATIC_EXAMPLES
|
|||||||
311-Gen-CustomCapture.cpp
|
311-Gen-CustomCapture.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_EXAMPLES "${SOURCES_IDIOMATIC_EXAMPLES}" )
|
# main-s for reporter-specific test sources:
|
||||||
set( TARGETS_IDIOMATIC_EXAMPLES ${BASENAMES_IDIOMATIC_EXAMPLES} )
|
|
||||||
|
|
||||||
|
set( SOURCES_REPORTERS_MAIN
|
||||||
foreach( name ${TARGETS_IDIOMATIC_EXAMPLES} )
|
200-Rpt-CatchMain.cpp
|
||||||
add_executable( ${name}
|
|
||||||
${EXAMPLES_DIR}/${name}.cpp )
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
set(ALL_EXAMPLE_TARGETS
|
|
||||||
${TARGETS_IDIOMATIC_EXAMPLES}
|
|
||||||
010-TestCase
|
|
||||||
020-MultiFile
|
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach( name ${ALL_EXAMPLE_TARGETS} )
|
string( REPLACE ".cpp" "" BASENAMES_REPORTERS_MAIN 200-Rpt-CatchMain.cpp )
|
||||||
target_link_libraries( ${name} Catch2 Catch2WithMain )
|
|
||||||
set_property(TARGET ${name} PROPERTY CXX_STANDARD 14)
|
set( NAMES_REPORTERS TeamCity )
|
||||||
set_property(TARGET ${name} PROPERTY CXX_EXTENSIONS OFF)
|
|
||||||
|
foreach( reporter ${NAMES_REPORTERS} )
|
||||||
|
list( APPEND SOURCES_SPECIFIC_REPORTERS_MAIN ${BASENAMES_REPORTERS_MAIN}${reporter}.cpp )
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# sources to combine with 200-Rpt-CatchMain{Reporter}.cpp:
|
||||||
|
|
||||||
|
set( SOURCES_REPORTERS_TESTS
|
||||||
|
207-Rpt-TeamCityReporter.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# check if all sources are listed, warn if not:
|
||||||
|
|
||||||
|
set( SOURCES_ALL
|
||||||
|
${SOURCES_020}
|
||||||
|
${SOURCES_SINGLE_FILE}
|
||||||
|
${SOURCES_IDIOMATIC_MAIN}
|
||||||
|
${SOURCES_IDIOMATIC_TESTS}
|
||||||
|
${SOURCES_REPORTERS_MAIN}
|
||||||
|
${SOURCES_REPORTERS_TESTS}
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach( name ${SOURCES_ALL} )
|
||||||
|
list( APPEND SOURCES_ALL_PATH ${EXAMPLES_DIR}/${name} )
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
CheckFileList( SOURCES_ALL_PATH ${EXAMPLES_DIR} )
|
||||||
|
|
||||||
|
# create target names:
|
||||||
|
|
||||||
|
string( REPLACE ".cpp" "" BASENAMES_SINGLE_FILE "${SOURCES_SINGLE_FILE}" )
|
||||||
|
string( REPLACE ".cpp" "" BASENAMES_IDIOMATIC_TESTS "${SOURCES_IDIOMATIC_TESTS}" )
|
||||||
|
string( REPLACE ".cpp" "" BASENAMES_REPORTERS_TESTS "${SOURCES_REPORTERS_TESTS}" )
|
||||||
|
string( REPLACE ".cpp" "" BASENAMES_REPORTERS_MAIN "${SOURCES_REPORTERS_MAIN}" )
|
||||||
|
|
||||||
|
set( TARGETS_SINGLE_FILE ${BASENAMES_SINGLE_FILE} )
|
||||||
|
set( TARGETS_IDIOMATIC_TESTS ${BASENAMES_IDIOMATIC_TESTS} )
|
||||||
|
set( TARGETS_REPORTERS_TESTS ${BASENAMES_REPORTERS_TESTS} )
|
||||||
|
set( TARGETS_REPORTERS_MAIN ${BASENAMES_REPORTERS_MAIN} )
|
||||||
|
|
||||||
|
set( TARGETS_ALL
|
||||||
|
${TARGETS_SINGLE_FILE}
|
||||||
|
020-TestCase
|
||||||
|
${TARGETS_IDIOMATIC_TESTS} CatchMain
|
||||||
|
${TARGETS_REPORTERS_TESTS} CatchMainTeamCity
|
||||||
|
)
|
||||||
|
|
||||||
|
# define program targets:
|
||||||
|
|
||||||
|
add_library( CatchMain OBJECT ${EXAMPLES_DIR}/${SOURCES_IDIOMATIC_MAIN} ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
#add_library( CatchMainAutomake OBJECT ${EXAMPLES_DIR}/200-Rpt-CatchMain.cpp ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
#add_library( CatchMainTap OBJECT ${EXAMPLES_DIR}/200-Rpt-CatchMain.cpp ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
add_library( CatchMainTeamCity OBJECT ${EXAMPLES_DIR}/200-Rpt-CatchMain.cpp ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
|
||||||
|
#target_compile_definitions( CatchMainAutomake PRIVATE CATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_automake.hpp\" )
|
||||||
|
#target_compile_definitions( CatchMainTap PRIVATE CATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_tap.hpp\" )
|
||||||
|
target_compile_definitions( CatchMainTeamCity PRIVATE CATCH_EXAMPLE_RPT_1=\"include/reporters/catch_reporter_teamcity.hpp\" )
|
||||||
|
|
||||||
|
foreach( name ${TARGETS_SINGLE_FILE} )
|
||||||
|
add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
foreach( name ${TARGETS_IDIOMATIC_TESTS} )
|
||||||
|
add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp $<TARGET_OBJECTS:CatchMain> ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
add_executable( 020-TestCase ${EXAMPLES_DIR}/020-TestCase-1.cpp ${EXAMPLES_DIR}/020-TestCase-2.cpp ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
|
||||||
|
#add_executable( 207-Rpt-AutomakeReporter ${EXAMPLES_DIR}/207-Rpt-AutomakeReporter.cpp $<TARGET_OBJECTS:CatchMainAutomake> ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
#add_executable( 207-Rpt-TapReporter ${EXAMPLES_DIR}/207-Rpt-TapReporter.cpp $<TARGET_OBJECTS:CatchMainTap> ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
add_executable( 207-Rpt-TeamCityReporter ${EXAMPLES_DIR}/207-Rpt-TeamCityReporter.cpp $<TARGET_OBJECTS:CatchMainTeamCity> ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
|
||||||
|
#foreach( name ${TARGETS_REPORTERS_TESTS} )
|
||||||
|
# add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp $<TARGET_OBJECTS:CatchMain> ${HEADER_DIR}/catch2/catch.hpp )
|
||||||
|
#endforeach()
|
||||||
|
|
||||||
|
foreach( name ${TARGETS_ALL} )
|
||||||
|
target_include_directories( ${name} PRIVATE ${HEADER_DIR} ${CATCH_DIR} )
|
||||||
|
|
||||||
|
set_property(TARGET ${name} PROPERTY CXX_STANDARD 11)
|
||||||
|
set_property(TARGET ${name} PROPERTY CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
# Add desired warnings
|
||||||
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
|
||||||
|
target_compile_options( ${name} PRIVATE -Wall -Wextra -Wunreachable-code )
|
||||||
|
endif()
|
||||||
|
# Clang specific warning go here
|
||||||
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
||||||
|
# Actually keep these
|
||||||
|
target_compile_options( ${name} PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn )
|
||||||
|
endif()
|
||||||
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
||||||
|
target_compile_options( ${name} PRIVATE /W4 /w44265 /WX )
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
list(APPEND CATCH_WARNING_TARGETS ${ALL_EXAMPLE_TARGETS})
|
|
||||||
set(CATCH_WARNING_TARGETS ${CATCH_WARNING_TARGETS} PARENT_SCOPE)
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,20 +0,0 @@
|
|||||||
# License: Boost 1.0
|
|
||||||
# By Paul Dreik 2020
|
|
||||||
|
|
||||||
# add a library that brings in the main() function from libfuzzer
|
|
||||||
# and has all the dependencies, so the individual fuzzers can be
|
|
||||||
# added one line each.
|
|
||||||
add_library(fuzzhelper NullOStream.h NullOStream.cpp)
|
|
||||||
target_link_libraries(fuzzhelper PUBLIC Catch2::Catch2)
|
|
||||||
|
|
||||||
# use C++17 so we can get string_view
|
|
||||||
target_compile_features(fuzzhelper PUBLIC cxx_std_17)
|
|
||||||
|
|
||||||
# This should be possible to set from the outside to be oss-fuzz compatible,
|
|
||||||
# fix later. For now, target libFuzzer only.
|
|
||||||
target_link_options(fuzzhelper PUBLIC "-fsanitize=fuzzer")
|
|
||||||
|
|
||||||
foreach(fuzzer TestSpecParser XmlWriter textflow)
|
|
||||||
add_executable(fuzz_${fuzzer} fuzz_${fuzzer}.cpp)
|
|
||||||
target_link_libraries(fuzz_${fuzzer} PRIVATE fuzzhelper)
|
|
||||||
endforeach()
|
|
@@ -1,10 +0,0 @@
|
|||||||
#include "NullOStream.h"
|
|
||||||
|
|
||||||
void NullOStream::avoidOutOfLineVirtualCompilerWarning()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int NullStreambuf::overflow(int c){
|
|
||||||
setp(dummyBuffer, dummyBuffer + sizeof(dummyBuffer));
|
|
||||||
return (c == traits_type::eof()) ? '\0' : c;
|
|
||||||
}
|
|
@@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <ostream>
|
|
||||||
#include <streambuf>
|
|
||||||
|
|
||||||
// from https://stackoverflow.com/a/8244052
|
|
||||||
class NullStreambuf : public std::streambuf {
|
|
||||||
char dummyBuffer[64];
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual int overflow(int c) override final;
|
|
||||||
};
|
|
||||||
|
|
||||||
class NullOStream final : private NullStreambuf, public std::ostream {
|
|
||||||
public:
|
|
||||||
NullOStream() : std::ostream(this) {}
|
|
||||||
NullStreambuf *rdbuf() { return this; }
|
|
||||||
virtual void avoidOutOfLineVirtualCompilerWarning();
|
|
||||||
};
|
|
||||||
|
|
@@ -1,33 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# Builds the fuzzers
|
|
||||||
#
|
|
||||||
# By Paul Dreik 20200923
|
|
||||||
set -exu
|
|
||||||
|
|
||||||
CATCHROOT=$(readlink -f $(dirname $0)/..)
|
|
||||||
|
|
||||||
|
|
||||||
BUILDDIR=$CATCHROOT/build-fuzzers
|
|
||||||
mkdir -p $BUILDDIR
|
|
||||||
cd $BUILDDIR
|
|
||||||
|
|
||||||
if which /usr/lib/ccache/clang++ >/dev/null 2>&1 ; then
|
|
||||||
CXX=/usr/lib/ccache/clang++
|
|
||||||
else
|
|
||||||
CXX=clang++
|
|
||||||
fi
|
|
||||||
|
|
||||||
cmake $CATCHROOT \
|
|
||||||
-DCMAKE_CXX_COMPILER=$CXX \
|
|
||||||
-DCMAKE_CXX_FLAGS="-fsanitize=fuzzer-no-link,address,undefined -O3 -g" \
|
|
||||||
-DCATCH_DEVELOPMENT_BUILD=On \
|
|
||||||
-DCATCH_BUILD_EXAMPLES=Off \
|
|
||||||
-DCATCH_BUILD_EXTRA_TESTS=Off \
|
|
||||||
-DCATCH_BUILD_TESTING=Off \
|
|
||||||
-DBUILD_TESTING=Off \
|
|
||||||
-DCATCH_ENABLE_WERROR=Off \
|
|
||||||
-DCATCH_BUILD_FUZZERS=On
|
|
||||||
|
|
||||||
cmake --build . -j $(nproc)
|
|
||||||
|
|
@@ -1,16 +0,0 @@
|
|||||||
//License: Boost 1.0
|
|
||||||
//By Paul Dreik 2020
|
|
||||||
|
|
||||||
#include <catch2/internal/catch_test_spec_parser.hpp>
|
|
||||||
#include <catch2/internal/catch_tag_alias_registry.hpp>
|
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|
||||||
|
|
||||||
Catch::TagAliasRegistry tar;
|
|
||||||
Catch::TestSpecParser tsp(tar);
|
|
||||||
|
|
||||||
std::string buf(Data,Data+Size);
|
|
||||||
tsp.parse(buf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@@ -1,16 +0,0 @@
|
|||||||
//License: Boost 1.0
|
|
||||||
//By Paul Dreik 2020
|
|
||||||
|
|
||||||
#include <catch2/internal/catch_xmlwriter.hpp>
|
|
||||||
|
|
||||||
#include "NullOStream.h"
|
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|
||||||
|
|
||||||
std::string buf(Data,Data+Size);
|
|
||||||
NullOStream nul;
|
|
||||||
Catch::XmlEncode encode(buf);
|
|
||||||
encode.encodeTo(nul);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
@@ -1,47 +0,0 @@
|
|||||||
//License: Boost 1.0
|
|
||||||
//By Paul Dreik 2020
|
|
||||||
|
|
||||||
#include <catch2/internal/catch_textflow.hpp>
|
|
||||||
|
|
||||||
#include "NullOStream.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
|
|
||||||
template<class Callback>
|
|
||||||
void split(const char *Data, size_t Size, Callback callback) {
|
|
||||||
|
|
||||||
using namespace std::literals;
|
|
||||||
constexpr auto sep="\n~~~\n"sv;
|
|
||||||
|
|
||||||
std::string_view remainder(Data,Size);
|
|
||||||
for (;;) {
|
|
||||||
auto pos=remainder.find(sep);
|
|
||||||
if(pos==std::string_view::npos) {
|
|
||||||
//not found. use the remainder and exit
|
|
||||||
callback(remainder);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
//found. invoke callback on the first part, then proceed with the rest.
|
|
||||||
callback(remainder.substr(0,pos));
|
|
||||||
remainder=remainder.substr(pos+sep.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|
||||||
|
|
||||||
Catch::TextFlow::Columns columns;
|
|
||||||
|
|
||||||
// break the input on separator
|
|
||||||
split((const char*)Data,Size,[&](std::string_view word) {
|
|
||||||
columns+=Catch::TextFlow::Column(std::string(word));
|
|
||||||
});
|
|
||||||
|
|
||||||
NullOStream nul;
|
|
||||||
nul << columns;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
496
include/catch.hpp
Normal file
496
include/catch.hpp
Normal file
@@ -0,0 +1,496 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 22/10/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_HPP_INCLUDED
|
||||||
|
|
||||||
|
#define CATCH_VERSION_MAJOR 2
|
||||||
|
#define CATCH_VERSION_MINOR 13
|
||||||
|
#define CATCH_VERSION_PATCH 2
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
# pragma clang system_header
|
||||||
|
#elif defined __GNUC__
|
||||||
|
# pragma GCC system_header
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "internal/catch_suppress_warnings.h"
|
||||||
|
|
||||||
|
#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
|
||||||
|
# define CATCH_IMPL
|
||||||
|
# define CATCH_CONFIG_ALL_PARTS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// In the impl file, we want to have access to all parts of the headers
|
||||||
|
// Can also be used to sanely support PCHs
|
||||||
|
#if defined(CATCH_CONFIG_ALL_PARTS)
|
||||||
|
# define CATCH_CONFIG_EXTERNAL_INTERFACES
|
||||||
|
# if defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
# undef CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
# endif
|
||||||
|
# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
|
||||||
|
# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_IMPL_ONLY)
|
||||||
|
#include "internal/catch_platform.h"
|
||||||
|
|
||||||
|
#ifdef CATCH_IMPL
|
||||||
|
# ifndef CLARA_CONFIG_MAIN
|
||||||
|
# define CLARA_CONFIG_MAIN_NOT_DEFINED
|
||||||
|
# define CLARA_CONFIG_MAIN
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "internal/catch_user_interfaces.h"
|
||||||
|
#include "internal/catch_tag_alias_autoregistrar.h"
|
||||||
|
#include "internal/catch_test_registry.h"
|
||||||
|
#include "internal/catch_capture.hpp"
|
||||||
|
#include "internal/catch_section.h"
|
||||||
|
#include "internal/catch_interfaces_exception.h"
|
||||||
|
#include "internal/catch_approx.h"
|
||||||
|
#include "internal/catch_compiler_capabilities.h"
|
||||||
|
#include "internal/catch_string_manip.h"
|
||||||
|
|
||||||
|
#ifndef CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#include "internal/catch_capture_matchers.h"
|
||||||
|
#endif
|
||||||
|
#include "internal/catch_generators.hpp"
|
||||||
|
#include "internal/catch_generators_generic.hpp"
|
||||||
|
#include "internal/catch_generators_specific.hpp"
|
||||||
|
|
||||||
|
// These files are included here so the single_include script doesn't put them
|
||||||
|
// in the conditionally compiled sections
|
||||||
|
#include "internal/catch_test_case_info.h"
|
||||||
|
#include "internal/catch_interfaces_runner.h"
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
|
#include "internal/catch_objc.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Benchmarking needs the externally-facing parts of reporters to work
|
||||||
|
#if defined(CATCH_CONFIG_EXTERNAL_INTERFACES) || defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
|
||||||
|
#include "internal/catch_external_interfaces.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
|
||||||
|
#include "internal/benchmark/catch_benchmarking_all.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ! CATCH_CONFIG_IMPL_ONLY
|
||||||
|
|
||||||
|
#ifdef CATCH_IMPL
|
||||||
|
#include "internal/catch_impl.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CATCH_CONFIG_MAIN
|
||||||
|
#include "internal/catch_default_main.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_IMPL_ONLY)
|
||||||
|
|
||||||
|
#ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
|
||||||
|
# undef CLARA_CONFIG_MAIN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE)
|
||||||
|
//////
|
||||||
|
// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
|
||||||
|
#ifdef CATCH_CONFIG_PREFIX_ALL
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
|
||||||
|
#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
|
#endif// CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
|
||||||
|
#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_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__ )
|
||||||
|
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
|
||||||
|
#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
|
||||||
|
#define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
|
||||||
|
#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
||||||
|
#define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE",__VA_ARGS__ )
|
||||||
|
|
||||||
|
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
|
||||||
|
#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
|
||||||
|
#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
|
||||||
|
#define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
|
||||||
|
#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
|
||||||
|
#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
|
||||||
|
|
||||||
|
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
|
||||||
|
#else
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#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__ )
|
||||||
|
#else
|
||||||
|
#define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ )
|
||||||
|
#define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// "BDD-style" convenience wrappers
|
||||||
|
#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
|
||||||
|
#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
|
||||||
|
#define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
|
||||||
|
#define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
|
||||||
|
#define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
|
||||||
|
#define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
|
||||||
|
#define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
|
||||||
|
#define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
|
||||||
|
|
||||||
|
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
|
||||||
|
#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__,,))
|
||||||
|
#define CATCH_BENCHMARK_ADVANCED(name) \
|
||||||
|
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name)
|
||||||
|
#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
|
||||||
|
|
||||||
|
// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||||
|
|
||||||
|
#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
|
||||||
|
#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
|
||||||
|
#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 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__ )
|
||||||
|
#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
|
||||||
|
#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
|
||||||
|
|
||||||
|
#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
|
||||||
|
#define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
|
||||||
|
#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
||||||
|
#define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE",__VA_ARGS__ )
|
||||||
|
|
||||||
|
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
||||||
|
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
|
||||||
|
#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
|
||||||
|
#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
|
||||||
|
#define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
|
||||||
|
#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
#define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
|
||||||
|
|
||||||
|
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
|
||||||
|
#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__)
|
||||||
|
#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#else
|
||||||
|
#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#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__ ")" )
|
||||||
|
#else
|
||||||
|
#define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ )
|
||||||
|
#define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
|
||||||
|
|
||||||
|
// "BDD-style" convenience wrappers
|
||||||
|
#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
|
||||||
|
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
|
||||||
|
|
||||||
|
#define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
|
||||||
|
#define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
|
||||||
|
#define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
|
||||||
|
#define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
|
||||||
|
#define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
|
||||||
|
#define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
|
||||||
|
|
||||||
|
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
|
||||||
|
#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__,,))
|
||||||
|
#define BENCHMARK_ADVANCED(name) \
|
||||||
|
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name)
|
||||||
|
#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
|
||||||
|
|
||||||
|
using Catch::Detail::Approx;
|
||||||
|
|
||||||
|
#else // CATCH_CONFIG_DISABLE
|
||||||
|
|
||||||
|
//////
|
||||||
|
// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
|
||||||
|
#ifdef CATCH_CONFIG_PREFIX_ALL
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE( ... ) (void)(0)
|
||||||
|
#define CATCH_REQUIRE_FALSE( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE_THROWS( ... ) (void)(0)
|
||||||
|
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif// CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_CHECK( ... ) (void)(0)
|
||||||
|
#define CATCH_CHECK_FALSE( ... ) (void)(0)
|
||||||
|
#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__)
|
||||||
|
#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
|
||||||
|
#define CATCH_CHECK_NOFAIL( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_CHECK_THROWS( ... ) (void)(0)
|
||||||
|
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_CHECK_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_CHECK_THAT( arg, matcher ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
#define CATCH_INFO( msg ) (void)(0)
|
||||||
|
#define CATCH_UNSCOPED_INFO( msg ) (void)(0)
|
||||||
|
#define CATCH_WARN( msg ) (void)(0)
|
||||||
|
#define CATCH_CAPTURE( msg ) (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_METHOD_AS_TEST_CASE( method, ... )
|
||||||
|
#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||||
|
#define CATCH_SECTION( ... )
|
||||||
|
#define CATCH_DYNAMIC_SECTION( ... )
|
||||||
|
#define CATCH_FAIL( ... ) (void)(0)
|
||||||
|
#define CATCH_FAIL_CHECK( ... ) (void)(0)
|
||||||
|
#define CATCH_SUCCEED( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
|
||||||
|
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#else
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// "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_GIVEN( desc )
|
||||||
|
#define CATCH_AND_GIVEN( desc )
|
||||||
|
#define CATCH_WHEN( desc )
|
||||||
|
#define CATCH_AND_WHEN( desc )
|
||||||
|
#define CATCH_THEN( desc )
|
||||||
|
#define CATCH_AND_THEN( desc )
|
||||||
|
|
||||||
|
#define CATCH_STATIC_REQUIRE( ... ) (void)(0)
|
||||||
|
#define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0)
|
||||||
|
|
||||||
|
// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define REQUIRE( ... ) (void)(0)
|
||||||
|
#define REQUIRE_FALSE( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define REQUIRE_THROWS( ... ) (void)(0)
|
||||||
|
#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define REQUIRE_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CHECK( ... ) (void)(0)
|
||||||
|
#define CHECK_FALSE( ... ) (void)(0)
|
||||||
|
#define CHECKED_IF( ... ) if (__VA_ARGS__)
|
||||||
|
#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
|
||||||
|
#define CHECK_NOFAIL( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CHECK_THROWS( ... ) (void)(0)
|
||||||
|
#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CHECK_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CHECK_THAT( arg, matcher ) (void)(0)
|
||||||
|
|
||||||
|
#define REQUIRE_THAT( arg, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
#define INFO( msg ) (void)(0)
|
||||||
|
#define UNSCOPED_INFO( msg ) (void)(0)
|
||||||
|
#define WARN( msg ) (void)(0)
|
||||||
|
#define CAPTURE( msg ) (void)(0)
|
||||||
|
|
||||||
|
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
#define METHOD_AS_TEST_CASE( method, ... )
|
||||||
|
#define REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||||
|
#define SECTION( ... )
|
||||||
|
#define DYNAMIC_SECTION( ... )
|
||||||
|
#define FAIL( ... ) (void)(0)
|
||||||
|
#define FAIL_CHECK( ... ) (void)(0)
|
||||||
|
#define SUCCEED( ... ) (void)(0)
|
||||||
|
#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
|
||||||
|
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
|
||||||
|
#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
|
||||||
|
#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#else
|
||||||
|
#define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
|
||||||
|
#define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define STATIC_REQUIRE( ... ) (void)(0)
|
||||||
|
#define STATIC_REQUIRE_FALSE( ... ) (void)(0)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
|
||||||
|
|
||||||
|
// "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 GIVEN( desc )
|
||||||
|
#define AND_GIVEN( desc )
|
||||||
|
#define WHEN( desc )
|
||||||
|
#define AND_WHEN( desc )
|
||||||
|
#define THEN( desc )
|
||||||
|
#define AND_THEN( desc )
|
||||||
|
|
||||||
|
using Catch::Detail::Approx;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ! CATCH_CONFIG_IMPL_ONLY
|
||||||
|
|
||||||
|
#include "internal/catch_reenable_warnings.h"
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED
|
14
include/catch_with_main.hpp
Normal file
14
include/catch_with_main.hpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 01/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_WITH_MAIN_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_WITH_MAIN_HPP_INCLUDED
|
||||||
|
|
||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_WITH_MAIN_HPP_INCLUDED
|
1268
include/external/clara.hpp
vendored
Normal file
1268
include/external/clara.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,28 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Benchmark
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#ifndef TWOBLUECUBES_CATCH_BENCHMARK_HPP_INCLUDED
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
#define TWOBLUECUBES_CATCH_BENCHMARK_HPP_INCLUDED
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#include "../catch_config.hpp"
|
||||||
// Adapted from donated nonius code.
|
#include "../catch_context.h"
|
||||||
|
#include "../catch_interfaces_reporter.h"
|
||||||
|
#include "../catch_test_registry.h"
|
||||||
|
|
||||||
#ifndef CATCH_BENCHMARK_HPP_INCLUDED
|
#include "catch_chronometer.hpp"
|
||||||
#define CATCH_BENCHMARK_HPP_INCLUDED
|
#include "catch_clock.hpp"
|
||||||
|
#include "catch_environment.hpp"
|
||||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
#include "catch_execution_plan.hpp"
|
||||||
#include <catch2/internal/catch_context.hpp>
|
#include "detail/catch_estimate_clock.hpp"
|
||||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
#include "detail/catch_complete_invoke.hpp"
|
||||||
|
#include "detail/catch_analyse.hpp"
|
||||||
#include <catch2/benchmark/catch_chronometer.hpp>
|
#include "detail/catch_benchmark_function.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
#include "detail/catch_run_for_at_least.hpp"
|
||||||
#include <catch2/benchmark/catch_environment.hpp>
|
|
||||||
#include <catch2/benchmark/catch_execution_plan.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_estimate_clock.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_analyse.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_benchmark_function.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -33,12 +34,12 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
struct Benchmark {
|
struct Benchmark {
|
||||||
Benchmark(std::string&& benchmarkName)
|
Benchmark(std::string &&name)
|
||||||
: name(std::move(benchmarkName)) {}
|
: name(std::move(name)) {}
|
||||||
|
|
||||||
template <class FUN>
|
template <class FUN>
|
||||||
Benchmark(std::string&& benchmarkName , FUN &&func)
|
Benchmark(std::string &&name, FUN &&func)
|
||||||
: fun(std::move(func)), name(std::move(benchmarkName)) {}
|
: fun(std::move(func)), name(std::move(name)) {}
|
||||||
|
|
||||||
template <typename Clock>
|
template <typename Clock>
|
||||||
ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
|
ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
|
||||||
@@ -51,7 +52,7 @@ namespace Catch {
|
|||||||
|
|
||||||
template <typename Clock = default_clock>
|
template <typename Clock = default_clock>
|
||||||
void run() {
|
void run() {
|
||||||
auto const* cfg = getCurrentContext().getConfig();
|
IConfigPtr cfg = getCurrentContext().getConfig();
|
||||||
|
|
||||||
auto env = Detail::measure_environment<Clock>();
|
auto env = Detail::measure_environment<Clock>();
|
||||||
|
|
||||||
@@ -118,20 +119,4 @@ namespace Catch {
|
|||||||
if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
|
if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
|
||||||
BenchmarkName = [&]
|
BenchmarkName = [&]
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_PREFIX_ALL)
|
#endif // TWOBLUECUBES_CATCH_BENCHMARK_HPP_INCLUDED
|
||||||
|
|
||||||
#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__,,))
|
|
||||||
#define CATCH_BENCHMARK_ADVANCED(name) \
|
|
||||||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), 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__,,))
|
|
||||||
#define BENCHMARK_ADVANCED(name) \
|
|
||||||
INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(____C_A_T_C_H____B_E_N_C_H____), name)
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CATCH_BENCHMARK_HPP_INCLUDED
|
|
29
include/internal/benchmark/catch_benchmarking_all.hpp
Normal file
29
include/internal/benchmark/catch_benchmarking_all.hpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// A proxy header that includes all of the benchmarking headers to allow
|
||||||
|
// concise include of the benchmarking features. You should prefer the
|
||||||
|
// individual includes in standard use.
|
||||||
|
|
||||||
|
#include "catch_benchmark.hpp"
|
||||||
|
#include "catch_chronometer.hpp"
|
||||||
|
#include "catch_clock.hpp"
|
||||||
|
#include "catch_constructor.hpp"
|
||||||
|
#include "catch_environment.hpp"
|
||||||
|
#include "catch_estimate.hpp"
|
||||||
|
#include "catch_execution_plan.hpp"
|
||||||
|
#include "catch_optimizer.hpp"
|
||||||
|
#include "catch_outlier_classification.hpp"
|
||||||
|
#include "catch_sample_analysis.hpp"
|
||||||
|
#include "detail/catch_analyse.hpp"
|
||||||
|
#include "detail/catch_benchmark_function.hpp"
|
||||||
|
#include "detail/catch_complete_invoke.hpp"
|
||||||
|
#include "detail/catch_estimate_clock.hpp"
|
||||||
|
#include "detail/catch_measure.hpp"
|
||||||
|
#include "detail/catch_repeat.hpp"
|
||||||
|
#include "detail/catch_run_for_at_least.hpp"
|
||||||
|
#include "detail/catch_stats.hpp"
|
||||||
|
#include "detail/catch_timing.hpp"
|
@@ -1,19 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// User-facing chronometer
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_CHRONOMETER_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_CHRONOMETER_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_CHRONOMETER_HPP_INCLUDED
|
#include "catch_clock.hpp"
|
||||||
#define CATCH_CHRONOMETER_HPP_INCLUDED
|
#include "catch_optimizer.hpp"
|
||||||
|
#include "detail/catch_complete_invoke.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
#include "../catch_meta.hpp"
|
||||||
#include <catch2/benchmark/catch_optimizer.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
|
||||||
#include <catch2/internal/catch_meta.hpp>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
@@ -21,11 +22,7 @@ namespace Catch {
|
|||||||
struct ChronometerConcept {
|
struct ChronometerConcept {
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
virtual void finish() = 0;
|
virtual void finish() = 0;
|
||||||
virtual ~ChronometerConcept(); // = default;
|
virtual ~ChronometerConcept() = default;
|
||||||
|
|
||||||
ChronometerConcept() = default;
|
|
||||||
ChronometerConcept(ChronometerConcept const&) = default;
|
|
||||||
ChronometerConcept& operator=(ChronometerConcept const&) = default;
|
|
||||||
};
|
};
|
||||||
template <typename Clock>
|
template <typename Clock>
|
||||||
struct ChronometerModel final : public ChronometerConcept {
|
struct ChronometerModel final : public ChronometerConcept {
|
||||||
@@ -44,11 +41,11 @@ namespace Catch {
|
|||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(int)>()); }
|
void measure(Fun&& fun) { measure(std::forward<Fun>(fun), is_callable<Fun(int)>()); }
|
||||||
|
|
||||||
int runs() const { return repeats; }
|
int runs() const { return k; }
|
||||||
|
|
||||||
Chronometer(Detail::ChronometerConcept& meter, int repeats_)
|
Chronometer(Detail::ChronometerConcept& meter, int k)
|
||||||
: impl(&meter)
|
: impl(&meter)
|
||||||
, repeats(repeats_) {}
|
, k(k) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
@@ -60,15 +57,15 @@ namespace Catch {
|
|||||||
void measure(Fun&& fun, std::true_type) {
|
void measure(Fun&& fun, std::true_type) {
|
||||||
Detail::optimizer_barrier();
|
Detail::optimizer_barrier();
|
||||||
impl->start();
|
impl->start();
|
||||||
for (int i = 0; i < repeats; ++i) invoke_deoptimized(fun, i);
|
for (int i = 0; i < k; ++i) invoke_deoptimized(fun, i);
|
||||||
impl->finish();
|
impl->finish();
|
||||||
Detail::optimizer_barrier();
|
Detail::optimizer_barrier();
|
||||||
}
|
}
|
||||||
|
|
||||||
Detail::ChronometerConcept* impl;
|
Detail::ChronometerConcept* impl;
|
||||||
int repeats;
|
int k;
|
||||||
};
|
};
|
||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_CHRONOMETER_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CHRONOMETER_HPP_INCLUDED
|
@@ -1,14 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Clocks
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_CLOCK_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_CLOCK_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_CLOCK_HPP_INCLUDED
|
|
||||||
#define CATCH_CLOCK_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ratio>
|
#include <ratio>
|
||||||
@@ -36,4 +37,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_CLOCK_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CLOCK_HPP_INCLUDED
|
@@ -1,14 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Constructor and destructor helpers
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_CONSTRUCTOR_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_CONSTRUCTOR_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_CONSTRUCTOR_HPP_INCLUDED
|
|
||||||
#define CATCH_CONSTRUCTOR_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
@@ -65,14 +66,14 @@ namespace Catch {
|
|||||||
|
|
||||||
TStorage data;
|
TStorage data;
|
||||||
};
|
};
|
||||||
} // namespace Detail
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using storage_for = Detail::ObjectStorage<T, true>;
|
using storage_for = Detail::ObjectStorage<T, true>;
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using destructable_object = Detail::ObjectStorage<T, false>;
|
using destructable_object = Detail::ObjectStorage<T, false>;
|
||||||
} // namespace Benchmark
|
}
|
||||||
} // namespace Catch
|
}
|
||||||
|
|
||||||
#endif // CATCH_CONSTRUCTOR_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CONSTRUCTOR_HPP_INCLUDED
|
@@ -1,17 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Environment information
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_ENVIRONMENT_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_ENVIRONMENT_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_ENVIRONMENT_HPP_INCLUDED
|
#include "catch_clock.hpp"
|
||||||
#define CATCH_ENVIRONMENT_HPP_INCLUDED
|
#include "catch_outlier_classification.hpp"
|
||||||
|
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
|
||||||
#include <catch2/benchmark/catch_outlier_classification.hpp>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
@@ -34,4 +35,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_ENVIRONMENT_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_ENVIRONMENT_HPP_INCLUDED
|
@@ -1,14 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Statistics estimates
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_ESTIMATE_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_ESTIMATE_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_ESTIMATE_HPP_INCLUDED
|
|
||||||
#define CATCH_ESTIMATE_HPP_INCLUDED
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
@@ -27,4 +28,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_ESTIMATE_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_ESTIMATE_HPP_INCLUDED
|
@@ -1,21 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Execution plan
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_EXECUTION_PLAN_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_EXECUTION_PLAN_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_EXECUTION_PLAN_HPP_INCLUDED
|
#include "../catch_config.hpp"
|
||||||
#define CATCH_EXECUTION_PLAN_HPP_INCLUDED
|
#include "catch_clock.hpp"
|
||||||
|
#include "catch_environment.hpp"
|
||||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
#include "detail/catch_benchmark_function.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
#include "detail/catch_repeat.hpp"
|
||||||
#include <catch2/benchmark/catch_environment.hpp>
|
#include "detail/catch_run_for_at_least.hpp"
|
||||||
#include <catch2/benchmark/detail/catch_benchmark_function.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_repeat.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@@ -54,4 +55,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_EXECUTION_PLAN_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_EXECUTION_PLAN_HPP_INCLUDED
|
@@ -1,22 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Hinting the optimizer
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_OPTIMIZER_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_OPTIMIZER_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_OPTIMIZER_HPP_INCLUDED
|
|
||||||
#define CATCH_OPTIMIZER_HPP_INCLUDED
|
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# include <atomic> // atomic_thread_fence
|
# include <atomic> // atomic_thread_fence
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
@@ -67,4 +65,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_OPTIMIZER_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_OPTIMIZER_HPP_INCLUDED
|
@@ -1,14 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Outlier information
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#ifndef TWOBLUECUBES_CATCH_OUTLIERS_HPP_INCLUDED
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
#define TWOBLUECUBES_CATCH_OUTLIERS_HPP_INCLUDED
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
// Adapted from donated nonius code.
|
|
||||||
|
|
||||||
#ifndef CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED
|
|
||||||
#define CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
@@ -26,4 +26,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_OUTLIERS_CLASSIFICATION_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_OUTLIERS_HPP_INCLUDED
|
@@ -1,18 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Benchmark results
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_BENCHMARK_RESULTS_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_BENCHMARK_RESULTS_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
|
#include "catch_clock.hpp"
|
||||||
#define CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
|
#include "catch_estimate.hpp"
|
||||||
|
#include "catch_outlier_classification.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
|
||||||
#include <catch2/benchmark/catch_estimate.hpp>
|
|
||||||
#include <catch2/benchmark/catch_outlier_classification.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -46,4 +47,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_BENCHMARK_RESULTS_HPP_INCLUDED
|
@@ -1,18 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Run and analyse one benchmark
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_ANALYSE_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_DETAIL_ANALYSE_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_ANALYSE_HPP_INCLUDED
|
#include "../catch_clock.hpp"
|
||||||
#define CATCH_ANALYSE_HPP_INCLUDED
|
#include "../catch_sample_analysis.hpp"
|
||||||
|
#include "catch_stats.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
|
||||||
#include <catch2/benchmark/catch_sample_analysis.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_stats.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@@ -74,4 +75,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_ANALYSE_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DETAIL_ANALYSE_HPP_INCLUDED
|
@@ -1,23 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Dumb std::function implementation for consistent call overhead
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_BENCHMARK_FUNCTION_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_DETAIL_BENCHMARK_FUNCTION_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
|
#include "../catch_chronometer.hpp"
|
||||||
#define CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
|
#include "catch_complete_invoke.hpp"
|
||||||
|
#include "../../catch_meta.hpp"
|
||||||
#include <catch2/benchmark/catch_chronometer.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
|
||||||
#include <catch2/internal/catch_meta.hpp>
|
|
||||||
#include <catch2/internal/catch_unique_ptr.hpp>
|
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
@@ -40,16 +41,12 @@ namespace Catch {
|
|||||||
struct callable {
|
struct callable {
|
||||||
virtual void call(Chronometer meter) const = 0;
|
virtual void call(Chronometer meter) const = 0;
|
||||||
virtual callable* clone() const = 0;
|
virtual callable* clone() const = 0;
|
||||||
virtual ~callable(); // = default;
|
virtual ~callable() = default;
|
||||||
|
|
||||||
callable() = default;
|
|
||||||
callable(callable const&) = default;
|
|
||||||
callable& operator=(callable const&) = default;
|
|
||||||
};
|
};
|
||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
struct model : public callable {
|
struct model : public callable {
|
||||||
model(Fun&& fun_) : fun(std::move(fun_)) {}
|
model(Fun&& fun) : fun(std::move(fun)) {}
|
||||||
model(Fun const& fun_) : fun(fun_) {}
|
model(Fun const& fun) : fun(fun) {}
|
||||||
|
|
||||||
model<Fun>* clone() const override { return new model<Fun>(*this); }
|
model<Fun>* clone() const override { return new model<Fun>(*this); }
|
||||||
|
|
||||||
@@ -80,15 +77,14 @@ namespace Catch {
|
|||||||
BenchmarkFunction(Fun&& fun)
|
BenchmarkFunction(Fun&& fun)
|
||||||
: f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
|
: f(new model<typename std::decay<Fun>::type>(std::forward<Fun>(fun))) {}
|
||||||
|
|
||||||
BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
|
BenchmarkFunction(BenchmarkFunction&& that)
|
||||||
f( std::move( that.f ) ) {}
|
: f(std::move(that.f)) {}
|
||||||
|
|
||||||
BenchmarkFunction(BenchmarkFunction const& that)
|
BenchmarkFunction(BenchmarkFunction const& that)
|
||||||
: f(that.f->clone()) {}
|
: f(that.f->clone()) {}
|
||||||
|
|
||||||
BenchmarkFunction&
|
BenchmarkFunction& operator=(BenchmarkFunction&& that) {
|
||||||
operator=( BenchmarkFunction&& that ) noexcept {
|
f = std::move(that.f);
|
||||||
f = std::move( that.f );
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,10 +96,10 @@ namespace Catch {
|
|||||||
void operator()(Chronometer meter) const { f->call(meter); }
|
void operator()(Chronometer meter) const { f->call(meter); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Catch::Detail::unique_ptr<callable> f;
|
std::unique_ptr<callable> f;
|
||||||
};
|
};
|
||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DETAIL_BENCHMARK_FUNCTION_HPP_INCLUDED
|
@@ -1,19 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Invoke with a special case for void
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_COMPLETE_INVOKE_HPP_INCLUDED
|
#include "../../catch_enforce.h"
|
||||||
#define CATCH_COMPLETE_INVOKE_HPP_INCLUDED
|
#include "../../catch_meta.hpp"
|
||||||
|
|
||||||
#include <catch2/internal/catch_enforce.hpp>
|
|
||||||
#include <catch2/internal/catch_meta.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -51,7 +50,7 @@ namespace Catch {
|
|||||||
return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
|
return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(std::forward<Fun>(fun), std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const std::string benchmarkErrorMsg;
|
const std::string benchmarkErrorMsg = "a benchmark failed to run successfully";
|
||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
|
|
||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
@@ -66,4 +65,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_COMPLETE_INVOKE_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DETAIL_COMPLETE_INVOKE_HPP_INCLUDED
|
@@ -1,24 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Environment measurement
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_ESTIMATE_CLOCK_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_DETAIL_ESTIMATE_CLOCK_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
|
#include "../catch_clock.hpp"
|
||||||
#define CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
|
#include "../catch_environment.hpp"
|
||||||
|
#include "catch_stats.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
#include "catch_measure.hpp"
|
||||||
#include <catch2/benchmark/catch_environment.hpp>
|
#include "catch_run_for_at_least.hpp"
|
||||||
#include <catch2/benchmark/detail/catch_stats.hpp>
|
#include "../catch_clock.hpp"
|
||||||
#include <catch2/benchmark/detail/catch_measure.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp>
|
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
@@ -108,4 +110,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DETAIL_ESTIMATE_CLOCK_HPP_INCLUDED
|
@@ -1,18 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Measure
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_MEASURE_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_DETAIL_MEASURE_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_MEASURE_HPP_INCLUDED
|
#include "../catch_clock.hpp"
|
||||||
#define CATCH_MEASURE_HPP_INCLUDED
|
#include "catch_complete_invoke.hpp"
|
||||||
|
#include "catch_timing.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_timing.hpp>
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
@@ -31,4 +32,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_MEASURE_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DETAIL_MEASURE_HPP_INCLUDED
|
@@ -1,14 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// repeat algorithm
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_REPEAT_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_DETAIL_REPEAT_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_REPEAT_HPP_INCLUDED
|
|
||||||
#define CATCH_REPEAT_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -33,4 +34,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_REPEAT_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DETAIL_REPEAT_HPP_INCLUDED
|
@@ -1,21 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Run a function for a minimum amount of time
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
|
#include "../catch_clock.hpp"
|
||||||
#define CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
|
#include "../catch_chronometer.hpp"
|
||||||
|
#include "catch_measure.hpp"
|
||||||
#include <catch2/benchmark/catch_clock.hpp>
|
#include "catch_complete_invoke.hpp"
|
||||||
#include <catch2/benchmark/catch_chronometer.hpp>
|
#include "catch_timing.hpp"
|
||||||
#include <catch2/benchmark/detail/catch_measure.hpp>
|
#include "../../catch_meta.hpp"
|
||||||
#include <catch2/benchmark/detail/catch_complete_invoke.hpp>
|
|
||||||
#include <catch2/benchmark/detail/catch_timing.hpp>
|
|
||||||
#include <catch2/internal/catch_meta.hpp>
|
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -38,9 +39,11 @@ namespace Catch {
|
|||||||
template <typename Clock, typename Fun>
|
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 = typename std::conditional<is_callable<Fun(Chronometer)>::value, Chronometer, int>::type;
|
||||||
|
|
||||||
|
struct optimized_away_error : std::exception {
|
||||||
[[noreturn]]
|
const char* what() const noexcept override {
|
||||||
void throw_optimized_away_error();
|
return "could not measure benchmark, maybe it was optimized away";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename Clock, typename Fun>
|
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) {
|
TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>> run_for_at_least(ClockDuration<Clock> how_long, int seed, Fun&& fun) {
|
||||||
@@ -53,10 +56,10 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
iters *= 2;
|
iters *= 2;
|
||||||
}
|
}
|
||||||
throw_optimized_away_error();
|
throw optimized_away_error{};
|
||||||
}
|
}
|
||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
|
@@ -1,18 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 15/06/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Statistical analysis tools
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
|
||||||
// Adapted from donated nonius code.
|
|
||||||
|
|
||||||
#include <catch2/benchmark/detail/catch_stats.hpp>
|
#include "catch_stats.hpp"
|
||||||
|
|
||||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
#include "../../catch_compiler_capabilities.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iterator>
|
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
|
|
||||||
@@ -21,27 +23,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
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;
|
|
||||||
std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
|
|
||||||
|
|
||||||
sample out;
|
|
||||||
out.reserve(resamples);
|
|
||||||
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)]; });
|
|
||||||
return estimator(resampled.begin(), resampled.end());
|
|
||||||
});
|
|
||||||
std::sort(out.begin(), out.end());
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
double erf_inv(double x) {
|
double erf_inv(double x) {
|
||||||
// Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2
|
// Code accompanying the article "Approximating the erfinv function" in GPU Computing Gems, Volume 2
|
||||||
double w, p;
|
double w, p;
|
||||||
@@ -239,3 +220,5 @@ namespace Catch {
|
|||||||
} // namespace Detail
|
} // namespace Detail
|
||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
|
#endif // CATCH_CONFIG_ENABLE_BENCHMARKING
|
@@ -1,24 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
// Statistical analysis tools
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_ANALYSIS_HPP_INCLUDED
|
||||||
// Adapted from donated nonius code.
|
#define TWOBLUECUBES_CATCH_DETAIL_ANALYSIS_HPP_INCLUDED
|
||||||
|
|
||||||
#ifndef CATCH_STATS_HPP_INCLUDED
|
#include "../catch_clock.hpp"
|
||||||
#define CATCH_STATS_HPP_INCLUDED
|
#include "../catch_estimate.hpp"
|
||||||
|
#include "../catch_outlier_classification.hpp"
|
||||||
#include <catch2/benchmark/catch_estimate.hpp>
|
|
||||||
#include <catch2/benchmark/catch_outlier_classification.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iterator>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace Benchmark {
|
namespace Benchmark {
|
||||||
@@ -58,11 +64,27 @@ namespace Catch {
|
|||||||
return sum / count;
|
return sum / count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename URng, typename Iterator, typename Estimator>
|
||||||
|
sample resample(URng& rng, int resamples, Iterator first, Iterator last, Estimator& estimator) {
|
||||||
|
auto n = last - first;
|
||||||
|
std::uniform_int_distribution<decltype(n)> dist(0, n - 1);
|
||||||
|
|
||||||
|
sample out;
|
||||||
|
out.reserve(resamples);
|
||||||
|
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)]; });
|
||||||
|
return estimator(resampled.begin(), resampled.end());
|
||||||
|
});
|
||||||
|
std::sort(out.begin(), out.end());
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Estimator, typename Iterator>
|
template <typename Estimator, typename Iterator>
|
||||||
sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
|
sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
|
||||||
auto n = last - first;
|
auto n = last - first;
|
||||||
auto second = first;
|
auto second = std::next(first);
|
||||||
++second;
|
|
||||||
sample results;
|
sample results;
|
||||||
results.reserve(n);
|
results.reserve(n);
|
||||||
|
|
||||||
@@ -135,4 +157,4 @@ namespace Catch {
|
|||||||
} // namespace Benchmark
|
} // namespace Benchmark
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_STATS_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_DETAIL_ANALYSIS_HPP_INCLUDED
|
33
include/internal/benchmark/detail/catch_timing.hpp
Normal file
33
include/internal/benchmark/detail/catch_timing.hpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Created by Joachim on 16/04/2019.
|
||||||
|
* Adapted from donated nonius code.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Timing
|
||||||
|
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_DETAIL_TIMING_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_DETAIL_TIMING_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "../catch_clock.hpp"
|
||||||
|
#include "catch_complete_invoke.hpp"
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
namespace Benchmark {
|
||||||
|
template <typename Duration, typename Result>
|
||||||
|
struct Timing {
|
||||||
|
Duration elapsed;
|
||||||
|
Result result;
|
||||||
|
int iterations;
|
||||||
|
};
|
||||||
|
template <typename Clock, typename Func, typename... Args>
|
||||||
|
using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<FunctionReturnType<Func, Args...>>>;
|
||||||
|
} // namespace Benchmark
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_DETAIL_TIMING_HPP_INCLUDED
|
@@ -1,12 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 19/07/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_approx.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#include "catch_enforce.h"
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
#include <catch2/catch_approx.hpp>
|
|
||||||
#include <catch2/internal/catch_enforce.hpp>
|
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -22,6 +23,7 @@ bool marginComparison(double lhs, double rhs, double margin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
namespace Detail {
|
||||||
|
|
||||||
Approx::Approx ( double value )
|
Approx::Approx ( double value )
|
||||||
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
|
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
|
||||||
@@ -68,16 +70,18 @@ namespace Catch {
|
|||||||
m_epsilon = newEpsilon;
|
m_epsilon = newEpsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // end namespace Detail
|
||||||
|
|
||||||
namespace literals {
|
namespace literals {
|
||||||
Approx operator "" _a(long double val) {
|
Detail::Approx operator "" _a(long double val) {
|
||||||
return Approx(val);
|
return Detail::Approx(val);
|
||||||
}
|
}
|
||||||
Approx operator "" _a(unsigned long long val) {
|
Detail::Approx operator "" _a(unsigned long long val) {
|
||||||
return Approx(val);
|
return Detail::Approx(val);
|
||||||
}
|
}
|
||||||
} // end namespace literals
|
} // end namespace literals
|
||||||
|
|
||||||
std::string StringMaker<Catch::Approx>::convert(Catch::Approx const& value) {
|
std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
@@ -1,25 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 28/04/2011.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_tostring.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
#ifndef CATCH_APPROX_HPP_INCLUDED
|
|
||||||
#define CATCH_APPROX_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <catch2/catch_tostring.hpp>
|
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
namespace Detail {
|
||||||
|
|
||||||
class Approx {
|
class Approx {
|
||||||
private:
|
private:
|
||||||
bool equalityComparisonImpl(double other) const;
|
bool equalityComparisonImpl(double other) const;
|
||||||
// Sets and validates the new margin (margin >= 0)
|
// Validates the new margin (margin >= 0)
|
||||||
|
// out-of-line to avoid including stdexcept in the header
|
||||||
void setMargin(double margin);
|
void setMargin(double margin);
|
||||||
// Sets and validates the new epsilon (0 < epsilon < 1)
|
// Validates the new epsilon (0 < epsilon < 1)
|
||||||
|
// out-of-line to avoid including stdexcept in the header
|
||||||
void setEpsilon(double epsilon);
|
void setEpsilon(double epsilon);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -29,7 +32,7 @@ namespace Catch {
|
|||||||
|
|
||||||
Approx operator-() const;
|
Approx operator-() const;
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
Approx operator()( T const& value ) {
|
Approx operator()( T const& value ) {
|
||||||
Approx approx( static_cast<double>(value) );
|
Approx approx( static_cast<double>(value) );
|
||||||
approx.m_epsilon = m_epsilon;
|
approx.m_epsilon = m_epsilon;
|
||||||
@@ -38,67 +41,67 @@ namespace Catch {
|
|||||||
return approx;
|
return approx;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
explicit Approx( T const& value ): Approx(static_cast<double>(value))
|
explicit Approx( T const& value ): Approx(static_cast<double>(value))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator == ( const T& lhs, Approx const& rhs ) {
|
friend bool operator == ( const T& lhs, Approx const& rhs ) {
|
||||||
auto lhs_v = static_cast<double>(lhs);
|
auto lhs_v = static_cast<double>(lhs);
|
||||||
return rhs.equalityComparisonImpl(lhs_v);
|
return rhs.equalityComparisonImpl(lhs_v);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator == ( Approx const& lhs, const T& rhs ) {
|
friend bool operator == ( Approx const& lhs, const T& rhs ) {
|
||||||
return operator==( rhs, lhs );
|
return operator==( rhs, lhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator != ( T const& lhs, Approx const& rhs ) {
|
friend bool operator != ( T const& lhs, Approx const& rhs ) {
|
||||||
return !operator==( lhs, rhs );
|
return !operator==( lhs, rhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator != ( Approx const& lhs, T const& rhs ) {
|
friend bool operator != ( Approx const& lhs, T const& rhs ) {
|
||||||
return !operator==( rhs, lhs );
|
return !operator==( rhs, lhs );
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator <= ( T const& lhs, Approx const& rhs ) {
|
friend bool operator <= ( T const& lhs, Approx const& rhs ) {
|
||||||
return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
|
return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator <= ( Approx const& lhs, T const& rhs ) {
|
friend bool operator <= ( Approx const& lhs, T const& rhs ) {
|
||||||
return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
|
return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator >= ( T const& lhs, Approx const& rhs ) {
|
friend bool operator >= ( T const& lhs, Approx const& rhs ) {
|
||||||
return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
|
return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
friend bool operator >= ( Approx const& lhs, T const& rhs ) {
|
friend bool operator >= ( Approx const& lhs, T const& rhs ) {
|
||||||
return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
|
return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
Approx& epsilon( T const& newEpsilon ) {
|
Approx& epsilon( T const& newEpsilon ) {
|
||||||
double epsilonAsDouble = static_cast<double>(newEpsilon);
|
double epsilonAsDouble = static_cast<double>(newEpsilon);
|
||||||
setEpsilon(epsilonAsDouble);
|
setEpsilon(epsilonAsDouble);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
Approx& margin( T const& newMargin ) {
|
Approx& margin( T const& newMargin ) {
|
||||||
double marginAsDouble = static_cast<double>(newMargin);
|
double marginAsDouble = static_cast<double>(newMargin);
|
||||||
setMargin(marginAsDouble);
|
setMargin(marginAsDouble);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
Approx& scale( T const& newScale ) {
|
Approx& scale( T const& newScale ) {
|
||||||
m_scale = static_cast<double>(newScale);
|
m_scale = static_cast<double>(newScale);
|
||||||
return *this;
|
return *this;
|
||||||
@@ -112,17 +115,18 @@ namespace Catch {
|
|||||||
double m_scale;
|
double m_scale;
|
||||||
double m_value;
|
double m_value;
|
||||||
};
|
};
|
||||||
|
} // end namespace Detail
|
||||||
|
|
||||||
namespace literals {
|
namespace literals {
|
||||||
Approx operator "" _a(long double val);
|
Detail::Approx operator "" _a(long double val);
|
||||||
Approx operator "" _a(unsigned long long val);
|
Detail::Approx operator "" _a(unsigned long long val);
|
||||||
} // end namespace literals
|
} // end namespace literals
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct StringMaker<Catch::Approx> {
|
struct StringMaker<Catch::Detail::Approx> {
|
||||||
static std::string convert(Catch::Approx const& value);
|
static std::string convert(Catch::Detail::Approx const& value);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_APPROX_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
@@ -1,21 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_assertionhandler.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#include "catch_assertionresult.h"
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
#include "catch_interfaces_runner.h"
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
#include "catch_interfaces_config.h"
|
||||||
|
#include "catch_context.h"
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#include "catch_debugger.h"
|
||||||
#include <catch2/internal/catch_assertion_handler.hpp>
|
#include "catch_interfaces_registry_hub.h"
|
||||||
#include <catch2/interfaces/catch_interfaces_config.hpp>
|
#include "catch_capture_matchers.h"
|
||||||
#include <catch2/internal/catch_context.hpp>
|
#include "catch_run_context.h"
|
||||||
#include <catch2/internal/catch_enforce.hpp>
|
#include "catch_enforce.h"
|
||||||
#include <catch2/internal/catch_debugger.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
|
||||||
#include <catch2/internal/catch_run_context.hpp>
|
|
||||||
#include <catch2/matchers/catch_matchers_string.hpp>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
|
||||||
|
expr.streamReconstructedExpression( os );
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyExpression::LazyExpression( bool isNegated )
|
||||||
|
: m_isNegated( isNegated )
|
||||||
|
{}
|
||||||
|
|
||||||
|
LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
|
||||||
|
|
||||||
|
LazyExpression::operator bool() const {
|
||||||
|
return m_transientExpression != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
|
||||||
|
if( lazyExpr.m_isNegated )
|
||||||
|
os << "!";
|
||||||
|
|
||||||
|
if( lazyExpr ) {
|
||||||
|
if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() )
|
||||||
|
os << "(" << *lazyExpr.m_transientExpression << ")";
|
||||||
|
else
|
||||||
|
os << *lazyExpr.m_transientExpression;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
os << "{** error - unchecked empty expression requested **}";
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
AssertionHandler::AssertionHandler
|
AssertionHandler::AssertionHandler
|
||||||
( StringRef const& macroName,
|
( StringRef const& macroName,
|
||||||
SourceLineInfo const& lineInfo,
|
SourceLineInfo const& lineInfo,
|
@@ -1,17 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_assertioninfo.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#include "catch_decomposer.h"
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
#include "catch_interfaces_capture.h"
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
#ifndef CATCH_ASSERTION_HANDLER_HPP_INCLUDED
|
|
||||||
#define CATCH_ASSERTION_HANDLER_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <catch2/catch_assertion_info.hpp>
|
|
||||||
#include <catch2/internal/catch_decomposer.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
|
||||||
#include <catch2/internal/catch_lazy_expr.hpp>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@@ -20,6 +19,23 @@ namespace Catch {
|
|||||||
struct IResultCapture;
|
struct IResultCapture;
|
||||||
class RunContext;
|
class RunContext;
|
||||||
|
|
||||||
|
class LazyExpression {
|
||||||
|
friend class AssertionHandler;
|
||||||
|
friend struct AssertionStats;
|
||||||
|
friend class RunContext;
|
||||||
|
|
||||||
|
ITransientExpression const* m_transientExpression = nullptr;
|
||||||
|
bool m_isNegated;
|
||||||
|
public:
|
||||||
|
LazyExpression( bool isNegated );
|
||||||
|
LazyExpression( LazyExpression const& other );
|
||||||
|
LazyExpression& operator = ( LazyExpression const& ) = delete;
|
||||||
|
|
||||||
|
explicit operator bool() const;
|
||||||
|
|
||||||
|
friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
|
||||||
|
};
|
||||||
|
|
||||||
struct AssertionReaction {
|
struct AssertionReaction {
|
||||||
bool shouldDebugBreak = false;
|
bool shouldDebugBreak = false;
|
||||||
bool shouldThrow = false;
|
bool shouldThrow = false;
|
||||||
@@ -69,4 +85,4 @@ namespace Catch {
|
|||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_ASSERTION_HANDLER_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
|
31
include/internal/catch_assertioninfo.h
Normal file
31
include/internal/catch_assertioninfo.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_ASSERTIONINFO_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_ASSERTIONINFO_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_result_type.h"
|
||||||
|
#include "catch_common.h"
|
||||||
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct AssertionInfo
|
||||||
|
{
|
||||||
|
StringRef macroName;
|
||||||
|
SourceLineInfo lineInfo;
|
||||||
|
StringRef capturedExpression;
|
||||||
|
ResultDisposition::Flags resultDisposition;
|
||||||
|
|
||||||
|
// We want to delete this constructor but a compiler bug in 4.8 means
|
||||||
|
// the struct is then treated as non-aggregate
|
||||||
|
//AssertionInfo() = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_ASSERTIONINFO_H_INCLUDED
|
@@ -1,15 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/12
|
||||||
|
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_assertionresult.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
#include <catch2/catch_assertion_result.hpp>
|
|
||||||
#include <catch2/internal/catch_stream.hpp>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
|
AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
|
||||||
lazyExpression(_lazyExpression),
|
lazyExpression(_lazyExpression),
|
||||||
resultType(_resultType) {}
|
resultType(_resultType) {}
|
@@ -1,19 +1,19 @@
|
|||||||
|
/*
|
||||||
// Copyright Catch2 Authors
|
* Created by Phil on 28/10/2010.
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
*
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
*/
|
||||||
#ifndef CATCH_ASSERTION_RESULT_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
|
||||||
#define CATCH_ASSERTION_RESULT_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <catch2/catch_assertion_info.hpp>
|
#include "catch_assertioninfo.h"
|
||||||
#include <catch2/internal/catch_result_type.hpp>
|
#include "catch_result_type.h"
|
||||||
#include <catch2/internal/catch_common.hpp>
|
#include "catch_common.h"
|
||||||
#include <catch2/internal/catch_stringref.hpp>
|
#include "catch_stringref.h"
|
||||||
#include <catch2/internal/catch_lazy_expr.hpp>
|
#include "catch_assertionhandler.h"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@@ -56,4 +56,4 @@ namespace Catch {
|
|||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // CATCH_ASSERTION_RESULT_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
|
@@ -1,22 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 18/10/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_assertionhandler.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#include "catch_interfaces_capture.h"
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
#include "catch_message.h"
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
#ifndef CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
|
|
||||||
#define CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <catch2/internal/catch_assertion_handler.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_capture.hpp>
|
|
||||||
#include <catch2/internal/catch_stringref.hpp>
|
|
||||||
|
|
||||||
// We need this suppression to leak, because it took until GCC 9
|
|
||||||
// for the front end to handle local suppression via _Pragma properly
|
|
||||||
#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 9
|
|
||||||
#pragma GCC diagnostic ignored "-Wparentheses"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CATCH_CONFIG_DISABLE)
|
#if !defined(CATCH_CONFIG_DISABLE)
|
||||||
|
|
||||||
@@ -120,6 +115,26 @@
|
|||||||
} while( false )
|
} while( false )
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
||||||
|
do { \
|
||||||
|
Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
|
||||||
|
catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
|
||||||
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
|
} while( false )
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
|
||||||
|
auto varName = Catch::Capturer( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \
|
||||||
|
varName.captureValues( 0, __VA_ARGS__ )
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define INTERNAL_CATCH_INFO( macroName, log ) \
|
||||||
|
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log );
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
|
||||||
|
Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Although this is matcher-based, it can be used with just a string
|
// Although this is matcher-based, it can be used with just a string
|
||||||
@@ -141,4 +156,4 @@
|
|||||||
|
|
||||||
#endif // CATCH_CONFIG_DISABLE
|
#endif // CATCH_CONFIG_DISABLE
|
||||||
|
|
||||||
#endif // CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
24
include/internal/catch_capture_matchers.cpp
Normal file
24
include/internal/catch_capture_matchers.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 9/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include "catch_capture_matchers.h"
|
||||||
|
#include "catch_interfaces_registry_hub.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
|
||||||
|
|
||||||
|
// This is the general overload that takes a any string matcher
|
||||||
|
// There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers
|
||||||
|
// the Equals matcher (so the header does not mention matchers)
|
||||||
|
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) {
|
||||||
|
std::string exceptionMessage = Catch::translateActiveException();
|
||||||
|
MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
|
||||||
|
handler.handleExpr( expr );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Catch
|
@@ -1,27 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 9/8/2017
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_capture.hpp"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#include "catch_matchers.h"
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
#include "catch_matchers_exception.hpp"
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
#include "catch_matchers_floating.h"
|
||||||
|
#include "catch_matchers_generic.hpp"
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#include "catch_matchers_string.h"
|
||||||
#ifndef CATCH_MATCHERS_IMPL_HPP_INCLUDED
|
#include "catch_matchers_vector.h"
|
||||||
#define CATCH_MATCHERS_IMPL_HPP_INCLUDED
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
#include <catch2/internal/catch_test_macro_impl.hpp>
|
|
||||||
#include <catch2/internal/catch_stringref.hpp>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
template<typename ArgT, typename MatcherT>
|
template<typename ArgT, typename MatcherT>
|
||||||
class MatchExpr : public ITransientExpression {
|
class MatchExpr : public ITransientExpression {
|
||||||
ArgT && m_arg;
|
ArgT const& m_arg;
|
||||||
MatcherT const& m_matcher;
|
MatcherT m_matcher;
|
||||||
StringRef m_matcherString;
|
StringRef m_matcherString;
|
||||||
public:
|
public:
|
||||||
MatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString )
|
MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString )
|
||||||
: ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose
|
: ITransientExpression{ true, matcher.match( arg ) },
|
||||||
m_arg( std::forward<ArgT>(arg) ),
|
m_arg( arg ),
|
||||||
m_matcher( matcher ),
|
m_matcher( matcher ),
|
||||||
m_matcherString( matcherString )
|
m_matcherString( matcherString )
|
||||||
{}
|
{}
|
||||||
@@ -36,18 +42,13 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Matchers {
|
using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
|
||||||
template <typename ArgT>
|
|
||||||
struct MatcherBase;
|
|
||||||
}
|
|
||||||
|
|
||||||
using StringMatcher = Matchers::MatcherBase<std::string>;
|
|
||||||
|
|
||||||
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString );
|
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString );
|
||||||
|
|
||||||
template<typename ArgT, typename MatcherT>
|
template<typename ArgT, typename MatcherT>
|
||||||
auto makeMatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> {
|
auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> {
|
||||||
return MatchExpr<ArgT, MatcherT>( std::forward<ArgT>(arg), matcher, matcherString );
|
return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString );
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
@@ -84,5 +85,4 @@ namespace Catch {
|
|||||||
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( false )
|
} while( false )
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
||||||
#endif // CATCH_MATCHERS_IMPL_HPP_INCLUDED
|
|
38
include/internal/catch_clara.h
Normal file
38
include/internal/catch_clara.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 10/2/2014.
|
||||||
|
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
|
||||||
|
|
||||||
|
// Use Catch's value for console width (store Clara's off to the side, if present)
|
||||||
|
#ifdef CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
|
#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
||||||
|
#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
||||||
|
#endif
|
||||||
|
#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wweak-vtables"
|
||||||
|
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||||
|
#pragma clang diagnostic ignored "-Wshadow"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../external/clara.hpp"
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Restore Clara's value for console width, if present
|
||||||
|
#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
|
#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
|
#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
|
@@ -1,26 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 02/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_commandline.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
#include "catch_string_manip.h"
|
||||||
#include <catch2/internal/catch_commandline.hpp>
|
|
||||||
|
|
||||||
#include <catch2/catch_config.hpp>
|
#include "catch_interfaces_registry_hub.h"
|
||||||
#include <catch2/internal/catch_string_manip.hpp>
|
#include "catch_interfaces_reporter.h"
|
||||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_reporter_registry.hpp>
|
|
||||||
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
|
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
Clara::Parser makeCommandLineParser( ConfigData& config ) {
|
clara::Parser makeCommandLineParser( ConfigData& config ) {
|
||||||
|
|
||||||
using namespace Clara;
|
using namespace clara;
|
||||||
|
|
||||||
auto const setWarning = [&]( std::string const& warning ) {
|
auto const setWarning = [&]( std::string const& warning ) {
|
||||||
auto warningSet = [&]() {
|
auto warningSet = [&]() {
|
||||||
@@ -61,18 +61,18 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
auto const setTestOrder = [&]( std::string const& order ) {
|
auto const setTestOrder = [&]( std::string const& order ) {
|
||||||
if( startsWith( "declared", order ) )
|
if( startsWith( "declared", order ) )
|
||||||
config.runOrder = TestRunOrder::Declared;
|
config.runOrder = RunTests::InDeclarationOrder;
|
||||||
else if( startsWith( "lexical", order ) )
|
else if( startsWith( "lexical", order ) )
|
||||||
config.runOrder = TestRunOrder::LexicographicallySorted;
|
config.runOrder = RunTests::InLexicographicalOrder;
|
||||||
else if( startsWith( "random", order ) )
|
else if( startsWith( "random", order ) )
|
||||||
config.runOrder = TestRunOrder::Randomized;
|
config.runOrder = RunTests::InRandomOrder;
|
||||||
else
|
else
|
||||||
return ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
|
return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
|
||||||
return ParserResult::ok( ParseResultType::Matched );
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
};
|
};
|
||||||
auto const setRngSeed = [&]( std::string const& seed ) {
|
auto const setRngSeed = [&]( std::string const& seed ) {
|
||||||
if( seed != "time" )
|
if( seed != "time" )
|
||||||
return Clara::Detail::convertInto( seed, config.rngSeed );
|
return clara::detail::convertInto( seed, config.rngSeed );
|
||||||
config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
|
config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
|
||||||
return ParserResult::ok( ParseResultType::Matched );
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
};
|
};
|
||||||
@@ -185,6 +185,9 @@ namespace Catch {
|
|||||||
| Opt( setVerbosity, "quiet|normal|high" )
|
| Opt( setVerbosity, "quiet|normal|high" )
|
||||||
["-v"]["--verbosity"]
|
["-v"]["--verbosity"]
|
||||||
( "set output verbosity" )
|
( "set output verbosity" )
|
||||||
|
| Opt( config.listTestNamesOnly )
|
||||||
|
["--list-test-names-only"]
|
||||||
|
( "list all/matching test cases names only" )
|
||||||
| Opt( config.listReporters )
|
| Opt( config.listReporters )
|
||||||
["--list-reporters"]
|
["--list-reporters"]
|
||||||
( "list all reporters" )
|
( "list all reporters" )
|
20
include/internal/catch_commandline.h
Normal file
20
include/internal/catch_commandline.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 02/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_config.hpp"
|
||||||
|
#include "catch_clara.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
clara::Parser makeCommandLineParser( ConfigData& config );
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
@@ -1,11 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 27/11/2013.
|
||||||
|
* Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
// Copyright Catch2 Authors
|
#include "catch_common.h"
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
#include "catch_context.h"
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
#include "catch_interfaces_config.h"
|
||||||
// https://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
#include <catch2/internal/catch_common.hpp>
|
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@@ -30,4 +33,11 @@ namespace Catch {
|
|||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
std::string StreamEndStop::operator+() const {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
NonCopyable::NonCopyable() = default;
|
||||||
|
NonCopyable::~NonCopyable() = default;
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user