Compare commits
135 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
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 |
12
.bazelrc
@@ -1,12 +0,0 @@
|
||||
build --enable_platform_specific_config
|
||||
|
||||
build:gcc9 --cxxopt=-std=c++2a
|
||||
build:gcc11 --cxxopt=-std=c++2a
|
||||
build:gcc13 --cxxopt=-std=c++2a
|
||||
build:clang13 --cxxopt=-std=c++17
|
||||
build:vs2019 --cxxopt=/std:c++17
|
||||
build:vs2022 --cxxopt=/std:c++17
|
||||
|
||||
build:windows --config=vs2022
|
||||
build:linux --config=gcc11
|
||||
build:macos --cxxopt=-std=c++2b
|
@@ -1,45 +1,25 @@
|
||||
---
|
||||
Language: Cpp
|
||||
Standard: c++14
|
||||
|
||||
# Note that we cannot use IncludeIsMainRegex functionality, because it
|
||||
# does not support includes in angle brackets (<>)
|
||||
SortIncludes: true
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
- Regex: <catch2/.*\.hpp>
|
||||
Priority: 1
|
||||
- Regex: <.*/.*\.hpp>
|
||||
Priority: 2
|
||||
- Regex: <.*>
|
||||
Priority: 3
|
||||
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
|
||||
AccessModifierOffset: "-4"
|
||||
AccessModifierOffset: '-4'
|
||||
AlignEscapedNewlines: Left
|
||||
AllowAllConstructorInitializersOnNextLine: "true"
|
||||
BinPackArguments: "false"
|
||||
BinPackParameters: "false"
|
||||
AllowAllConstructorInitializersOnNextLine: 'true'
|
||||
BinPackArguments: 'false'
|
||||
BinPackParameters: 'false'
|
||||
BreakConstructorInitializers: AfterColon
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: "true"
|
||||
DerivePointerAlignment: "false"
|
||||
FixNamespaceComments: "true"
|
||||
IndentCaseLabels: "false"
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||
DerivePointerAlignment: 'false'
|
||||
FixNamespaceComments: 'true'
|
||||
IncludeBlocks: Regroup
|
||||
IndentCaseLabels: 'false'
|
||||
IndentPPDirectives: AfterHash
|
||||
IndentWidth: "4"
|
||||
IndentWidth: '4'
|
||||
Language: Cpp
|
||||
NamespaceIndentation: All
|
||||
PointerAlignment: Left
|
||||
SpaceBeforeCtorInitializerColon: "false"
|
||||
SpaceInEmptyParentheses: "false"
|
||||
SpacesInParentheses: "true"
|
||||
TabWidth: "4"
|
||||
SpaceBeforeCtorInitializerColon: 'false'
|
||||
SpaceInEmptyParentheses: 'false'
|
||||
SpacesInParentheses: 'true'
|
||||
Standard: Cpp11
|
||||
TabWidth: '4'
|
||||
UseTab: Never
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SortUsingDeclarations: true
|
||||
ReflowComments: true
|
||||
|
||||
...
|
||||
|
82
.clang-tidy
@@ -1,82 +0,0 @@
|
||||
---
|
||||
# Note: Alas, `Checks` is a string, not an array.
|
||||
# Comments in the block string are not parsed and are passed in the value.
|
||||
# They must thus be delimited by ',' from either side - then they are
|
||||
# harmless. It's terrible, but it works.
|
||||
Checks: >-
|
||||
clang-diagnostic-*,
|
||||
clang-analyzer-*,
|
||||
-clang-analyzer-optin.core.EnumCastOutOfRange,
|
||||
|
||||
bugprone-*,
|
||||
-bugprone-unchecked-optional-access,
|
||||
,# This is ridiculous, as it triggers on constants,
|
||||
-bugprone-implicit-widening-of-multiplication-result,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
,# Is not really useful, has false positives, triggers for no-noexcept move constructors ...,
|
||||
-bugprone-exception-escape,
|
||||
-bugprone-narrowing-conversions,
|
||||
-bugprone-chained-comparison,# RIP decomposers,
|
||||
|
||||
modernize-*,
|
||||
-modernize-avoid-c-arrays,
|
||||
-modernize-use-auto,
|
||||
-modernize-use-emplace,
|
||||
-modernize-use-nullptr,# it went crazy with three-way comparison operators,
|
||||
-modernize-use-trailing-return-type,
|
||||
-modernize-return-braced-init-list,
|
||||
-modernize-concat-nested-namespaces,
|
||||
-modernize-use-nodiscard,
|
||||
-modernize-use-default-member-init,
|
||||
-modernize-type-traits,# we need to support C++14,
|
||||
-modernize-deprecated-headers,
|
||||
,# There's a lot of these and most of them are probably not useful,
|
||||
-modernize-pass-by-value,
|
||||
|
||||
performance-*,
|
||||
performance-enum-size,
|
||||
|
||||
portability-*,
|
||||
|
||||
readability-*,
|
||||
-readability-braces-around-statements,
|
||||
-readability-container-size-empty,
|
||||
-readability-convert-member-functions-to-static,
|
||||
-readability-else-after-return,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-function-size,
|
||||
-readability-identifier-length,
|
||||
-readability-implicit-bool-conversion,
|
||||
-readability-isolate-declaration,
|
||||
-readability-magic-numbers,
|
||||
-readability-math-missing-parentheses, #no, 'a + B * C' obeying math rules is not confusing,
|
||||
-readability-named-parameter,
|
||||
-readability-qualified-auto,
|
||||
-readability-redundant-access-specifiers,
|
||||
-readability-simplify-boolean-expr,
|
||||
-readability-static-definition-in-anonymous-namespace,
|
||||
-readability-uppercase-literal-suffix,
|
||||
-readability-use-anyofallof,
|
||||
-readability-avoid-return-with-void-value,
|
||||
|
||||
,# time hogs,
|
||||
-bugprone-throw-keyword-missing,
|
||||
-modernize-replace-auto-ptr,
|
||||
-readability-identifier-naming,
|
||||
|
||||
,# We cannot use this until clang-tidy supports custom unique_ptr,
|
||||
-bugprone-use-after-move,
|
||||
,# Doesn't recognize unevaluated context in CATCH_MOVE and CATCH_FORWARD,
|
||||
-bugprone-macro-repeated-side-effects,
|
||||
WarningsAsErrors: >-
|
||||
clang-analyzer-core.*,
|
||||
clang-analyzer-cplusplus.*,
|
||||
clang-analyzer-security.*,
|
||||
clang-analyzer-unix.*,
|
||||
performance-move-const-arg,
|
||||
performance-unnecessary-value-param,
|
||||
readability-duplicate-include,
|
||||
HeaderFilterRegex: '.*\.(c|cxx|cpp)$'
|
||||
FormatStyle: none
|
||||
CheckOptions: {}
|
||||
...
|
@@ -26,8 +26,8 @@ class BuilderSettings(object):
|
||||
""" Set Catch2 repository to be used on upload.
|
||||
The upload server address could be customized by env var
|
||||
CONAN_UPLOAD. If not defined, the method will check the branch name.
|
||||
Only devel or CONAN_STABLE_BRANCH_PATTERN will be accepted.
|
||||
The devel branch will be pushed to testing channel, because it does
|
||||
Only master or CONAN_STABLE_BRANCH_PATTERN will be accepted.
|
||||
The master branch will be pushed to testing channel, because it does
|
||||
not match the stable pattern. Otherwise it will upload to stable
|
||||
channel.
|
||||
"""
|
||||
@@ -49,7 +49,7 @@ class BuilderSettings(object):
|
||||
def reference(self):
|
||||
""" 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
|
||||
def channel(self):
|
||||
@@ -85,7 +85,7 @@ if __name__ == "__main__":
|
||||
reference=settings.reference,
|
||||
channel=settings.channel,
|
||||
upload=settings.upload,
|
||||
upload_only_when_stable=False,
|
||||
upload_only_when_stable=settings.upload_only_when_stable,
|
||||
stable_branch_pattern=settings.stable_branch_pattern,
|
||||
login_username=settings.login_username,
|
||||
username=settings.username,
|
||||
|
@@ -1,7 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(PackageTest LANGUAGES CXX)
|
||||
cmake_minimum_required(VERSION 3.2.0)
|
||||
project(test_package CXX)
|
||||
|
||||
find_package(Catch2 CONFIG REQUIRED)
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup(TARGETS)
|
||||
|
||||
add_executable(test_package test_package.cpp)
|
||||
target_link_libraries(test_package Catch2::Catch2WithMain)
|
||||
find_package(Catch2 REQUIRED CONFIG)
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} CONAN_PKG::Catch2)
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 11)
|
||||
|
@@ -1,28 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from conan import ConanFile
|
||||
from conan.tools.cmake import CMake, cmake_layout
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.files import save, load
|
||||
from conans import ConanFile, CMake
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
|
||||
test_type = "explicit"
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def generate(self):
|
||||
save(self, os.path.join(self.build_folder, "package_folder"),
|
||||
self.dependencies[self.tested_reference_str].package_folder)
|
||||
save(self, os.path.join(self.build_folder, "license"),
|
||||
self.dependencies[self.tested_reference_str].license)
|
||||
generators = "cmake"
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
@@ -30,11 +14,6 @@ class TestPackageConan(ConanFile):
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if can_run(self):
|
||||
cmd = os.path.join(self.cpp.build.bindir, "test_package")
|
||||
self.run(cmd, env="conanrun")
|
||||
|
||||
package_folder = load(self, os.path.join(self.build_folder, "package_folder"))
|
||||
license = load(self, os.path.join(self.build_folder, "license"))
|
||||
assert os.path.isfile(os.path.join(package_folder, "licenses", "LICENSE.txt"))
|
||||
assert license == 'BSL-1.0'
|
||||
assert os.path.isfile(os.path.join(self.deps_cpp_info["Catch2"].rootpath, "licenses", "LICENSE.txt"))
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
self.run("%s -s" % bin_path, run_environment=True)
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#define CATCH_CONFIG_MAIN
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
int Factorial( int number ) {
|
||||
return number <= 1 ? 1 : Factorial( number - 1 ) * number;
|
||||
|
1
.github/FUNDING.yml
vendored
@@ -1,2 +1 @@
|
||||
github: "horenmar"
|
||||
custom: "https://www.paypal.me/horenmar"
|
||||
|
24
.github/workflows/linux-bazel-builds.yml
vendored
@@ -1,24 +0,0 @@
|
||||
name: Linux Builds (Bazel)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build_and_test_ubuntu:
|
||||
name: Linux Ubuntu 22.04 Bazel build <GCC 11.2.0>
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
compilation_mode: [fastbuild, dbg, opt]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Mount Bazel cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: "/home/runner/.cache/bazel"
|
||||
key: bazel-ubuntu22-gcc11
|
||||
|
||||
- name: Build
|
||||
run: bazelisk build --compilation_mode=${{matrix.compilation_mode}} //...
|
44
.github/workflows/linux-meson-builds.yml
vendored
@@ -1,44 +0,0 @@
|
||||
name: Linux Builds (Meson)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: meson ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}}
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
cxx:
|
||||
- g++-11
|
||||
- clang++-11
|
||||
build_type: [debug, release]
|
||||
std: [14, 17]
|
||||
include:
|
||||
- cxx: clang++-11
|
||||
other_pkgs: clang-11
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y meson ninja-build ${{matrix.other_pkgs}}
|
||||
|
||||
- name: Configure
|
||||
env:
|
||||
CXX: ${{matrix.cxx}}
|
||||
CXXFLAGS: -std=c++${{matrix.std}} ${{matrix.cxxflags}}
|
||||
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
|
||||
# This is important
|
||||
run: |
|
||||
meson -Dbuildtype=${{matrix.build_type}} ${{runner.workspace}}/meson-build
|
||||
|
||||
- name: Build
|
||||
working-directory: ${{runner.workspace}}/meson-build
|
||||
run: ninja
|
||||
|
||||
- name: Test
|
||||
working-directory: ${{runner.workspace}}/meson-build
|
||||
run: meson test --verbose
|
125
.github/workflows/linux-other-builds.yml
vendored
@@ -1,125 +0,0 @@
|
||||
# The builds in this file are more complex (e.g. they need custom CMake
|
||||
# configuration) and thus are unsuitable to the simple build matrix
|
||||
# approach used in simple-builds
|
||||
name: Linux Builds (Complex)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.build_description}}, ${{matrix.cxx}}, C++${{matrix.std}} ${{matrix.build_type}}
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
# We add builds one by one in this case, because there are no
|
||||
# dimensions that are shared across the builds
|
||||
include:
|
||||
|
||||
# Single surrogate header build
|
||||
- cxx: clang++-14
|
||||
build_description: Surrogates build
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: clang-14
|
||||
cmake_configurations: -DCATCH_BUILD_SURROGATES=ON
|
||||
|
||||
# Extras and examples with gcc-11
|
||||
- cxx: g++-11
|
||||
build_description: Extras + Examples
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: g++-11
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON
|
||||
- cxx: g++-11
|
||||
build_description: Extras + Examples
|
||||
build_type: Release
|
||||
std: 14
|
||||
other_pkgs: g++-11
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON
|
||||
|
||||
# Extras and examples with Clang-14
|
||||
- cxx: clang++-14
|
||||
build_description: Extras + Examples
|
||||
build_type: Debug
|
||||
std: 17
|
||||
other_pkgs: clang-14
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON
|
||||
- cxx: clang++-14
|
||||
build_description: Extras + Examples
|
||||
build_type: Release
|
||||
std: 17
|
||||
other_pkgs: clang-14
|
||||
cmake_configurations: -DCATCH_BUILD_EXTRA_TESTS=ON -DCATCH_BUILD_EXAMPLES=ON -DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON
|
||||
|
||||
# Configure tests with Clang-14
|
||||
- cxx: clang++-14
|
||||
build_description: CMake configuration tests
|
||||
build_type: Debug
|
||||
std: 14
|
||||
other_pkgs: clang-14
|
||||
cmake_configurations: -DCATCH_ENABLE_CONFIGURE_TESTS=ON
|
||||
|
||||
# Valgrind test Clang-14
|
||||
# - cxx: clang++-14
|
||||
# build_description: Valgrind tests
|
||||
# build_type: Debug
|
||||
# std: 14
|
||||
# other_pkgs: clang-14 valgrind
|
||||
# cmake_configurations: -DMEMORYCHECK_COMMAND=`which valgrind` -DMEMORYCHECK_COMMAND_OPTIONS="-q --track-origins=yes --leak-check=full --num-callers=50 --show-leak-kinds=definite --error-exitcode=1"
|
||||
# other_ctest_args: -T memcheck -LE uses-python
|
||||
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build ${{matrix.other_pkgs}}
|
||||
|
||||
- name: Configure build
|
||||
run: |
|
||||
cmake --preset basic-tests -GNinja \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_CXX_COMPILER=${{matrix.cxx}} \
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
${{matrix.cmake_configurations}}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Test
|
||||
run: ctest --test-dir build -j --output-on-failure
|
||||
|
||||
clang-tidy:
|
||||
name: clang-tidy
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build clang-15 clang-tidy-15
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
clangtidy="clang-tidy-15;-use-color"
|
||||
# Use a dummy compiler/linker/ar/ranlib to effectively disable the
|
||||
# compilation and only run clang-tidy.
|
||||
cmake --preset basic-tests -GNinja \
|
||||
-DCMAKE_AR=/usr/bin/true \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_CXX_CLANG_TIDY="$clangtidy" \
|
||||
-DCMAKE_CXX_COMPILER_AR=/usr/bin/true \
|
||||
-DCMAKE_CXX_COMPILER_LAUNCHER=/usr/bin/true \
|
||||
-DCMAKE_CXX_COMPILER=clang++-15 \
|
||||
-DCMAKE_CXX_LINK_EXECUTABLE=/usr/bin/true \
|
||||
-DCMAKE_CXX_STANDARD=17 \
|
||||
-DCMAKE_RANLIB=/usr/bin/true \
|
||||
-DCATCH_BUILD_EXAMPLES=ON \
|
||||
-DCATCH_ENABLE_CMAKE_HELPER_TESTS=ON
|
||||
|
||||
- name: Run clang-tidy
|
||||
run: cmake --build build
|
105
.github/workflows/linux-simple-builds.yml
vendored
@@ -1,105 +0,0 @@
|
||||
name: Linux Builds (Basic)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}}
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
cxx:
|
||||
- g++-9
|
||||
- g++-10
|
||||
- g++-11
|
||||
- g++-12
|
||||
- clang++-6.0
|
||||
- clang++-7
|
||||
- clang++-8
|
||||
- clang++-9
|
||||
- clang++-10
|
||||
- clang++-11
|
||||
- clang++-12
|
||||
- clang++-13
|
||||
- clang++-14
|
||||
build_type: [Debug, Release]
|
||||
std: [14]
|
||||
include:
|
||||
- cxx: g++-9
|
||||
other_pkgs: g++-9
|
||||
- cxx: g++-10
|
||||
other_pkgs: g++-10
|
||||
- cxx: g++-11
|
||||
other_pkgs: g++-11
|
||||
- cxx: g++-12
|
||||
other_pkgs: g++-12
|
||||
- cxx: clang++-6.0
|
||||
other_pkgs: clang-6.0
|
||||
- cxx: clang++-7
|
||||
other_pkgs: clang-7
|
||||
- cxx: clang++-8
|
||||
other_pkgs: clang-8
|
||||
- cxx: clang++-9
|
||||
other_pkgs: clang-9
|
||||
- cxx: clang++-10
|
||||
other_pkgs: clang-10
|
||||
- cxx: clang++-11
|
||||
other_pkgs: clang-11
|
||||
- cxx: clang++-12
|
||||
other_pkgs: clang-12
|
||||
- cxx: clang++-13
|
||||
other_pkgs: clang-13
|
||||
- cxx: clang++-14
|
||||
other_pkgs: clang-14
|
||||
# Clang 14 + C++17
|
||||
- cxx: clang++-14
|
||||
build_type: Debug
|
||||
std: 17
|
||||
other_pkgs: clang-14
|
||||
- cxx: clang++-14
|
||||
build_type: Release
|
||||
std: 17
|
||||
other_pkgs: clang-14
|
||||
- cxx: clang++-14
|
||||
build_type: Debug
|
||||
std: 20
|
||||
other_pkgs: clang-14
|
||||
- cxx: clang++-14
|
||||
build_type: Release
|
||||
std: 20
|
||||
other_pkgs: clang-14
|
||||
- cxx: g++-11
|
||||
build_type: Debug
|
||||
std: 20
|
||||
other_pkgs: g++-11
|
||||
- cxx: g++-11
|
||||
build_type: Release
|
||||
std: 20
|
||||
other_pkgs: g++-11
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Add repositories for older compilers
|
||||
run: |
|
||||
sudo apt-add-repository 'deb http://azure.archive.ubuntu.com/ubuntu/ focal main'
|
||||
sudo apt-add-repository 'deb http://azure.archive.ubuntu.com/ubuntu/ focal universe'
|
||||
|
||||
- name: Prepare environment
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ninja-build ${{matrix.other_pkgs}}
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake --preset basic-tests -GNinja \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_CXX_COMPILER=${{matrix.cxx}} \
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}}
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Test
|
||||
run: ctest --test-dir build -j --output-on-failure
|
32
.github/workflows/mac-builds.yml
vendored
@@ -1,32 +0,0 @@
|
||||
name: Mac Builds
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# From macos-14 forward, the baseline "macos-X" image is Arm based,
|
||||
# and not Intel based.
|
||||
runs-on: ${{matrix.image}}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
image: [macos-13, macos-14, macos-15]
|
||||
build_type: [Debug, Release]
|
||||
std: [14, 17]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake --preset basic-tests -GNinja \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} \
|
||||
-DCATCH_BUILD_EXAMPLES=ON \
|
||||
-DCATCH_BUILD_EXTRA_TESTS=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build build
|
||||
|
||||
- name: Test
|
||||
run: ctest --test-dir build -j --output-on-failure
|
31
.github/workflows/package-manager-builds.yaml
vendored
@@ -1,31 +0,0 @@
|
||||
name: Package Manager Builds
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
conan_builds:
|
||||
name: Conan ${{matrix.conan_version}}
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
matrix:
|
||||
conan_version:
|
||||
- '1.63'
|
||||
- '2.1'
|
||||
|
||||
include:
|
||||
# Conan 1 has default profiles installed
|
||||
- conan_version: '1.63'
|
||||
profile_generate: 'false'
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install conan
|
||||
run: pip install conan==${{matrix.conan_version}}
|
||||
|
||||
- name: Setup conan profiles
|
||||
if: matrix.profile_generate != 'false'
|
||||
run: conan profile detect
|
||||
|
||||
- name: Run conan package create
|
||||
run: conan create . -tf .conan/test_package
|
36
.github/workflows/validate-header-guards.yml
vendored
@@ -1,36 +0,0 @@
|
||||
name: Check header guards
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Set the type of machine to run on
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Dependencies
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.7'
|
||||
- name: Install checkguard
|
||||
run: pip install guardonce
|
||||
|
||||
- name: Check that include guards are properly named
|
||||
run: |
|
||||
wrong_files=$(checkguard -r src/catch2/ -p "name | append _INCLUDED | upper")
|
||||
if [[ $wrong_files ]]; then
|
||||
echo "Files with wrong header guard:"
|
||||
echo $wrong_files
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check that there are no duplicated filenames
|
||||
run: |
|
||||
./tools/scripts/checkDuplicateFilenames.py
|
||||
|
||||
- name: Check that all source files have the correct license header
|
||||
run: |
|
||||
./tools/scripts/checkLicense.py
|
31
.github/workflows/windows-simple-builds.yml
vendored
@@ -1,31 +0,0 @@
|
||||
name: Windows Builds (Basic)
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: ${{matrix.os}}, ${{matrix.std}}, ${{matrix.build_type}}, ${{matrix.platform}}
|
||||
runs-on: ${{matrix.os}}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-2022, windows-2025]
|
||||
platform: [Win32, x64]
|
||||
build_type: [Debug, Release]
|
||||
std: [14, 17]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Configure build
|
||||
run: |
|
||||
cmake --preset all-tests `
|
||||
-A ${{matrix.platform}} `
|
||||
-DCMAKE_CXX_STANDARD=${{matrix.std}} `
|
||||
|
||||
- name: Build tests
|
||||
run: cmake --build build --config ${{matrix.build_type}} --parallel %NUMBER_OF_PROCESSORS%
|
||||
shell: cmd
|
||||
|
||||
- name: Run tests
|
||||
run: ctest --test-dir build -C ${{matrix.build_type}} -j %NUMBER_OF_PROCESSORS% --output-on-failure
|
||||
shell: cmd
|
19
.gitignore
vendored
@@ -1,5 +1,4 @@
|
||||
*.build
|
||||
!meson.build
|
||||
*.pbxuser
|
||||
*.mode1v3
|
||||
*.ncb
|
||||
@@ -12,6 +11,11 @@ Release
|
||||
xcuserdata
|
||||
CatchSelfTest.xcscheme
|
||||
Breakpoints.xcbkptlist
|
||||
projects/VS2010/TestCatch/_UpgradeReport_Files/
|
||||
projects/VS2010/TestCatch/TestCatch/TestCatch.vcxproj.filters
|
||||
projects/VisualStudio/TestCatch/UpgradeLog.XML
|
||||
projects/CMake/.idea
|
||||
projects/CMake/cmake-build-debug
|
||||
UpgradeLog.XML
|
||||
Resources/DWARF
|
||||
projects/Generated
|
||||
@@ -21,20 +25,7 @@ DerivedData
|
||||
Build
|
||||
.idea
|
||||
.vs
|
||||
.vscode
|
||||
cmake-build-*
|
||||
benchmark-dir
|
||||
.conan/test_package/build
|
||||
**/CMakeUserPresets.json
|
||||
bazel-*
|
||||
MODULE.bazel.lock
|
||||
build-fuzzers
|
||||
debug-build
|
||||
.vscode
|
||||
msvc-sln*
|
||||
# Currently we use Doxygen for dep graphs and the full docs are only slowly
|
||||
# being filled in, so we definitely do not want git to deal with the docs.
|
||||
docs/doxygen
|
||||
*.cache
|
||||
compile_commands.json
|
||||
**/*.unapproved.txt
|
||||
|
339
.travis.yml
Normal file
@@ -0,0 +1,339 @@
|
||||
language: cpp
|
||||
|
||||
branches:
|
||||
except:
|
||||
- /dev-appveyor.*/
|
||||
|
||||
common_sources: &all_sources
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-trusty
|
||||
- llvm-toolchain-trusty-3.9
|
||||
- llvm-toolchain-trusty-4.0
|
||||
- llvm-toolchain-xenial-5.0
|
||||
- llvm-toolchain-xenial-6.0
|
||||
|
||||
matrix:
|
||||
include:
|
||||
|
||||
# 1/ Linux Clang Builds
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-3.5']
|
||||
env: COMPILER='clang++-3.5'
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-3.6']
|
||||
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
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-3.9']
|
||||
env: COMPILER='clang++-3.9'
|
||||
|
||||
- os: linux
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-4.0']
|
||||
env: COMPILER='clang++-4.0'
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-5.0']
|
||||
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
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-3.9', 'libstdc++-6-dev']
|
||||
env: COMPILER='clang++-3.9' CPP14=1
|
||||
|
||||
- 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
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-6.0', 'libstdc++-8-dev']
|
||||
env: COMPILER='clang++-6.0' CPP17=1
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
addons:
|
||||
apt:
|
||||
sources: *all_sources
|
||||
packages: ['clang-6.0', 'libstdc++-8-dev']
|
||||
env: COMPILER='clang++-6.0' CPP17=1 EXAMPLES=1 COVERAGE=1 EXTRAS=1
|
||||
|
||||
# 8/ Conan
|
||||
- language: python
|
||||
python:
|
||||
- "3.7"
|
||||
dist: xenial
|
||||
install:
|
||||
- pip install conan-package-tools
|
||||
env:
|
||||
- CONAN_GCC_VERSIONS=8
|
||||
- CONAN_DOCKER_IMAGE=conanio/gcc8
|
||||
script:
|
||||
- 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:
|
||||
- export CXX=${COMPILER}
|
||||
- cd ${TRAVIS_BUILD_DIR}
|
||||
# Regenerate single header file, so it is tested in the examples...
|
||||
- python scripts/generateSingleHeader.py
|
||||
|
||||
- |
|
||||
if [[ ${CPP17} -eq 1 ]]; then
|
||||
export CPP_STANDARD=17
|
||||
elif [[ ${CPP14} -eq 1 ]]; then
|
||||
export CPP_STANDARD=14
|
||||
else
|
||||
export CPP_STANDARD=11
|
||||
fi
|
||||
|
||||
# Use Debug builds for running Valgrind and building examples
|
||||
- cmake -H. -BBuild-Debug -DCMAKE_BUILD_TYPE=Debug -Wdev -DCATCH_USE_VALGRIND=${VALGRIND} -DCATCH_BUILD_EXAMPLES=${EXAMPLES} -DCATCH_ENABLE_COVERAGE=${COVERAGE} -DCATCH_BUILD_EXTRA_TESTS=${EXTRAS} -DCMAKE_CXX_STANDARD=${CPP_STANDARD} -DCMAKE_CXX_STANDARD_REQUIRED=On -DCMAKE_CXX_EXTENSIONS=OFF
|
||||
# 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
|
||||
|
||||
|
||||
script:
|
||||
- cd Build-Debug
|
||||
- make -j 2
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j 2
|
||||
# Coverage collection does not work for OS X atm
|
||||
- |
|
||||
if [[ "${TRAVIS_OS_NAME}" == "linux" ]] && [[ "${COVERAGE}" == "1" ]]; then
|
||||
make gcov
|
||||
make lcov
|
||||
bash <(curl -s https://codecov.io/bash) -X gcov || echo "Codecov did not collect coverage reports"
|
||||
fi
|
||||
- # Go to release build
|
||||
- cd ../Build-Release
|
||||
- make -j 2
|
||||
- CTEST_OUTPUT_ON_FAILURE=1 ctest -j 2
|
121
BUILD.bazel
@@ -1,117 +1,10 @@
|
||||
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
|
||||
load("@rules_cc//cc:cc_library.bzl", "cc_library")
|
||||
load("@rules_license//rules:license.bzl", "license")
|
||||
# Load the cc_library rule.
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(
|
||||
default_applicable_licenses = [":license"],
|
||||
)
|
||||
|
||||
exports_files([
|
||||
"LICENSE.MIT",
|
||||
])
|
||||
|
||||
license(
|
||||
name = "license",
|
||||
license_kinds = ["@rules_license//licenses/spdx:BSL-1.0"],
|
||||
license_text = "LICENSE.MIT",
|
||||
)
|
||||
|
||||
expand_template(
|
||||
name = "catch_user_config",
|
||||
out = "catch2/catch_user_config.hpp",
|
||||
substitutions = {
|
||||
"@CATCH_CONFIG_CONSOLE_WIDTH@": "80",
|
||||
"@CATCH_CONFIG_DEFAULT_REPORTER@": "console",
|
||||
"#cmakedefine CATCH_CONFIG_ANDROID_LOGWRITE": "",
|
||||
"#cmakedefine CATCH_CONFIG_BAZEL_SUPPORT": "#define CATCH_CONFIG_BAZEL_SUPPORT",
|
||||
"#cmakedefine CATCH_CONFIG_COLOUR_WIN32": "",
|
||||
"#cmakedefine CATCH_CONFIG_COUNTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP11_TO_STRING": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_BYTE": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_OPTIONAL": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_STRING_VIEW": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_CPP17_VARIANT": "",
|
||||
"#cmakedefine CATCH_CONFIG_DEPRECATION_ANNOTATIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS_CUSTOM_HANDLER": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE_EXCEPTIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE_STRINGIFICATION": "",
|
||||
"#cmakedefine CATCH_CONFIG_DISABLE": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER": "",
|
||||
"#cmakedefine CATCH_CONFIG_EXPERIMENTAL_REDIRECT": "",
|
||||
"#cmakedefine CATCH_CONFIG_FALLBACK_STRINGIFIER @CATCH_CONFIG_FALLBACK_STRINGIFIER@": "",
|
||||
"#cmakedefine CATCH_CONFIG_FAST_COMPILE": "",
|
||||
"#cmakedefine CATCH_CONFIG_GETENV": "",
|
||||
"#cmakedefine CATCH_CONFIG_GLOBAL_NEXTAFTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_ANDROID_LOGWRITE": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_COLOUR_WIN32": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_COUNTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP11_TO_STRING": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_BYTE": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_OPTIONAL": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_STRING_VIEW": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_CPP17_VARIANT": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_GETENV": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_GLOBAL_NEXTAFTER": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_POSIX_SIGNALS": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_USE_ASYNC": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_WCHAR": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_WINDOWS_SEH": "",
|
||||
"#cmakedefine CATCH_CONFIG_NOSTDOUT": "",
|
||||
"#cmakedefine CATCH_CONFIG_POSIX_SIGNALS": "",
|
||||
"#cmakedefine CATCH_CONFIG_PREFIX_ALL": "",
|
||||
"#cmakedefine CATCH_CONFIG_PREFIX_MESSAGES": "",
|
||||
"#cmakedefine CATCH_CONFIG_SHARED_LIBRARY": "",
|
||||
"#cmakedefine CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT": "",
|
||||
"#cmakedefine CATCH_CONFIG_USE_ASYNC": "",
|
||||
"#cmakedefine CATCH_CONFIG_WCHAR": "",
|
||||
"#cmakedefine CATCH_CONFIG_WINDOWS_CRTDBG": "",
|
||||
"#cmakedefine CATCH_CONFIG_WINDOWS_SEH": "",
|
||||
"#cmakedefine CATCH_CONFIG_USE_BUILTIN_CONSTANT_P": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_USE_BUILTIN_CONSTANT_P": "",
|
||||
"#cmakedefine CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS": "",
|
||||
"#cmakedefine CATCH_CONFIG_NO_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS": "",
|
||||
},
|
||||
template = "src/catch2/catch_user_config.hpp.in",
|
||||
)
|
||||
|
||||
# Generated header library, modifies the include prefix to account for
|
||||
# generation path so that we can include <catch2/catch_user_config.hpp>
|
||||
# correctly.
|
||||
# Header-only rule to export catch2/catch.hpp.
|
||||
cc_library(
|
||||
name = "catch2_generated",
|
||||
hdrs = ["catch2/catch_user_config.hpp"],
|
||||
include_prefix = ".", # to manipulate -I of dependencies
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Static library, without main.
|
||||
cc_library(
|
||||
name = "catch2",
|
||||
srcs = glob(
|
||||
["src/catch2/**/*.cpp"],
|
||||
exclude = ["src/catch2/internal/catch_main.cpp"],
|
||||
),
|
||||
hdrs = glob(["src/catch2/**/*.hpp"]),
|
||||
includes = ["src/"],
|
||||
linkstatic = True,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":catch2_generated"],
|
||||
)
|
||||
|
||||
# Static library, with main.
|
||||
cc_library(
|
||||
name = "catch2_main",
|
||||
srcs = ["src/catch2/internal/catch_main.cpp"],
|
||||
includes = ["src/"],
|
||||
linkstatic = True,
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [":catch2"],
|
||||
name = "catch2",
|
||||
hdrs = ["single_include/catch2/catch.hpp"],
|
||||
visibility = ["//visibility:public"],
|
||||
includes = ["single_include/"],
|
||||
)
|
||||
|
@@ -1,9 +1,10 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
|
||||
# Avoid repeatedly including the targets
|
||||
if(NOT TARGET Catch2::Catch2)
|
||||
# Provide path for scripts
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||
# Provide path for scripts
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake)
|
||||
endif()
|
||||
|
@@ -1,91 +0,0 @@
|
||||
|
||||
# Copyright Catch2 Authors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE.txt or copy at
|
||||
# https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
##
|
||||
# This file contains options that are materialized into the Catch2
|
||||
# compiled library. All of them default to OFF, as even the positive
|
||||
# forms correspond to the user _forcing_ them to ON, while being OFF
|
||||
# means that Catch2 can use its own autodetection.
|
||||
#
|
||||
# For detailed docs look into docs/configuration.md
|
||||
|
||||
macro(AddOverridableConfigOption OptionBaseName)
|
||||
option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF)
|
||||
option(CATCH_CONFIG_NO_${OptionBaseName} "Read docs/configuration.md for details" OFF)
|
||||
mark_as_advanced(CATCH_CONFIG_${OptionBaseName} CATCH_CONFIG_NO_${OptionBaseName})
|
||||
endmacro()
|
||||
|
||||
macro(AddConfigOption OptionBaseName)
|
||||
option(CATCH_CONFIG_${OptionBaseName} "Read docs/configuration.md for details" OFF)
|
||||
mark_as_advanced(CATCH_CONFIG_${OptionBaseName})
|
||||
endmacro()
|
||||
|
||||
set(_OverridableOptions
|
||||
"ANDROID_LOGWRITE"
|
||||
"BAZEL_SUPPORT"
|
||||
"COLOUR_WIN32"
|
||||
"COUNTER"
|
||||
"CPP11_TO_STRING"
|
||||
"CPP17_BYTE"
|
||||
"CPP17_OPTIONAL"
|
||||
"CPP17_STRING_VIEW"
|
||||
"CPP17_UNCAUGHT_EXCEPTIONS"
|
||||
"CPP17_VARIANT"
|
||||
"GLOBAL_NEXTAFTER"
|
||||
"POSIX_SIGNALS"
|
||||
"USE_ASYNC"
|
||||
"WCHAR"
|
||||
"WINDOWS_SEH"
|
||||
"GETENV"
|
||||
"EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT"
|
||||
"USE_BUILTIN_CONSTANT_P"
|
||||
"DEPRECATION_ANNOTATIONS"
|
||||
"EXPERIMENTAL_THREAD_SAFE_ASSERTIONS"
|
||||
)
|
||||
|
||||
foreach(OptionName ${_OverridableOptions})
|
||||
AddOverridableConfigOption(${OptionName})
|
||||
endforeach()
|
||||
|
||||
set(_OtherConfigOptions
|
||||
"DISABLE_EXCEPTIONS"
|
||||
"DISABLE_EXCEPTIONS_CUSTOM_HANDLER"
|
||||
"DISABLE"
|
||||
"DISABLE_STRINGIFICATION"
|
||||
"ENABLE_ALL_STRINGMAKERS"
|
||||
"ENABLE_OPTIONAL_STRINGMAKER"
|
||||
"ENABLE_PAIR_STRINGMAKER"
|
||||
"ENABLE_TUPLE_STRINGMAKER"
|
||||
"ENABLE_VARIANT_STRINGMAKER"
|
||||
"EXPERIMENTAL_REDIRECT"
|
||||
"FAST_COMPILE"
|
||||
"NOSTDOUT"
|
||||
"PREFIX_ALL"
|
||||
"PREFIX_MESSAGES"
|
||||
"WINDOWS_CRTDBG"
|
||||
)
|
||||
|
||||
|
||||
foreach(OptionName ${_OtherConfigOptions})
|
||||
AddConfigOption(${OptionName})
|
||||
endforeach()
|
||||
if(DEFINED BUILD_SHARED_LIBS)
|
||||
set(CATCH_CONFIG_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
|
||||
else()
|
||||
set(CATCH_CONFIG_SHARED_LIBRARY "")
|
||||
endif()
|
||||
|
||||
set(CATCH_CONFIG_DEFAULT_REPORTER "console" CACHE STRING "Read docs/configuration.md for details. The name of the reporter should be without quotes.")
|
||||
set(CATCH_CONFIG_CONSOLE_WIDTH "80" CACHE STRING "Read docs/configuration.md for details. Must form a valid integer literal.")
|
||||
|
||||
mark_as_advanced(CATCH_CONFIG_SHARED_LIBRARY CATCH_CONFIG_DEFAULT_REPORTER CATCH_CONFIG_CONSOLE_WIDTH)
|
||||
|
||||
# There is no good way to both turn this into a CMake cache variable,
|
||||
# and keep reasonable default semantics inside the project. Thus we do
|
||||
# not define it and users have to provide it as an outside variable.
|
||||
#set(CATCH_CONFIG_FALLBACK_STRINGIFIER "" CACHE STRING "Read docs/configuration.md for details.")
|
@@ -1,121 +0,0 @@
|
||||
|
||||
# Copyright Catch2 Authors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE.txt or copy at
|
||||
# https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
function(add_cxx_flag_if_supported_to_targets flagname targets)
|
||||
string(MAKE_C_IDENTIFIER ${flagname} flag_identifier)
|
||||
check_cxx_compiler_flag("${flagname}" HAVE_FLAG_${flag_identifier})
|
||||
|
||||
if(HAVE_FLAG_${flag_identifier})
|
||||
foreach(target ${targets})
|
||||
target_compile_options(${target} PRIVATE ${flagname})
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Assumes that it is only called for development builds, where warnings
|
||||
# and Werror is desired, so it also enables Werror.
|
||||
function(add_warnings_to_targets targets)
|
||||
LIST(LENGTH targets TARGETS_LEN)
|
||||
# For now we just assume 2 possibilities: msvc and msvc-like compilers,
|
||||
# and other.
|
||||
if(MSVC)
|
||||
foreach(target ${targets})
|
||||
# Force MSVC to consider everything as encoded in utf-8
|
||||
target_compile_options(${target} PRIVATE /utf-8)
|
||||
# Enable Werror equivalent
|
||||
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
|
||||
"-Wabsolute-value"
|
||||
"-Wall"
|
||||
"-Wcall-to-pure-virtual-from-ctor-dtor"
|
||||
"-Wcast-align"
|
||||
"-Wcatch-value"
|
||||
"-Wdangling"
|
||||
"-Wdeprecated"
|
||||
"-Wdeprecated-register"
|
||||
"-Wexceptions"
|
||||
"-Wexit-time-destructors"
|
||||
"-Wextra"
|
||||
"-Wextra-semi"
|
||||
"-Wfloat-equal"
|
||||
"-Wglobal-constructors"
|
||||
"-Winit-self"
|
||||
"-Wmisleading-indentation"
|
||||
"-Wmismatched-new-delete"
|
||||
"-Wmismatched-return-types"
|
||||
"-Wmismatched-tags"
|
||||
"-Wmissing-braces"
|
||||
"-Wmissing-declarations"
|
||||
"-Wmissing-noreturn"
|
||||
"-Wmissing-prototypes"
|
||||
"-Wmissing-variable-declarations"
|
||||
"-Wnon-virtual-dtor"
|
||||
"-Wnull-dereference"
|
||||
"-Wold-style-cast"
|
||||
"-Woverloaded-virtual"
|
||||
"-Wparentheses"
|
||||
"-Wpedantic"
|
||||
"-Wredundant-decls"
|
||||
"-Wreorder"
|
||||
"-Wreturn-std-move"
|
||||
"-Wshadow"
|
||||
"-Wstrict-aliasing"
|
||||
"-Wsubobject-linkage"
|
||||
"-Wsuggest-destructor-override"
|
||||
"-Wsuggest-override"
|
||||
"-Wundef"
|
||||
"-Wuninitialized"
|
||||
"-Wunneeded-internal-declaration"
|
||||
"-Wunreachable-code-aggressive"
|
||||
"-Wunused"
|
||||
"-Wunused-function"
|
||||
"-Wunused-parameter"
|
||||
"-Wvla"
|
||||
"-Wweak-vtables"
|
||||
|
||||
# This is a useful warning, but our tests sometimes rely on
|
||||
# functions being present, but not picked (e.g. various checks
|
||||
# for stringification implementation ordering).
|
||||
# Ergo, we should use it every now and then, but we cannot
|
||||
# enable it by default.
|
||||
# "-Wunused-member-function"
|
||||
)
|
||||
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()
|
||||
|
||||
# Adds flags required for reproducible build to the target
|
||||
# Currently only supports GCC and Clang
|
||||
function(add_build_reproducibility_settings target)
|
||||
# Make the build reproducible on versions of g++ and clang that supports -ffile-prefix-map
|
||||
if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
|
||||
add_cxx_flag_if_supported_to_targets("-ffile-prefix-map=${CATCH_DIR}/=" "${target}")
|
||||
endif()
|
||||
endfunction()
|
26
CMake/MiscFunctions.cmake
Normal file
@@ -0,0 +1,26 @@
|
||||
#checks that the given hard-coded list contains all headers + sources in the given folder
|
||||
function(CheckFileList LIST_VAR FOLDER)
|
||||
set(MESSAGE " should be added to the variable ${LIST_VAR}")
|
||||
set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
|
||||
file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp"
|
||||
"${FOLDER}/*.hpp"
|
||||
"${FOLDER}/*.h")
|
||||
list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
|
||||
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()
|
||||
|
||||
function(CheckFileListRec LIST_VAR FOLDER)
|
||||
set(MESSAGE " should be added to the variable ${LIST_VAR}")
|
||||
set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n")
|
||||
file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp"
|
||||
"${FOLDER}/*.hpp"
|
||||
"${FOLDER}/*.h")
|
||||
list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}})
|
||||
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()
|
@@ -1,10 +0,0 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
libdir=${prefix}/@lib_dir@
|
||||
pkg_version=@Catch2_VERSION@
|
||||
|
||||
Name: Catch2 with main function
|
||||
Description: A modern, C++-native test framework for C++14 and above (links in default main)
|
||||
URL: https://github.com/catchorg/Catch2
|
||||
Version: ${pkg_version}
|
||||
Requires: catch2 = ${pkg_version}
|
||||
Libs: -L${libdir} -l@lib_name@
|
@@ -1,11 +1,7 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
includedir=${prefix}/@include_dir@
|
||||
libdir=${prefix}/@lib_dir@
|
||||
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||
|
||||
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
|
||||
Version: @Catch2_VERSION@
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -l@lib_name@
|
||||
|
328
CMakeLists.txt
@@ -1,162 +1,194 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
# detect if Catch is being bundled,
|
||||
# disable testsuite in that case
|
||||
if(NOT DEFINED PROJECT_NAME)
|
||||
set(NOT_SUBPROJECT ON)
|
||||
else()
|
||||
set(NOT_SUBPROJECT OFF)
|
||||
set(NOT_SUBPROJECT ON)
|
||||
endif()
|
||||
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON)
|
||||
option(CATCH_INSTALL_EXTRAS "Install extras (CMake scripts, debugger helpers) alongside library" ON)
|
||||
option(CATCH_DEVELOPMENT_BUILD "Build tests, enable warnings, enable Werror, etc" OFF)
|
||||
option(CATCH_ENABLE_REPRODUCIBLE_BUILD "Add compiler flags for improving build reproducibility" ON)
|
||||
|
||||
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)
|
||||
cmake_dependent_option(CATCH_BUILD_SURROGATES "Enable generating and building surrogate TUs for the main headers" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_ENABLE_CONFIGURE_TESTS "Enable CMake configuration tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
cmake_dependent_option(CATCH_ENABLE_CMAKE_HELPER_TESTS "Enable CMake helper tests. WARNING: VERY EXPENSIVE" OFF "CATCH_DEVELOPMENT_BUILD" OFF)
|
||||
|
||||
# Catch2's build breaks if done in-tree. You probably should not build
|
||||
# things in tree anyway, but we can allow projects that include Catch2
|
||||
# as a subproject to build in-tree as long as it is not in our tree.
|
||||
if(CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
|
||||
if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
|
||||
endif()
|
||||
|
||||
project(Catch2
|
||||
VERSION 3.9.1 # CML version placeholder, don't delete
|
||||
LANGUAGES CXX
|
||||
HOMEPAGE_URL "https://github.com/catchorg/Catch2"
|
||||
DESCRIPTION "A modern, C++-native, unit test framework."
|
||||
)
|
||||
|
||||
# Provide path for scripts. We first add path to the scripts we don't use,
|
||||
# but projects including us might, and set the path up to parent scope.
|
||||
# Then we also add path that we use to configure the project, but is of
|
||||
# no use to top level projects.
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extras")
|
||||
if(NOT NOT_SUBPROJECT)
|
||||
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
|
||||
endif()
|
||||
project(Catch2 LANGUAGES CXX VERSION 2.13.1)
|
||||
|
||||
# Provide path for scripts
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
include(CatchConfigOptions)
|
||||
if(CATCH_DEVELOPMENT_BUILD)
|
||||
include(CTest)
|
||||
endif()
|
||||
|
||||
# This variable is used in some subdirectories, so we need it here, rather
|
||||
# than later in the install block
|
||||
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
|
||||
option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF)
|
||||
option(CATCH_BUILD_TESTING "Build SelfTest project" ON)
|
||||
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
|
||||
# are built during these tests, so this is required here, before
|
||||
# the subdirectories are added.
|
||||
if(CATCH_TEST_USE_WMAIN)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
|
||||
endif()
|
||||
|
||||
# Basic paths
|
||||
# define some folders
|
||||
set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(SOURCES_DIR ${CATCH_DIR}/src/catch2)
|
||||
set(SELF_TEST_DIR ${CATCH_DIR}/tests/SelfTest)
|
||||
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
||||
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
|
||||
set(HEADER_DIR ${CATCH_DIR}/include)
|
||||
|
||||
# We need to bring-in the variables defined there to this scope
|
||||
add_subdirectory(src)
|
||||
if(USE_WMAIN)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup")
|
||||
endif()
|
||||
|
||||
# Build tests only if requested
|
||||
if(BUILD_TESTING AND CATCH_BUILD_TESTING AND NOT_SUBPROJECT)
|
||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
||||
if(NOT TARGET Python3::Interpreter)
|
||||
message(FATAL_ERROR "Python not found, but required for tests")
|
||||
endif()
|
||||
set(CMAKE_FOLDER "tests")
|
||||
add_subdirectory(tests)
|
||||
if(NOT_SUBPROJECT)
|
||||
include(CTest)
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
if(BUILD_TESTING AND CATCH_BUILD_TESTING)
|
||||
find_package(PythonInterp)
|
||||
if (NOT PYTHONINTERP_FOUND)
|
||||
message(FATAL_ERROR "Python not found, but required for tests")
|
||||
endif()
|
||||
add_subdirectory(projects)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CATCH_BUILD_EXAMPLES)
|
||||
set(CMAKE_FOLDER "Examples")
|
||||
add_subdirectory(examples)
|
||||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
if(CATCH_BUILD_EXTRA_TESTS)
|
||||
set(CMAKE_FOLDER "tests/ExtraTests")
|
||||
add_subdirectory(tests/ExtraTests)
|
||||
add_subdirectory(projects/ExtraTests)
|
||||
endif()
|
||||
|
||||
if(CATCH_BUILD_FUZZERS)
|
||||
set(CMAKE_FOLDER "fuzzing")
|
||||
add_subdirectory(fuzzing)
|
||||
# add catch as a 'linkable' target
|
||||
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()
|
||||
|
||||
if(CATCH_DEVELOPMENT_BUILD)
|
||||
set(CATCH_ALL_TARGETS ${CATCH_IMPL_TARGETS} ${CATCH_TEST_TARGETS})
|
||||
add_warnings_to_targets("${CATCH_ALL_TARGETS}")
|
||||
# After we added the noreturn hint to FAIL and SKIP, Clang became
|
||||
# extremely good at diagnosing tests that test these macros as being
|
||||
# noreturn, but not marked as such. This made the warning useless for
|
||||
# our test files.
|
||||
add_cxx_flag_if_supported_to_targets("-Wno-missing-noreturn" "${CATCH_TEST_TARGETS}")
|
||||
endif()
|
||||
# provide a namespaced alias for clients to 'link' against if catch is included as a sub-project
|
||||
add_library(Catch2::Catch2 ALIAS Catch2)
|
||||
|
||||
# Only perform the installation steps when Catch is not being used as
|
||||
# a subproject via `add_subdirectory`, or the destinations will break,
|
||||
# see https://github.com/catchorg/Catch2/issues/1373
|
||||
if(NOT_SUBPROJECT)
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
|
||||
INSTALL_DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
if (NOT_SUBPROJECT)
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2")
|
||||
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
||||
COMPATIBILITY
|
||||
SameMajorVersion
|
||||
)
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake
|
||||
INSTALL_DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
|
||||
|
||||
# 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
|
||||
# generated on. Because Catch2 is header-only, it is arch-independent
|
||||
# and thus Catch2ConfigVersion should not be tied to the architecture
|
||||
# it was generated on.
|
||||
#
|
||||
# CMake does not provide a direct customization point for this in
|
||||
# `write_basic_package_version_file`, but it can be accomplished
|
||||
# indirectly by temporarily redefining `CMAKE_SIZEOF_VOID_P` to an
|
||||
# empty string. Note that just undefining the variable could be
|
||||
# insufficient in cases where the variable was already in CMake cache
|
||||
set(CATCH2_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
|
||||
set(CMAKE_SIZEOF_VOID_P "")
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
||||
DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
COMPATIBILITY
|
||||
SameMajorVersion
|
||||
)
|
||||
set(CMAKE_SIZEOF_VOID_P ${CATCH2_CMAKE_SIZEOF_VOID_P})
|
||||
|
||||
# Install documentation
|
||||
if(CATCH_INSTALL_DOCS)
|
||||
install(
|
||||
DIRECTORY
|
||||
docs/
|
||||
"single_include/"
|
||||
DESTINATION
|
||||
"${CMAKE_INSTALL_DOCDIR}"
|
||||
PATTERN "doxygen" EXCLUDE
|
||||
"${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CATCH_INSTALL_EXTRAS)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake"
|
||||
DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
|
||||
# Install documentation
|
||||
if(CATCH_INSTALL_DOCS)
|
||||
install(
|
||||
DIRECTORY
|
||||
docs/
|
||||
DESTINATION
|
||||
"${CMAKE_INSTALL_DOCDIR}"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CATCH_INSTALL_HELPERS)
|
||||
# Install CMake scripts
|
||||
install(
|
||||
FILES
|
||||
"extras/ParseAndAddCatchTests.cmake"
|
||||
"extras/Catch.cmake"
|
||||
"extras/CatchAddTests.cmake"
|
||||
"extras/CatchShardTests.cmake"
|
||||
"extras/CatchShardTestsImpl.cmake"
|
||||
"contrib/ParseAndAddCatchTests.cmake"
|
||||
"contrib/Catch.cmake"
|
||||
"contrib/CatchAddTests.cmake"
|
||||
DESTINATION
|
||||
${CATCH_CMAKE_CONFIG_DESTINATION}
|
||||
)
|
||||
@@ -164,55 +196,39 @@ if(NOT_SUBPROJECT)
|
||||
# Install debugger helpers
|
||||
install(
|
||||
FILES
|
||||
"extras/gdbinit"
|
||||
"extras/lldbinit"
|
||||
"contrib/gdbinit"
|
||||
"contrib/lldbinit"
|
||||
DESTINATION
|
||||
${CMAKE_INSTALL_DATAROOTDIR}/Catch2
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
## Provide some pkg-config integration
|
||||
set(PKGCONFIG_INSTALL_DIR
|
||||
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
|
||||
CACHE PATH "Path where catch2.pc is installed"
|
||||
)
|
||||
## Provide some pkg-config integration
|
||||
set(PKGCONFIG_INSTALL_DIR
|
||||
"${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig"
|
||||
CACHE PATH "Path where catch2.pc is installed"
|
||||
)
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/catch2.pc
|
||||
@ONLY
|
||||
)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/catch2.pc"
|
||||
DESTINATION
|
||||
${PKGCONFIG_INSTALL_DIR}
|
||||
)
|
||||
|
||||
# Generate the pkg-config files
|
||||
# To understand the script below, you have to understand that it works in two steps.
|
||||
# 1) A CMake script is generated at configuration time
|
||||
# 2) It is executed at install time.
|
||||
# And both of these have access to different parts of the information we need.
|
||||
#
|
||||
# Further, the variables before "[[" are expanded at configuration time,
|
||||
# while the ones inside the [[]] block are expanded at script execution (install) time.
|
||||
string(
|
||||
JOIN "\n"
|
||||
install_script
|
||||
"set(install_pkgconfdir \"${PKGCONFIG_INSTALL_DIR}\")"
|
||||
"set(impl_pc_file \"${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in\")"
|
||||
"set(main_pc_file \"${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2-with-main.pc.in\")"
|
||||
"set(Catch2_VERSION ${Catch2_VERSION})"
|
||||
"set(include_dir \"${CMAKE_INSTALL_INCLUDEDIR}\")"
|
||||
"set(lib_dir \"${CMAKE_INSTALL_LIBDIR}\")"
|
||||
[[
|
||||
set(lib_name "$<TARGET_FILE_BASE_NAME:Catch2>")
|
||||
configure_file(
|
||||
"${impl_pc_file}"
|
||||
"${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2.pc"
|
||||
@ONLY
|
||||
)
|
||||
# CPack/CMake started taking the package version from project version 3.12
|
||||
# So we need to set the version manually for older CMake versions
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
||||
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
|
||||
endif()
|
||||
|
||||
set(lib_name "$<TARGET_FILE_BASE_NAME:Catch2WithMain>")
|
||||
configure_file(
|
||||
"${main_pc_file}"
|
||||
"${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2-with-main.pc"
|
||||
@ONLY
|
||||
)
|
||||
]]
|
||||
)
|
||||
install(CODE "${install_script}")
|
||||
set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/")
|
||||
|
||||
set(CPACK_PACKAGE_CONTACT "https://github.com/catchorg/Catch2/")
|
||||
|
||||
include(CPack)
|
||||
endif()
|
||||
include( CPack )
|
||||
|
||||
endif(NOT_SUBPROJECT)
|
||||
|
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"version": 3,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "basic-tests",
|
||||
"binaryDir": "build",
|
||||
"installDir": "build/install",
|
||||
"displayName": "Basic development build",
|
||||
"description": "Enables development build with basic tests that are cheap to build and run",
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_EXTENSIONS": "OFF",
|
||||
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
||||
"CATCH_DEVELOPMENT_BUILD": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "all-tests",
|
||||
"inherits": "basic-tests",
|
||||
"displayName": "Full development build",
|
||||
"description": "Enables development build with examples and ALL tests",
|
||||
"cacheVariables": {
|
||||
"CATCH_BUILD_EXAMPLES": "ON",
|
||||
"CATCH_BUILD_EXTRA_TESTS": "ON",
|
||||
"CATCH_BUILD_SURROGATES": "ON",
|
||||
"CATCH_ENABLE_CONFIGURE_TESTS": "ON",
|
||||
"CATCH_ENABLE_CMAKE_HELPER_TESTS": "ON"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Catch2 Maintainers
|
||||
|
||||
## Current
|
||||
|
||||
* Chris Thrasher ([@christhrasher](https://github.com/ChrisThrasher)), gpg key: 56FB686C9DFC8E2C
|
||||
* Martin Hořeňovský ([@horenmar](https://github.com/horenmar)), gpg key: E29C46F3B8A7502860793B7DECC9C20E314B2360
|
||||
|
||||
## Retired
|
||||
|
||||
* Phil Nash ([@philsquared](https://github.com/philsquared))
|
@@ -1,5 +0,0 @@
|
||||
module(name = "catch2")
|
||||
|
||||
bazel_dep(name = "bazel_skylib", version = "1.7.1")
|
||||
bazel_dep(name = "rules_cc", version = "0.1.1")
|
||||
bazel_dep(name = "rules_license", version = "1.0.0")
|
100
README.md
@@ -1,92 +1,28 @@
|
||||
<a id="top"></a>
|
||||

|
||||

|
||||
|
||||
[](https://github.com/catchorg/catch2/releases)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/linux-simple-builds.yml)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/linux-other-builds.yml)
|
||||
[](https://github.com/catchorg/Catch2/actions/workflows/mac-builds.yml)
|
||||
[](https://ci.appveyor.com/project/catchorg/catch2)
|
||||
[](https://codecov.io/gh/catchorg/Catch2)
|
||||
[](https://godbolt.org/z/EdoY15q9G)
|
||||
[](https://travis-ci.org/catchorg/Catch2)
|
||||
[](https://ci.appveyor.com/project/catchorg/catch2)
|
||||
[](https://codecov.io/gh/catchorg/Catch2)
|
||||
[](https://wandbox.org/permlink/6JUH8Eybx4CtvkJS)
|
||||
[](https://discord.gg/4CWS9zD)
|
||||
|
||||
|
||||
## What is Catch2?
|
||||
<a href="https://github.com/catchorg/Catch2/releases/download/v2.13.1/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
|
||||
|
||||
Catch2 is mainly a unit testing framework for C++, but it also
|
||||
provides basic micro-benchmarking features, and simple BDD macros.
|
||||
## Catch2 is released!
|
||||
|
||||
Catch2's main advantage is that using it is both simple and natural.
|
||||
Test names do not have to be valid identifiers, assertions look like
|
||||
normal C++ boolean expressions, and sections provide a nice and local way
|
||||
to share set-up and tear-down code in tests.
|
||||
If you've been using an earlier version of Catch, please see the
|
||||
Breaking Changes section of [the release notes](https://github.com/catchorg/Catch2/releases/tag/v2.0.1)
|
||||
before moving to Catch2. You might also like to read [this blog post](https://levelofindirection.com/blog/catch2-released.html) for more details.
|
||||
|
||||
**Example unit test**
|
||||
```cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
uint32_t factorial( uint32_t number ) {
|
||||
return number <= 1 ? number : factorial(number-1) * number;
|
||||
}
|
||||
|
||||
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
REQUIRE( factorial( 1) == 1 );
|
||||
REQUIRE( factorial( 2) == 2 );
|
||||
REQUIRE( factorial( 3) == 6 );
|
||||
REQUIRE( factorial(10) == 3'628'800 );
|
||||
}
|
||||
```
|
||||
|
||||
**Example microbenchmark**
|
||||
```cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/benchmark/catch_benchmark.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
uint64_t fibonacci(uint64_t number) {
|
||||
return number < 2 ? number : fibonacci(number - 1) + fibonacci(number - 2);
|
||||
}
|
||||
|
||||
TEST_CASE("Benchmark Fibonacci", "[!benchmark]") {
|
||||
REQUIRE(fibonacci(5) == 5);
|
||||
|
||||
REQUIRE(fibonacci(20) == 6'765);
|
||||
BENCHMARK("fibonacci 20") {
|
||||
return fibonacci(20);
|
||||
};
|
||||
|
||||
REQUIRE(fibonacci(25) == 75'025);
|
||||
BENCHMARK("fibonacci 25") {
|
||||
return fibonacci(25);
|
||||
};
|
||||
}
|
||||
```
|
||||
|
||||
_Note that benchmarks are not run by default, so you need to run it explicitly
|
||||
with the `[!benchmark]` tag._
|
||||
|
||||
|
||||
## Catch2 v3 has been released!
|
||||
|
||||
You are on the `devel` branch, where the v3 version is being developed.
|
||||
v3 brings a bunch of significant changes, the big one being that Catch2
|
||||
is no longer a single-header library. Catch2 now behaves as a normal
|
||||
library, with multiple headers and separately compiled implementation.
|
||||
|
||||
The documentation is slowly being updated to take these changes into
|
||||
account, but this work is currently still ongoing.
|
||||
|
||||
For migrating from the v2 releases to v3, you should look at [our
|
||||
documentation](docs/migrate-v2-to-v3.md#top). It provides a simple
|
||||
guidelines on getting started, and collects most common migration
|
||||
problems.
|
||||
|
||||
For the previous major version of Catch2 [look into the `v2.x` branch
|
||||
here on GitHub](https://github.com/catchorg/Catch2/tree/v2.x).
|
||||
## What's the Catch?
|
||||
|
||||
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
|
||||
This documentation comprises these three parts:
|
||||
@@ -95,9 +31,7 @@ This documentation comprises these three parts:
|
||||
* [Tutorial](docs/tutorial.md#top) - getting started
|
||||
* [Reference section](docs/Readme.md#top) - all the details
|
||||
|
||||
|
||||
## More
|
||||
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/catchorg/Catch2/issues)
|
||||
* For discussion or questions please use [our Discord](https://discord.gg/4CWS9zD)
|
||||
* See who else is using Catch2 in [Open Source Software](docs/opensource-users.md#top)
|
||||
or [commercially](docs/commercial-users.md#top).
|
||||
* For discussion or questions please use [the dedicated Google Groups forum](https://groups.google.com/forum/?fromgroups#!forum/catch-forum) or our [Discord](https://discord.gg/4CWS9zD)
|
||||
* See [who else is using Catch2](docs/opensource-users.md#top)
|
||||
|
19
SECURITY.md
@@ -1,19 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
* Versions 1.x (branch Catch1.x) are no longer supported.
|
||||
* Versions 2.x (branch v2.x) are currently supported.
|
||||
* `devel` branch serves for stable-ish development and is supported,
|
||||
but branches `devel-*` are considered short lived and are not supported separately.
|
||||
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Due to its nature as a _unit_ test framework, Catch2 shouldn't interact
|
||||
with untrusted inputs and there shouldn't be many security vulnerabilities
|
||||
in it.
|
||||
|
||||
However, if you find one you send email to martin <dot> horenovsky <at>
|
||||
gmail <dot> com. If you want to encrypt the email, my pgp key is
|
||||
`E29C 46F3 B8A7 5028 6079 3B7D ECC9 C20E 314B 2360`.
|
136
appveyor.yml
@@ -1,37 +1,93 @@
|
||||
version: "{build}-{branch}"
|
||||
|
||||
# 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 Github Actions.
|
||||
branches:
|
||||
except:
|
||||
- /devel-gha.+/
|
||||
|
||||
# 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;C:\Python35\Scripts;%PATH%
|
||||
- set PATH=C:\Python35\Scripts;%PATH%
|
||||
|
||||
|
||||
branches:
|
||||
except:
|
||||
- /dev-travis.+/
|
||||
|
||||
os:
|
||||
- Visual Studio 2017
|
||||
- Visual Studio 2015
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- 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:
|
||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { pip --disable-pip-version-check install codecov }
|
||||
# This removes our changes to PATH. Keep this step last!
|
||||
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { .\tools\misc\installOpenCppCoverage.ps1 }
|
||||
- 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:
|
||||
# We need to modify PATH again, because it was reset since the "init" step
|
||||
- set PATH=C:\Python35;C:\Python35\Scripts;%PATH%
|
||||
- set CXXFLAGS=%additional_flags%
|
||||
# If we are building examples/extra-tests, we need to regenerate the amalgamated files
|
||||
- cmd: if "%examples%"=="1" ( python .\tools\scripts\generateAmalgamatedFiles.py )
|
||||
# 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://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
|
||||
@@ -42,42 +98,4 @@ build:
|
||||
|
||||
test_script:
|
||||
- set CTEST_OUTPUT_ON_FAILURE=1
|
||||
- cmd: .\tools\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 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 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 Coverage
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
coverage: 1
|
||||
platform: x64
|
||||
configuration: Debug
|
||||
- cmd: .\misc\appveyorTestRunScript.bat
|
||||
|
BIN
artwork/catch2-c-logo.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
artwork/catch2-hand-logo.png
Normal file
After Width: | Height: | Size: 33 KiB |
BIN
artwork/catch2-logo-small.png
Normal file
After Width: | Height: | Size: 20 KiB |
@@ -10,13 +10,16 @@ coverage:
|
||||
default:
|
||||
target: 80%
|
||||
ignore:
|
||||
- "projects/SelfTest"
|
||||
- "**/catch_reporter_tap.hpp"
|
||||
- "**/catch_reporter_automake.hpp"
|
||||
- "**/catch_reporter_teamcity.hpp"
|
||||
- "**/catch_reporter_sonarqube.hpp"
|
||||
- "**/external/clara.hpp"
|
||||
- "tests"
|
||||
|
||||
|
||||
codecov:
|
||||
branch: devel
|
||||
max_report_age: off
|
||||
branch: master
|
||||
|
||||
comment:
|
||||
layout: "diff"
|
||||
|
133
conanfile.py
Executable file → Normal file
@@ -1,129 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
from conan import ConanFile
|
||||
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
|
||||
from conan.tools.files import copy, rmdir
|
||||
from conan.tools.build import check_min_cppstd
|
||||
from conan.tools.scm import Version
|
||||
from conan.errors import ConanInvalidConfiguration
|
||||
import os
|
||||
import re
|
||||
from conans import ConanFile, CMake
|
||||
|
||||
required_conan_version = ">=1.53.0"
|
||||
|
||||
class CatchConan(ConanFile):
|
||||
name = "catch2"
|
||||
description = "A modern, C++-native, framework for unit-tests, TDD and BDD"
|
||||
topics = ("conan", "catch2", "unit-test", "tdd", "bdd")
|
||||
name = "Catch2"
|
||||
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
|
||||
topics = ("conan", "catch2", "header-only", "unit-test", "tdd", "bdd")
|
||||
url = "https://github.com/catchorg/Catch2"
|
||||
homepage = url
|
||||
license = "BSL-1.0"
|
||||
version = "latest"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
extension_properties = {"compatibility_cppstd": False}
|
||||
|
||||
options = {
|
||||
"shared": [True, False],
|
||||
"fPIC": [True, False],
|
||||
}
|
||||
default_options = {
|
||||
"shared": False,
|
||||
"fPIC": True,
|
||||
}
|
||||
|
||||
@property
|
||||
def _min_cppstd(self):
|
||||
return "14"
|
||||
|
||||
@property
|
||||
def _compilers_minimum_version(self):
|
||||
return {
|
||||
"gcc": "7",
|
||||
"Visual Studio": "15",
|
||||
"msvc": "191",
|
||||
"clang": "5",
|
||||
"apple-clang": "10",
|
||||
}
|
||||
|
||||
|
||||
def set_version(self):
|
||||
pattern = re.compile(r"\w*VERSION (\d+\.\d+\.\d+) # CML version placeholder, don't delete")
|
||||
with open("CMakeLists.txt") as file:
|
||||
for line in file:
|
||||
result = pattern.search(line)
|
||||
if result:
|
||||
self.version = result.group(1)
|
||||
|
||||
self.output.info(f'Using version: {self.version}')
|
||||
|
||||
def export(self):
|
||||
copy(self, "LICENSE.txt", src=self.recipe_folder, dst=self.export_folder)
|
||||
|
||||
def export_sources(self):
|
||||
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)
|
||||
copy(self, "src/*", src=self.recipe_folder, dst=self.export_sources_folder)
|
||||
copy(self, "extras/*", src=self.recipe_folder, dst=self.export_sources_folder)
|
||||
copy(self, "CMake/*", src=self.recipe_folder, dst=self.export_sources_folder)
|
||||
|
||||
def config_options(self):
|
||||
if self.settings.os == "Windows":
|
||||
del self.options.fPIC
|
||||
|
||||
def configure(self):
|
||||
if self.options.shared:
|
||||
self.options.rm_safe("fPIC")
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def validate(self):
|
||||
if self.settings.compiler.get_safe("cppstd"):
|
||||
check_min_cppstd(self, self._min_cppstd)
|
||||
# INFO: Conan 1.x does not specify cppstd by default, so we need to check the compiler version instead.
|
||||
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
|
||||
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
|
||||
raise ConanInvalidConfiguration(f"{self.ref} requires C++{self._min_cppstd}, which your compiler doesn't support")
|
||||
|
||||
def generate(self):
|
||||
tc = CMakeToolchain(self)
|
||||
tc.cache_variables["BUILD_TESTING"] = False
|
||||
tc.cache_variables["CATCH_INSTALL_DOCS"] = False
|
||||
tc.cache_variables["CATCH_INSTALL_EXTRAS"] = True
|
||||
tc.generate()
|
||||
|
||||
deps = CMakeDeps(self)
|
||||
deps.generate()
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
exports = "LICENSE.txt"
|
||||
exports_sources = ("single_include/*", "CMakeLists.txt", "CMake/*", "contrib/*")
|
||||
generators = "cmake"
|
||||
|
||||
def package(self):
|
||||
copy(self, "LICENSE.txt", src=str(self.recipe_folder), dst=os.path.join(self.package_folder, "licenses"))
|
||||
cmake = CMake(self)
|
||||
cmake.definitions["BUILD_TESTING"] = "OFF"
|
||||
cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF"
|
||||
cmake.definitions["CATCH_INSTALL_HELPERS"] = "ON"
|
||||
cmake.configure(build_folder='build')
|
||||
cmake.install()
|
||||
rmdir(self, os.path.join(self.package_folder, "share"))
|
||||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
|
||||
copy(self, "*.cmake", src=os.path.join(self.export_sources_folder, "extras"),
|
||||
dst=os.path.join(self.package_folder, "lib", "cmake", "Catch2"))
|
||||
|
||||
self.copy(pattern="LICENSE.txt", dst="licenses")
|
||||
|
||||
def package_id(self):
|
||||
self.info.header_only()
|
||||
|
||||
def package_info(self):
|
||||
lib_suffix = "d" if self.settings.build_type == "Debug" else ""
|
||||
|
||||
self.cpp_info.set_property("cmake_file_name", "Catch2")
|
||||
self.cpp_info.set_property("cmake_target_name", "Catch2::Catch2WithMain")
|
||||
self.cpp_info.set_property("pkg_config_name", "catch2-with-main")
|
||||
|
||||
# Catch2
|
||||
self.cpp_info.components["catch2base"].set_property("cmake_file_name", "Catch2::Catch2")
|
||||
self.cpp_info.components["catch2base"].set_property("cmake_target_name", "Catch2::Catch2")
|
||||
self.cpp_info.components["catch2base"].set_property("pkg_config_name", "catch2")
|
||||
self.cpp_info.components["catch2base"].libs = ["Catch2" + lib_suffix]
|
||||
self.cpp_info.components["catch2base"].builddirs.append("lib/cmake/Catch2")
|
||||
|
||||
# Catch2WithMain
|
||||
self.cpp_info.components["catch2main"].set_property("cmake_file_name", "Catch2::Catch2WithMain")
|
||||
self.cpp_info.components["catch2main"].set_property("cmake_target_name", "Catch2::Catch2WithMain")
|
||||
self.cpp_info.components["catch2main"].set_property("pkg_config_name", "catch2-with-main")
|
||||
self.cpp_info.components["catch2main"].libs = ["Catch2Main" + lib_suffix]
|
||||
self.cpp_info.components["catch2main"].requires = ["catch2base"]
|
||||
self.cpp_info.builddirs.append("lib/cmake/Catch2")
|
||||
|
175
contrib/Catch.cmake
Normal file
@@ -0,0 +1,175 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
#[=======================================================================[.rst:
|
||||
Catch
|
||||
-----
|
||||
|
||||
This module defines a function to help use the Catch test framework.
|
||||
|
||||
The :command:`catch_discover_tests` discovers tests by asking the compiled test
|
||||
executable to enumerate its tests. This does not require CMake to be re-run
|
||||
when tests change. However, it may not work in a cross-compiling environment,
|
||||
and setting test properties is less convenient.
|
||||
|
||||
This command is intended to replace use of :command:`add_test` to register
|
||||
tests, and will create a separate CTest test for each Catch test case. Note
|
||||
that this is in some cases less efficient, as common set-up and tear-down logic
|
||||
cannot be shared by multiple test cases executing in the same instance.
|
||||
However, it provides more fine-grained pass/fail information to CTest, which is
|
||||
usually considered as more beneficial. By default, the CTest test name is the
|
||||
same as the Catch name; see also ``TEST_PREFIX`` and ``TEST_SUFFIX``.
|
||||
|
||||
.. command:: catch_discover_tests
|
||||
|
||||
Automatically add tests with CTest by querying the compiled test executable
|
||||
for available tests::
|
||||
|
||||
catch_discover_tests(target
|
||||
[TEST_SPEC arg1...]
|
||||
[EXTRA_ARGS arg1...]
|
||||
[WORKING_DIRECTORY dir]
|
||||
[TEST_PREFIX prefix]
|
||||
[TEST_SUFFIX suffix]
|
||||
[PROPERTIES name1 value1...]
|
||||
[TEST_LIST var]
|
||||
)
|
||||
|
||||
``catch_discover_tests`` sets up a post-build command on the test executable
|
||||
that generates the list of tests by parsing the output from running the test
|
||||
with the ``--list-test-names-only`` argument. This ensures that the full
|
||||
list of tests is obtained. Since test discovery occurs at build time, it is
|
||||
not necessary to re-run CMake when the list of tests changes.
|
||||
However, it requires that :prop_tgt:`CROSSCOMPILING_EMULATOR` is properly set
|
||||
in order to function in a cross-compiling environment.
|
||||
|
||||
Additionally, setting properties on tests is somewhat less convenient, since
|
||||
the tests are not available at CMake time. Additional test properties may be
|
||||
assigned to the set of tests as a whole using the ``PROPERTIES`` option. If
|
||||
more fine-grained test control is needed, custom content may be provided
|
||||
through an external CTest script using the :prop_dir:`TEST_INCLUDE_FILES`
|
||||
directory property. The set of discovered tests is made accessible to such a
|
||||
script via the ``<target>_TESTS`` variable.
|
||||
|
||||
The options are:
|
||||
|
||||
``target``
|
||||
Specifies the Catch executable, which must be a known CMake executable
|
||||
target. CMake will substitute the location of the built executable when
|
||||
running the test.
|
||||
|
||||
``TEST_SPEC arg1...``
|
||||
Specifies test cases, wildcarded test cases, tags and tag expressions to
|
||||
pass to the Catch executable with the ``--list-test-names-only`` argument.
|
||||
|
||||
``EXTRA_ARGS arg1...``
|
||||
Any extra arguments to pass on the command line to each test case.
|
||||
|
||||
``WORKING_DIRECTORY dir``
|
||||
Specifies the directory in which to run the discovered test cases. If this
|
||||
option is not provided, the current binary directory is used.
|
||||
|
||||
``TEST_PREFIX prefix``
|
||||
Specifies a ``prefix`` to be prepended to the name of each discovered test
|
||||
case. This can be useful when the same test executable is being used in
|
||||
multiple calls to ``catch_discover_tests()`` but with different
|
||||
``TEST_SPEC`` or ``EXTRA_ARGS``.
|
||||
|
||||
``TEST_SUFFIX suffix``
|
||||
Similar to ``TEST_PREFIX`` except the ``suffix`` is appended to the name of
|
||||
every discovered test case. Both ``TEST_PREFIX`` and ``TEST_SUFFIX`` may
|
||||
be specified.
|
||||
|
||||
``PROPERTIES name1 value1...``
|
||||
Specifies additional properties to be set on all tests discovered by this
|
||||
invocation of ``catch_discover_tests``.
|
||||
|
||||
``TEST_LIST var``
|
||||
Make the list of tests available in the variable ``var``, rather than the
|
||||
default ``<target>_TESTS``. This can be useful when the same test
|
||||
executable is being used in multiple calls to ``catch_discover_tests()``.
|
||||
Note that this variable is only available in CTest.
|
||||
|
||||
#]=======================================================================]
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
function(catch_discover_tests TARGET)
|
||||
cmake_parse_arguments(
|
||||
""
|
||||
""
|
||||
"TEST_PREFIX;TEST_SUFFIX;WORKING_DIRECTORY;TEST_LIST"
|
||||
"TEST_SPEC;EXTRA_ARGS;PROPERTIES"
|
||||
${ARGN}
|
||||
)
|
||||
|
||||
if(NOT _WORKING_DIRECTORY)
|
||||
set(_WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
if(NOT _TEST_LIST)
|
||||
set(_TEST_LIST ${TARGET}_TESTS)
|
||||
endif()
|
||||
|
||||
## Generate a unique name based on the extra arguments
|
||||
string(SHA1 args_hash "${_TEST_SPEC} ${_EXTRA_ARGS}")
|
||||
string(SUBSTRING ${args_hash} 0 7 args_hash)
|
||||
|
||||
# Define rule to generate test list for aforementioned test executable
|
||||
set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include-${args_hash}.cmake")
|
||||
set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests-${args_hash}.cmake")
|
||||
get_property(crosscompiling_emulator
|
||||
TARGET ${TARGET}
|
||||
PROPERTY CROSSCOMPILING_EMULATOR
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${TARGET} POST_BUILD
|
||||
BYPRODUCTS "${ctest_tests_file}"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "TEST_TARGET=${TARGET}"
|
||||
-D "TEST_EXECUTABLE=$<TARGET_FILE:${TARGET}>"
|
||||
-D "TEST_EXECUTOR=${crosscompiling_emulator}"
|
||||
-D "TEST_WORKING_DIR=${_WORKING_DIRECTORY}"
|
||||
-D "TEST_SPEC=${_TEST_SPEC}"
|
||||
-D "TEST_EXTRA_ARGS=${_EXTRA_ARGS}"
|
||||
-D "TEST_PROPERTIES=${_PROPERTIES}"
|
||||
-D "TEST_PREFIX=${_TEST_PREFIX}"
|
||||
-D "TEST_SUFFIX=${_TEST_SUFFIX}"
|
||||
-D "TEST_LIST=${_TEST_LIST}"
|
||||
-D "CTEST_FILE=${ctest_tests_file}"
|
||||
-P "${_CATCH_DISCOVER_TESTS_SCRIPT}"
|
||||
VERBATIM
|
||||
)
|
||||
|
||||
file(WRITE "${ctest_include_file}"
|
||||
"if(EXISTS \"${ctest_tests_file}\")\n"
|
||||
" include(\"${ctest_tests_file}\")\n"
|
||||
"else()\n"
|
||||
" add_test(${TARGET}_NOT_BUILT-${args_hash} ${TARGET}_NOT_BUILT-${args_hash})\n"
|
||||
"endif()\n"
|
||||
)
|
||||
|
||||
if(NOT ${CMAKE_VERSION} VERSION_LESS "3.10.0")
|
||||
# Add discovered tests to directory TEST_INCLUDE_FILES
|
||||
set_property(DIRECTORY
|
||||
APPEND PROPERTY TEST_INCLUDE_FILES "${ctest_include_file}"
|
||||
)
|
||||
else()
|
||||
# Add discovered tests as directory TEST_INCLUDE_FILE if possible
|
||||
get_property(test_include_file_set DIRECTORY PROPERTY TEST_INCLUDE_FILE SET)
|
||||
if (NOT ${test_include_file_set})
|
||||
set_property(DIRECTORY
|
||||
PROPERTY TEST_INCLUDE_FILE "${ctest_include_file}"
|
||||
)
|
||||
else()
|
||||
message(FATAL_ERROR
|
||||
"Cannot set more than one TEST_INCLUDE_FILE"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
endfunction()
|
||||
|
||||
###############################################################################
|
||||
|
||||
set(_CATCH_DISCOVER_TESTS_SCRIPT
|
||||
${CMAKE_CURRENT_LIST_DIR}/CatchAddTests.cmake
|
||||
)
|
81
contrib/CatchAddTests.cmake
Normal file
@@ -0,0 +1,81 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
set(prefix "${TEST_PREFIX}")
|
||||
set(suffix "${TEST_SUFFIX}")
|
||||
set(spec ${TEST_SPEC})
|
||||
set(extra_args ${TEST_EXTRA_ARGS})
|
||||
set(properties ${TEST_PROPERTIES})
|
||||
set(script)
|
||||
set(suite)
|
||||
set(tests)
|
||||
|
||||
function(add_command NAME)
|
||||
set(_args "")
|
||||
foreach(_arg ${ARGN})
|
||||
if(_arg MATCHES "[^-./:a-zA-Z0-9_]")
|
||||
set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument
|
||||
else()
|
||||
set(_args "${_args} ${_arg}")
|
||||
endif()
|
||||
endforeach()
|
||||
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Run test executable to get list of available tests
|
||||
if(NOT EXISTS "${TEST_EXECUTABLE}")
|
||||
message(FATAL_ERROR
|
||||
"Specified test executable '${TEST_EXECUTABLE}' does not exist"
|
||||
)
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only
|
||||
OUTPUT_VARIABLE output
|
||||
RESULT_VARIABLE result
|
||||
)
|
||||
# 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
|
||||
"Error running test executable '${TEST_EXECUTABLE}':\n"
|
||||
" Result: ${result}\n"
|
||||
" Output: ${output}\n"
|
||||
)
|
||||
endif()
|
||||
|
||||
string(REPLACE "\n" ";" output "${output}")
|
||||
|
||||
# Parse output
|
||||
foreach(line ${output})
|
||||
set(test ${line})
|
||||
# Escape characters in test case names that would be parsed by Catch2
|
||||
set(test_name ${test})
|
||||
foreach(char , [ ])
|
||||
string(REPLACE ${char} "\\${char}" test_name ${test_name})
|
||||
endforeach(char)
|
||||
# ...and add to script
|
||||
add_command(add_test
|
||||
"${prefix}${test}${suffix}"
|
||||
${TEST_EXECUTOR}
|
||||
"${TEST_EXECUTABLE}"
|
||||
"${test_name}"
|
||||
${extra_args}
|
||||
)
|
||||
add_command(set_tests_properties
|
||||
"${prefix}${test}${suffix}"
|
||||
PROPERTIES
|
||||
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
|
||||
${properties}
|
||||
)
|
||||
list(APPEND tests "${prefix}${test}${suffix}")
|
||||
endforeach()
|
||||
|
||||
# Create a list of all discovered tests, which users may use to e.g. set
|
||||
# properties on the tests
|
||||
add_command(set ${TEST_LIST} ${tests})
|
||||
|
||||
# Write CTest script
|
||||
file(WRITE "${CTEST_FILE}" "${script}")
|
@@ -1,11 +1,9 @@
|
||||
#==================================================================================================#
|
||||
# supported macros #
|
||||
# - TEST_CASE, #
|
||||
# - TEMPLATE_TEST_CASE #
|
||||
# - SCENARIO, #
|
||||
# - TEST_CASE_METHOD, #
|
||||
# - CATCH_TEST_CASE, #
|
||||
# - CATCH_TEMPLATE_TEST_CASE #
|
||||
# - CATCH_SCENARIO, #
|
||||
# - CATCH_TEST_CASE_METHOD. #
|
||||
# #
|
||||
@@ -56,7 +54,7 @@
|
||||
# #
|
||||
#==================================================================================================#
|
||||
|
||||
if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
|
||||
if (CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.8)
|
||||
message(FATAL_ERROR "ParseAndAddCatchTests requires CMake 2.8.8 or newer")
|
||||
endif()
|
||||
|
||||
@@ -67,9 +65,9 @@ option(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME "Add target name to the test na
|
||||
option(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS "Add test file to CMAKE_CONFIGURE_DEPENDS property" OFF)
|
||||
|
||||
function(ParseAndAddCatchTests_PrintDebugMessage)
|
||||
if(PARSE_CATCH_TESTS_VERBOSE)
|
||||
message(STATUS "ParseAndAddCatchTests: ${ARGV}")
|
||||
endif()
|
||||
if(PARSE_CATCH_TESTS_VERBOSE)
|
||||
message(STATUS "ParseAndAddCatchTests: ${ARGV}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# This removes the contents between
|
||||
@@ -90,161 +88,143 @@ endfunction()
|
||||
|
||||
# Worker function
|
||||
function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
|
||||
# If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
|
||||
if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
|
||||
return()
|
||||
endif()
|
||||
# According to CMake docs EXISTS behavior is well-defined only for full paths.
|
||||
get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
|
||||
if(NOT EXISTS ${SourceFile})
|
||||
message(WARNING "Cannot find source file: ${SourceFile}")
|
||||
return()
|
||||
endif()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
|
||||
file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
|
||||
|
||||
# Remove block and fullline comments
|
||||
ParseAndAddCatchTests_RemoveComments(Contents)
|
||||
|
||||
# Find definition of test names
|
||||
# https://regex101.com/r/JygOND/1
|
||||
string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([ \t\n]*\"[^\"]*\"[ \t\n]*(,[ \t\n]*\"[^\"]*\")?(,[ \t\n]*[^\,\)]*)*\\)[ \t\n]*\{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
|
||||
|
||||
if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
|
||||
set_property(
|
||||
DIRECTORY
|
||||
APPEND
|
||||
PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
|
||||
)
|
||||
endif()
|
||||
|
||||
# check CMP0110 policy for new add_test() behavior
|
||||
if(POLICY CMP0110)
|
||||
cmake_policy(GET CMP0110 _cmp0110_value) # new add_test() behavior
|
||||
else()
|
||||
# just to be thorough explicitly set the variable
|
||||
set(_cmp0110_value)
|
||||
endif()
|
||||
|
||||
foreach(TestName ${Tests})
|
||||
# Strip newlines
|
||||
string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
|
||||
|
||||
# Get test type and fixture if applicable
|
||||
string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
|
||||
string(REGEX MATCH "(CATCH_)?(TEMPLATE_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
|
||||
string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}")
|
||||
|
||||
# Get string parts of test definition
|
||||
string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}")
|
||||
|
||||
# Strip wrapping quotation marks
|
||||
string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}")
|
||||
string(REPLACE "\";\"" ";" TestStrings "${TestStrings}")
|
||||
|
||||
# Validate that a test name and tags have been provided
|
||||
list(LENGTH TestStrings TestStringsLength)
|
||||
if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1)
|
||||
message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}")
|
||||
# If SourceFile is an object library, do not scan it (as it is not a file). Exit without giving a warning about a missing file.
|
||||
if(SourceFile MATCHES "\\\$<TARGET_OBJECTS:.+>")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Detected OBJECT library: ${SourceFile} this will not be scanned for tests.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Assign name and tags
|
||||
list(GET TestStrings 0 Name)
|
||||
if("${TestType}" STREQUAL "SCENARIO")
|
||||
set(Name "Scenario: ${Name}")
|
||||
endif()
|
||||
if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture)
|
||||
set(CTestName "${TestFixture}:${Name}")
|
||||
else()
|
||||
set(CTestName "${Name}")
|
||||
endif()
|
||||
if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME)
|
||||
set(CTestName "${TestTarget}:${CTestName}")
|
||||
endif()
|
||||
# add target to labels to enable running all tests added from this target
|
||||
set(Labels ${TestTarget})
|
||||
if(TestStringsLength EQUAL 2)
|
||||
list(GET TestStrings 1 Tags)
|
||||
string(TOLOWER "${Tags}" Tags)
|
||||
# remove target from labels if the test is hidden
|
||||
if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*")
|
||||
list(REMOVE_ITEM Labels ${TestTarget})
|
||||
endif()
|
||||
string(REPLACE "]" ";" Tags "${Tags}")
|
||||
string(REPLACE "[" "" Tags "${Tags}")
|
||||
else()
|
||||
# unset tags variable from previous loop
|
||||
unset(Tags)
|
||||
# According to CMake docs EXISTS behavior is well-defined only for full paths.
|
||||
get_filename_component(SourceFile ${SourceFile} ABSOLUTE)
|
||||
if(NOT EXISTS ${SourceFile})
|
||||
message(WARNING "Cannot find source file: ${SourceFile}")
|
||||
return()
|
||||
endif()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("parsing ${SourceFile}")
|
||||
file(STRINGS ${SourceFile} Contents NEWLINE_CONSUME)
|
||||
|
||||
list(APPEND Labels ${Tags})
|
||||
# Remove block and fullline comments
|
||||
ParseAndAddCatchTests_RemoveComments(Contents)
|
||||
|
||||
set(HiddenTagFound OFF)
|
||||
foreach(label ${Labels})
|
||||
string(REGEX MATCH "^!hide|^\\." result ${label})
|
||||
if(result)
|
||||
set(HiddenTagFound ON)
|
||||
break()
|
||||
endif()
|
||||
endforeach(label)
|
||||
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label")
|
||||
else()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"")
|
||||
if(Labels)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}")
|
||||
endif()
|
||||
# Find definition of test names
|
||||
string(REGEX MATCHALL "[ \t]*(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^\)]+\\)+[ \t\n]*{+[ \t]*(//[^\n]*[Tt][Ii][Mm][Ee][Oo][Uu][Tt][ \t]*[0-9]+)*" Tests "${Contents}")
|
||||
|
||||
# Escape commas in the test spec
|
||||
string(REPLACE "," "\\," Name ${Name})
|
||||
|
||||
# Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were necessary,
|
||||
# only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1
|
||||
# And properly introduced in 3.19 with the CMP0110 policy
|
||||
if(_cmp0110_value STREQUAL "NEW" OR ${CMAKE_VERSION} VERSION_EQUAL "3.18")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to NEW, no need for add_test(\"\") workaround")
|
||||
else()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("CMP0110 set to OLD adding \"\" for add_test() workaround")
|
||||
set(CTestName "\"${CTestName}\"")
|
||||
endif()
|
||||
|
||||
# Handle template test cases
|
||||
if("${TestTypeAndFixture}" MATCHES ".*TEMPLATE_.*")
|
||||
set(Name "${Name} - *")
|
||||
endif()
|
||||
|
||||
# Add the test and set its properties
|
||||
add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
|
||||
# Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead
|
||||
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property")
|
||||
set_tests_properties("${CTestName}" PROPERTIES DISABLED ON)
|
||||
else()
|
||||
set_tests_properties("${CTestName}" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran"
|
||||
LABELS "${Labels}")
|
||||
endif()
|
||||
if(PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS AND Tests)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Adding ${SourceFile} to CMAKE_CONFIGURE_DEPENDS property")
|
||||
set_property(
|
||||
TARGET ${TestTarget}
|
||||
DIRECTORY
|
||||
APPEND
|
||||
PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
|
||||
set_property(
|
||||
SOURCE ${SourceFile}
|
||||
APPEND
|
||||
PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
|
||||
PROPERTY CMAKE_CONFIGURE_DEPENDS ${SourceFile}
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(TestName ${Tests})
|
||||
# Strip newlines
|
||||
string(REGEX REPLACE "\\\\\n|\n" "" TestName "${TestName}")
|
||||
|
||||
# Get test type and fixture if applicable
|
||||
string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)[ \t]*\\([^,^\"]*" TestTypeAndFixture "${TestName}")
|
||||
string(REGEX MATCH "(CATCH_)?(TEST_CASE_METHOD|SCENARIO|TEST_CASE)" TestType "${TestTypeAndFixture}")
|
||||
string(REGEX REPLACE "${TestType}\\([ \t]*" "" TestFixture "${TestTypeAndFixture}")
|
||||
|
||||
# Get string parts of test definition
|
||||
string(REGEX MATCHALL "\"+([^\\^\"]|\\\\\")+\"+" TestStrings "${TestName}")
|
||||
|
||||
# Strip wrapping quotation marks
|
||||
string(REGEX REPLACE "^\"(.*)\"$" "\\1" TestStrings "${TestStrings}")
|
||||
string(REPLACE "\";\"" ";" TestStrings "${TestStrings}")
|
||||
|
||||
# Validate that a test name and tags have been provided
|
||||
list(LENGTH TestStrings TestStringsLength)
|
||||
if(TestStringsLength GREATER 2 OR TestStringsLength LESS 1)
|
||||
message(FATAL_ERROR "You must provide a valid test name and tags for all tests in ${SourceFile}")
|
||||
endif()
|
||||
|
||||
# Assign name and tags
|
||||
list(GET TestStrings 0 Name)
|
||||
if("${TestType}" STREQUAL "SCENARIO")
|
||||
set(Name "Scenario: ${Name}")
|
||||
endif()
|
||||
if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture )
|
||||
set(CTestName "${TestFixture}:${Name}")
|
||||
else()
|
||||
set(CTestName "${Name}")
|
||||
endif()
|
||||
if(PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME)
|
||||
set(CTestName "${TestTarget}:${CTestName}")
|
||||
endif()
|
||||
# add target to labels to enable running all tests added from this target
|
||||
set(Labels ${TestTarget})
|
||||
if(TestStringsLength EQUAL 2)
|
||||
list(GET TestStrings 1 Tags)
|
||||
string(TOLOWER "${Tags}" Tags)
|
||||
# remove target from labels if the test is hidden
|
||||
if("${Tags}" MATCHES ".*\\[!?(hide|\\.)\\].*")
|
||||
list(REMOVE_ITEM Labels ${TestTarget})
|
||||
endif()
|
||||
string(REPLACE "]" ";" Tags "${Tags}")
|
||||
string(REPLACE "[" "" Tags "${Tags}")
|
||||
else()
|
||||
# unset tags variable from previous loop
|
||||
unset(Tags)
|
||||
endif()
|
||||
|
||||
list(APPEND Labels ${Tags})
|
||||
|
||||
set(HiddenTagFound OFF)
|
||||
foreach(label ${Labels})
|
||||
string(REGEX MATCH "^!hide|^\\." result ${label})
|
||||
if(result)
|
||||
set(HiddenTagFound ON)
|
||||
break()
|
||||
endif(result)
|
||||
endforeach(label)
|
||||
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_LESS "3.9")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Skipping test \"${CTestName}\" as it has [!hide], [.] or [.foo] label")
|
||||
else()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Adding test \"${CTestName}\"")
|
||||
if(Labels)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Setting labels to ${Labels}")
|
||||
endif()
|
||||
|
||||
# Escape commas in the test spec
|
||||
string(REPLACE "," "\\," Name ${Name})
|
||||
|
||||
# Work around CMake 3.18.0 change in `add_test()`, before the escaped quotes were neccessary,
|
||||
# only with CMake 3.18.0 the escaped double quotes confuse the call. This change is reverted in 3.18.1
|
||||
if(NOT ${CMAKE_VERSION} VERSION_EQUAL "3.18")
|
||||
set(CTestName "\"${CTestName}\"")
|
||||
endif()
|
||||
# Add the test and set its properties
|
||||
add_test(NAME "${CTestName}" COMMAND ${OptionalCatchTestLauncher} $<TARGET_FILE:${TestTarget}> ${Name} ${AdditionalCatchParameters})
|
||||
# Old CMake versions do not document VERSION_GREATER_EQUAL, so we use VERSION_GREATER with 3.8 instead
|
||||
if(PARSE_CATCH_TESTS_NO_HIDDEN_TESTS AND ${HiddenTagFound} AND ${CMAKE_VERSION} VERSION_GREATER "3.8")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Setting DISABLED test property")
|
||||
set_tests_properties("${CTestName}" PROPERTIES DISABLED ON)
|
||||
else()
|
||||
set_tests_properties("${CTestName}" PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran"
|
||||
LABELS "${Labels}")
|
||||
endif()
|
||||
set_property(
|
||||
TARGET ${TestTarget}
|
||||
APPEND
|
||||
PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
|
||||
set_property(
|
||||
SOURCE ${SourceFile}
|
||||
APPEND
|
||||
PROPERTY ParseAndAddCatchTests_TESTS "${CTestName}")
|
||||
endif()
|
||||
|
||||
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# entry point
|
||||
function(ParseAndAddCatchTests TestTarget)
|
||||
message(DEPRECATION "ParseAndAddCatchTest: function deprecated because of possibility of missed test cases. Consider using 'catch_discover_tests' from 'Catch.cmake'")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}")
|
||||
get_target_property(SourceFiles ${TestTarget} SOURCES)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}")
|
||||
foreach(SourceFile ${SourceFiles})
|
||||
ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget})
|
||||
endforeach()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}")
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Started parsing ${TestTarget}")
|
||||
get_target_property(SourceFiles ${TestTarget} SOURCES)
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Found the following sources: ${SourceFiles}")
|
||||
foreach(SourceFile ${SourceFiles})
|
||||
ParseAndAddCatchTests_ParseFile(${SourceFile} ${TestTarget})
|
||||
endforeach()
|
||||
ParseAndAddCatchTests_PrintDebugMessage("Finished parsing ${TestTarget}")
|
||||
endfunction()
|
@@ -1,105 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="104.41245mm"
|
||||
height="120.99883mm"
|
||||
viewBox="0 0 101.59999 117.7396"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.4-beta (62f545ba5e, 2024-04-22)"
|
||||
sodipodi:docname="catch2-c-logo.svg"
|
||||
xml:space="preserve"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="2"
|
||||
inkscape:cx="181"
|
||||
inkscape:cy="192.25"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1411"
|
||||
inkscape:window-x="-9"
|
||||
inkscape:window-y="-6"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg1"
|
||||
inkscape:clip-to-page="false" /><defs
|
||||
id="defs1"><inkscape:path-effect
|
||||
effect="bspline"
|
||||
id="path-effect21"
|
||||
is_visible="true"
|
||||
lpeversion="1.3"
|
||||
weight="33.333333"
|
||||
steps="2"
|
||||
helper_size="0"
|
||||
apply_no_weight="true"
|
||||
apply_with_weight="true"
|
||||
only_selected="false"
|
||||
uniform="false" /><inkscape:path-effect
|
||||
effect="mirror_symmetry"
|
||||
start_point="73.777381,64.846856"
|
||||
end_point="82.510207,65.15"
|
||||
center_point="78.143794,64.998428"
|
||||
id="path-effect17"
|
||||
is_visible="true"
|
||||
lpeversion="1.2"
|
||||
lpesatellites=""
|
||||
mode="free"
|
||||
discard_orig_path="false"
|
||||
fuse_paths="true"
|
||||
oposite_fuse="false"
|
||||
split_items="false"
|
||||
split_open="false"
|
||||
link_styles="false" /></defs><g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer2"
|
||||
inkscape:label="Layer 1"
|
||||
style="display:inline;opacity:1"><path
|
||||
style="display:inline;opacity:1;fill:#ff2500;fill-opacity:1;stroke:none"
|
||||
d="m 51.144204,74.60863 c 2.755126,3.847649 8.114087,5.089451 12.620377,4.385634 2.354879,-0.367807 8.839176,-2.41493 8.839176,-4.301423 V 61.300036 c 0,-0.274854 -4.644748,-5.35579 -14.139807,-4.033868 -7.781631,0.854243 -12.297148,10.391313 -7.319746,17.342462 z"
|
||||
id="path19" /><path
|
||||
style="display:inline;opacity:1;fill:#000000;fill-opacity:1;stroke:none"
|
||||
d="M 51.858331,11.754161 C 41.642983,13.144685 33.527664,20.30548 26.946464,27.781252 13.41997,43.146393 1.1940791,63.412939 0.27499404,84.40209 c -0.2484557,5.673984 0.0720803,11.551339 2.02561406,16.93334 6.4303318,17.71559 27.0809729,18.5262 42.4139739,13.56112 9.635256,-3.12006 19.559145,-9.05196 26.722916,-16.206958 2.544515,-2.541399 6.489211,-6.811827 4.760053,-10.836485 -0.807945,-1.880505 -3.120844,-1.771387 -4.760053,-1.239217 -3.777039,1.226226 -7.054253,3.815005 -10.31875,5.990284 -8.595381,5.727494 -18.582582,10.587386 -29.104166,10.583336 -5.314431,-0.002 -11.064865,-1.53917 -14.276067,-6.085419 C 14.249559,92.162607 14.966246,85.515419 15.941144,79.904173 18.379578,65.869225 26.039129,51.275896 34.494849,39.952087 37.975232,35.291195 43.042486,28.027749 49.477081,27.54157 c 2.673121,-0.201974 4.452111,1.728755 5.613208,3.943849 2.172279,4.144192 2.284401,8.974146 4.143505,13.229168 1.160297,2.655628 3.911041,5.951729 7.175599,4.380934 4.423264,-2.128318 5.563981,-8.759454 5.557271,-13.112185 -0.0164,-10.64231 -7.561412,-25.937074 -20.108333,-24.229175"
|
||||
id="path14" /><path
|
||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.14596;stroke-linecap:round"
|
||||
d="m 53.953228,68.740885 v -1.206827 h 3.137751 v -3.266479 h 1.174645 v 3.266479 h 3.073387 v 1.206827 h -3.073387 v 3.202116 h -1.174645 v -3.202116 z"
|
||||
id="path15"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.14596;stroke-linecap:round"
|
||||
d="m 62.418518,68.740885 v -1.206827 h 3.137751 v -3.266479 h 1.174645 v 3.266479 h 3.073387 v 1.206827 h -3.073387 v 3.202116 h -1.174645 v -3.202116 z"
|
||||
id="path16"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
d="M 85.440222,24.062768 C 86.646399,22.95745 88.272019,22.342526 89.673556,21.247484 94.611094,17.389708 103.0499,9.5981005 101.23198,3.5611216 100.54356,1.2749953 97.954172,0.02851298 95.475242,0.19207103 92.915127,0.3609856 90.311542,1.5166605 88.615222,2.3873449 86.831645,3.3028167 85.048448,3.2384541 84.477375,4.6552681 83.67664,6.6418721 85.77327,9.3242102 87.820455,9.0669662 88.433774,8.9898962 89.041201,8.700584 89.29669,8.1526509 89.865278,6.9332293 90.823337,6.6449856 92.781525,5.7141794 94.684453,4.8096405 96.75508,4.4020758 95.458862,7.6585999 93.598546,12.332323 85.734679,17.924982 80.774891,21.407129 c 0,0 -2.282573,1.504251 -2.853005,1.705572 -1.235548,0.436059 -2.378469,0.514326 -2.192851,1.747903 0.209704,1.393648 1.686087,2.720176 2.912476,2.922238 2.91246,0.479863 3.255425,0.04457 7.857045,0.896861 1.782728,0.330191 4.511564,1.873082 5.236267,1.861978 1.114192,-0.01707 2.38496,-5.01e-4 3.098369,-0.950708 1.003097,-1.336037 0.164345,-3.66292 -1.202522,-4.426382 -2.017657,-1.126959 -6.832185,-0.826419 -8.190448,-1.101823"
|
||||
style="display:inline;opacity:1;fill:#ff2500;fill-opacity:1;stroke:none"
|
||||
id="path1"
|
||||
inkscape:label="path1"
|
||||
sodipodi:nodetypes="csssssssssssssssssc" /><circle
|
||||
style="display:inline;opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.14596;stroke-linecap:round"
|
||||
id="path20"
|
||||
cx="81.427208"
|
||||
cy="64.690056"
|
||||
r="1.1207407" /><circle
|
||||
style="display:inline;opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.14596;stroke-linecap:round"
|
||||
id="circle21"
|
||||
cx="81.427208"
|
||||
cy="71.551033"
|
||||
r="1.1207407" /><path
|
||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.14596;stroke-linecap:round"
|
||||
d="M 73.866479,74.571917 V 61.475751 c 0.716819,0.227562 4.096107,2.192671 4.096107,6.519638 0,4.326967 -3.010942,6.386799 -4.096107,6.576528 z"
|
||||
id="path21"
|
||||
sodipodi:nodetypes="cczc" /><path
|
||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.14596;stroke-linecap:round"
|
||||
d="m 77.405059,65.799422 3.424802,-1.331236 0.204807,0.933002 -3.652363,1.353992 z"
|
||||
id="path22" /><path
|
||||
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.14596;stroke-linecap:round"
|
||||
d="m 77.427815,70.4303 3.094839,1.115049 0.40961,-0.739575 -3.402045,-1.433636 z"
|
||||
id="path23" /></g></svg>
|
Before Width: | Height: | Size: 6.6 KiB |
@@ -1,83 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="221.19167mm"
|
||||
height="254mm"
|
||||
viewBox="0 0 221.19167 254"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.4-beta (62f545ba5e, 2024-04-22)"
|
||||
sodipodi:docname="catch2-hand-logo.svg"
|
||||
xml:space="preserve"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="false"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="0.75528389"
|
||||
inkscape:cx="423.01975"
|
||||
inkscape:cy="494.51604"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1411"
|
||||
inkscape:window-x="-9"
|
||||
inkscape:window-y="-6"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer3" /><defs
|
||||
id="defs1" /><g
|
||||
inkscape:groupmode="layer"
|
||||
id="layer3"
|
||||
inkscape:label="Layer 1"
|
||||
style="display:inline;opacity:1"><path
|
||||
style="display:inline;fill:#ff2500;fill-opacity:1;stroke:none;stroke-width:0.997109"
|
||||
d="m 167.951,135.96691 c 2.74718,3.83654 8.09064,5.07475 12.58391,4.37297 2.34808,-0.36675 8.81363,-2.40795 8.81363,-4.28899 v -13.3541 c 0,-0.27407 -4.63132,-5.34032 -14.09894,-4.02222 -7.75915,0.85177 -12.26161,10.36129 -7.2986,17.29234 z"
|
||||
id="path19" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.997109"
|
||||
d="m 168.66307,73.294073 c -10.18583,1.386506 -18.27769,8.526609 -24.83988,15.980778 -13.4874,15.320749 -25.67797,35.528729 -26.59439,56.457219 -0.24775,5.65759 0.0719,11.51796 2.01975,16.88442 6.41176,17.66439 27.00272,18.47266 42.29142,13.52193 9.6074,-3.11105 19.50262,-9.0258 26.64569,-16.16012 2.53716,-2.53406 6.47045,-6.79215 4.7463,-10.80518 -0.80561,-1.87507 -3.11182,-1.76626 -4.7463,-1.23563 -3.76612,1.22268 -7.03387,3.80398 -10.28893,5.97297 -8.57055,5.71095 -18.52889,10.55679 -29.02007,10.55276 -5.29907,-0.002 -11.03289,-1.53473 -14.23481,-6.06784 -3.47888,-4.92522 -2.76426,-11.55319 -1.79218,-17.14822 2.43139,-13.99439 10.06881,-28.54555 18.5001,-39.83664 3.47032,-4.647428 8.52293,-11.889884 14.93893,-12.374659 2.6654,-0.20139 4.43924,1.72376 5.59699,3.932453 2.166,4.132217 2.2778,8.948216 4.13153,13.190946 1.15694,2.64795 3.89974,5.93453 7.15487,4.36828 4.41048,-2.12217 5.5479,-8.73415 5.5412,-13.074306 -0.0164,-10.611557 -7.53956,-25.862124 -20.05022,-24.159161"
|
||||
id="path14" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.145538;stroke-linecap:round"
|
||||
d="m 170.75192,130.11613 v -1.20334 h 3.12868 v -3.25705 h 1.17125 v 3.25705 h 3.0645 v 1.20334 h -3.0645 v 3.19287 h -1.17125 v -3.19287 z"
|
||||
id="path15"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.145538;stroke-linecap:round"
|
||||
d="m 179.19274,130.11613 v -1.20334 h 3.12869 v -3.25705 h 1.17125 v 3.25705 h 3.0645 v 1.20334 h -3.0645 v 3.19287 h -1.17125 v -3.19287 z"
|
||||
id="path16"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
d="m 204.99654,83.647387 c 1.20269,-1.102124 2.82361,-1.715271 4.2211,-2.807149 4.92327,-3.846627 13.33769,-11.61572 11.52502,-17.635254 -0.68642,-2.27952 -3.26833,-3.5224 -5.7401,-3.359314 -2.55271,0.168426 -5.14878,1.320761 -6.8402,2.18893 -1.77842,0.912826 -3.55647,0.84865 -4.12589,2.26137 -0.79842,1.980862 1.29215,4.655449 3.33343,4.398949 0.61154,-0.07684 1.21721,-0.365323 1.47197,-0.911673 0.56694,-1.215898 1.52223,-1.503309 3.47476,-2.431425 1.89743,-0.901925 3.96207,-1.308312 2.6696,1.938802 -1.85495,4.660217 -9.69609,10.236715 -14.64154,13.7088 0,0 -2.27598,1.499904 -2.84476,1.700643 -1.23198,0.434799 -2.37159,0.512839 -2.18652,1.742852 0.2091,1.38962 1.68122,2.712316 2.90406,2.913793 2.90404,0.478477 3.24602,0.04444 7.83434,0.89427 1.77758,0.329237 4.49854,1.867669 5.22114,1.856598 1.11097,-0.01702 2.37807,-5e-4 3.08942,-0.947962 1.00019,-1.332175 0.16387,-3.652334 -1.19905,-4.41359 -2.01182,-1.123702 -6.81244,-0.824031 -8.16678,-1.09864"
|
||||
style="display:inline;fill:#ff2500;fill-opacity:1;stroke:none;stroke-width:0.997109"
|
||||
id="path1-4"
|
||||
inkscape:label="path2"
|
||||
sodipodi:nodetypes="csssssssssssssssssc" /><circle
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.145538;stroke-linecap:round"
|
||||
id="path20"
|
||||
cx="198.14651"
|
||||
cy="126.077"
|
||||
r="1.117502" /><circle
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.145538;stroke-linecap:round"
|
||||
id="circle21"
|
||||
cx="198.14651"
|
||||
cy="132.91815"
|
||||
r="1.117502" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.145538;stroke-linecap:round"
|
||||
d="m 190.60762,135.93031 v -13.05833 c 0.71475,0.22692 4.08427,2.18634 4.08427,6.50081 0,4.31446 -3.00224,6.36834 -4.08427,6.55752 z"
|
||||
id="path21"
|
||||
sodipodi:nodetypes="cczc" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.145538;stroke-linecap:round"
|
||||
d="m 194.13597,127.18316 3.41491,-1.32739 0.20422,0.93031 -3.64181,1.35009 z"
|
||||
id="path22" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.145538;stroke-linecap:round"
|
||||
d="m 194.15867,131.80066 3.08589,1.11183 0.40843,-0.73744 -3.39221,-1.42949 z"
|
||||
id="path23" /><path
|
||||
style="opacity:1;fill:#000000"
|
||||
d="m 52.485231,274.30677 c -1.44545,-0.96726 -2.86981,-3.09456 -3.13906,-4.6882 -0.39677,-2.34847 0.81078,-4.39701 5.15499,-8.74518 20.43177,-20.45035 46.487389,-31.49087 92.078009,-39.01608 2.25557,-0.37231 4.92152,-0.92104 5.92434,-1.21941 4.02143,-1.19651 9.24392,-3.85561 19.87253,-10.11836 9.8535,-5.80602 12.12477,-6.79037 15.66794,-6.79037 2.05936,0 4.57269,2.67656 4.57269,4.86966 0,1.68904 -2.6986,6.0579 -4.7121,7.6286 -2.28208,1.78021 -6.58253,4.6015 -11.7076,7.68073 -9.06231,5.44478 -11.98022,6.71427 -21.41534,9.31715 -5.04752,1.39246 -16.38447,4.02852 -25.53267,5.93683 -25.13851,5.24388 -25.00563,5.21162 -29.765619,7.22491 -7.03101,2.97384 -16.88366,8.57665 -28.32629,16.10804 -4.97279,3.27302 -5.23095,3.48606 -6.59919,5.44572 -2.03051,2.90821 -4.81825,5.75178 -6.42266,6.55129 -2.02273,1.00797 -3.9618,0.94437 -5.64997,-0.18533 z M 2.1166706,214.04812 c -4.43974,-1.17966 -6.29001,-2.86592 -6.50258,-5.92618 -0.0561,-0.80826 -0.34243,-2.18306 -0.6362,-3.05512 -0.29378,-0.87205 -0.53414,-2.12574 -0.53414,-2.78598 0,-2.4519 9.57939,-32.76364 14.76039,-46.70584 C 21.897901,121.41582 36.072191,94.814185 53.824111,71.834375 c 11.92384,-15.435387 26.74991,-30.208723 41.2936,-41.146727 5.899709,-4.437045 11.752929,-7.682035 15.523289,-8.606009 2.83253,-0.694146 6.49309,-0.456289 8.54715,0.55538 0.86947,0.428233 2.07876,1.254856 2.6873,1.836939 1.24377,1.189682 1.58018,2.435151 1.36349,5.048044 -0.19501,2.351645 -1.01118,3.232511 -6.23188,6.725914 -2.50094,1.67349 -7.49666,5.375621 -11.10159,8.226959 -8.626469,6.823143 -12.675559,9.813426 -18.592969,13.731047 -4.5713,3.026431 -5.19257,3.540143 -9.40057,7.773067 -6.75068,6.79066 -18.35611,20.995666 -21.41793,26.215466 -7.26888,12.392015 -19.02869,38.165965 -27.46982,60.205545 -7.14782,18.66277 -15.28897,43.14897 -16.8808,50.77253 -1.36968,6.55961 -2.3943804,8.86415 -4.6390304,10.43312 -1.42141,0.99355 -2.86689,1.11226 -5.38768,0.44247 z M 84.451711,131.53763 c -2.71586,-1.44798 -4.39099,-4.45284 -3.91041,-7.01452 0.22361,-1.19197 2.16953,-4.12452 4.94017,-7.44499 2.77937,-3.33091 13.49664,-14.08622 17.176859,-17.237833 20.86316,-17.866412 44.82366,-30.594172 72.62813,-38.579882 13.98648,-4.017052 21.64688,-4.578234 28.9691,-2.122202 2.68998,0.902278 3.92015,1.642753 4.93107,2.968151 2.42706,3.182092 1.37728,7.464086 -2.28839,9.334167 -1.72612,0.880603 -5.30307,1.720503 -18.52445,4.349714 -34.65213,6.890939 -45.21368,10.483785 -64.01962,21.778305 -4.90594,2.94642 -12.73144,8.97117 -19.60898,15.0967 -4.21536,3.75444 -5.629099,5.40595 -7.922789,9.25525 -2.61622,4.39059 -3.64884,5.89007 -5.11311,7.42481 -2.32969,2.44183 -5.17662,3.30181 -7.25758,2.19233 z m -19.34134,-7.37312 c -0.67308,-0.23773 -1.75582,-0.98544 -2.55596,-1.76505 -1.563,-1.52288 -2.12938,-2.99059 -1.84499,-4.78105 0.49788,-3.13453 6.69521,-13.63592 13.12251,-22.236119 17.01101,-22.761971 41.464519,-41.822254 69.705419,-54.331885 8.97055,-3.973604 14.33402,-5.413308 20.23973,-5.432901 6.16545,-0.02045 10.0683,1.082726 12.13437,3.429906 2.78341,3.162114 2.82958,6.444745 0.12416,8.826153 -1.53485,1.351031 -4.80881,2.63842 -18.21165,7.161207 -31.8573,10.75024 -42.5879,16.147741 -58.492839,29.421967 -5.67746,4.738392 -13.21765,12.843914 -18.77808,20.185972 -2.50637,3.30944 -3.41949,5.02515 -5.06932,9.525 -2.27988,6.21828 -3.86567,8.69854 -6.28046,9.823 -1.53672,0.71558 -2.4493,0.75433 -4.09289,0.1738 z"
|
||||
id="path1"
|
||||
sodipodi:nodetypes="sssssssssssssssssscssssssssssssssssssssscssssssssssssssssssssssss"
|
||||
transform="translate(5.8208328,-21.43125)" /></g></svg>
|
Before Width: | Height: | Size: 9.1 KiB |
@@ -1,104 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="145.25626mm"
|
||||
height="76.199997mm"
|
||||
viewBox="0 0 145.25626 76.199997"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
xml:space="preserve"
|
||||
inkscape:version="1.4-beta (62f545ba5e, 2024-04-22)"
|
||||
sodipodi:docname="catch2-logo-full-with-background.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="true"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="2.1362654"
|
||||
inkscape:cx="260.73539"
|
||||
inkscape:cy="75.599221"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1411"
|
||||
inkscape:window-x="-9"
|
||||
inkscape:window-y="-6"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg1" /><defs
|
||||
id="defs1"><inkscape:path-effect
|
||||
effect="bspline"
|
||||
id="path-effect3"
|
||||
is_visible="true"
|
||||
lpeversion="1.3"
|
||||
weight="33.333333"
|
||||
steps="2"
|
||||
helper_size="0"
|
||||
apply_no_weight="true"
|
||||
apply_with_weight="true"
|
||||
only_selected="false"
|
||||
uniform="false" /></defs><path
|
||||
style="display:inline;opacity:1;fill:#ffffff;stroke-width:0.15;stroke-linecap:round"
|
||||
d="m 20.956995,75.891056 c -0.345757,0 -1.03727,0 -1.868118,-0.381881 -0.830849,-0.38188 -1.801033,-1.145642 -2.611239,-1.78039 -0.810207,-0.634747 -1.460436,-1.140482 -2.141629,-2.265482 -0.681193,-1.125 -1.393348,-2.869267 -2.275802,-4.458716 C 11.177753,65.415137 10.125,63.980505 9.288991,63.18578 8.4529816,62.391055 7.8337157,62.236239 6.9719037,61.730505 6.1100917,61.224771 5.005734,60.36812 4.3142201,59.790138 3.6227063,59.212156 3.3440368,58.912844 2.7521924,58.147933 2.1603479,57.383023 1.2553288,56.152515 0.80464381,54.814747 0.35395881,53.476979 0.35760785,52.03195 0.54006088,50.402645 0.72251392,48.773339 1.0837708,46.959757 1.6841117,44.78319 c 0.600341,-2.176566 1.4397661,-4.716117 2.4787447,-7.477291 1.0389785,-2.761174 2.2775105,-5.743971 3.7379462,-8.690646 1.4604358,-2.946674 3.1427754,-5.857225 4.9334864,-8.581996 1.790711,-2.724771 3.689793,-5.263761 5.90883,-7.756307 2.219037,-2.492546 4.758028,-4.9386471 6.873854,-6.7138764 2.115825,-1.7752293 3.808486,-2.8795875 5.294724,-3.6227067 1.486239,-0.7431192 2.766056,-1.12499991 3.627868,-1.34174306 0.861812,-0.21674314 1.305618,-0.26834858 2.002293,-0.24770639 0.696674,0.0206422 1.646216,0.11353208 3.240826,0.46961002 1.59461,0.35607793 3.834289,0.97534413 5.692086,1.43463303 1.857798,0.4592889 3.333716,0.758601 4.226491,0.9392202 0.892775,0.1806192 1.202408,0.2425458 1.708142,0.4076835 0.505734,0.1651376 1.207568,0.4334861 1.888761,0.7276375 0.681193,0.2941515 1.341744,0.6141056 2.14679,1.0837157 0.805046,0.4696101 1.754587,1.0888762 2.564794,1.6462156 0.810206,0.5573395 1.481078,1.0527523 2.327409,1.6616971 0.84633,0.6089449 1.86812,1.3314219 2.52867,1.7855509 0.660551,0.454128 0.959862,0.639908 1.486238,1.13016 0.526376,0.490253 1.279815,1.284977 2.012613,1.986812 0.732798,0.701835 1.444954,1.31078 1.955848,1.759748 0.510895,0.448968 0.820528,0.737959 1.739106,1.290138 0.918578,0.552179 2.446102,1.367546 3.860093,1.661697 1.413991,0.294152 2.71445,0.06709 3.530437,-0.08893 0.815986,-0.15602 1.147498,-0.240994 2.178082,-0.626493 1.030584,-0.385499 2.760238,-1.071523 4.061129,-1.628004 1.30089,-0.556482 2.192163,-0.992796 2.978809,-1.214324 0.786645,-0.221529 1.541055,-0.248227 2.342041,-0.216499 0.800986,0.03173 1.690589,0.123491 2.387555,0.320239 0.696966,0.196747 1.263209,0.515637 2.793374,1.465114 1.530165,0.949478 4.037903,2.537347 5.959128,3.296351 1.92123,0.759005 3.25679,0.689673 4.91893,0.56378 1.66215,-0.125892 3.65089,-0.308346 5.73086,-1.636604 2.07996,-1.328258 4.25115,-3.80232 5.64509,-5.265593 1.39394,-1.463273 2.01063,-1.915757 3.01777,-2.432099 1.00714,-0.516342 2.40473,-1.0965425 3.9574,-1.6530243 1.55268,-0.5564818 3.26044,-1.0892445 4.73466,-1.6694444 1.47422,-0.5801999 2.71491,-1.2078409 3.99573,-1.6384293 1.28082,-0.4305884 2.60178,-0.6641283 3.75853,-0.7407587 1.15675,-0.07663 2.1493,0.00365 3.1017,0.3466601 0.9524,0.3430107 1.86467,0.9487579 2.56894,1.5143606 0.70426,0.5656028 1.20054,1.0910709 1.68951,1.7989884 0.48898,0.7079176 0.97065,1.5982856 1.26623,2.8791066 0.29557,1.280821 0.40505,2.95209 0.11312,5.079492 -0.29192,2.127402 -0.98525,4.710938 -1.51071,7.049986 -0.52547,2.339048 -0.88307,4.433606 -0.88672,6.758058 -0.004,2.324452 0.34666,4.878795 0.85388,7.46233 0.50722,2.583535 1.17134,5.196259 1.45962,7.133911 0.28827,1.937653 0.2007,3.200226 -0.51087,4.627009 -0.71157,1.426784 -2.04712,3.01777 -3.52499,3.857055 -1.47787,0.839284 -3.10388,0.927177 -5.00548,0.843658 -1.90159,-0.08352 -4.13587,-0.343101 -6.08337,-0.281904 -1.94751,0.0612 -3.72418,0.445924 -5.61643,0.945314 -1.89226,0.499389 -3.93016,1.120257 -7.01361,1.499759 -3.08346,0.379502 -7.21419,0.518166 -11.35952,0.499921 -4.14534,-0.01825 -8.305268,-0.1934 -12.516283,-0.218943 -4.211016,-0.02554 -8.473119,0.09853 -12.950516,0.135015 -4.477396,0.03649 -9.170088,-0.0146 -11.88134,0.08028 -2.711251,0.09488 -3.441064,0.335715 -4.495642,0.864829 -1.054578,0.529114 -2.433923,1.346502 -3.692849,2.21133 -1.258925,0.864827 -2.397433,1.777092 -3.638113,2.557992 -1.240681,0.780899 -2.583535,1.430431 -3.959231,2.014281 -1.375696,0.583849 -2.784233,1.102015 -4.966371,1.726004 -2.182138,0.62399 -5.137876,1.353802 -7.425836,2.010633 -2.287961,0.656831 -3.908144,1.24068 -5.094089,1.718707 -1.185945,0.478026 -1.937652,0.850231 -2.981283,1.426783 -1.043632,0.576551 -2.379187,1.357451 -3.473905,2.028878 -1.094718,0.671427 -1.948598,1.233381 -2.729497,1.572744 -0.780899,0.339362 -1.488816,0.456133 -2.20046,0.515384 -0.711644,0.05925 -1.427013,0.06099 -1.784698,0.06185 -0.357685,8.67e-4 -0.357685,8.69e-4 -0.703442,8.69e-4 z"
|
||||
id="path3"
|
||||
inkscape:path-effect="#path-effect3"
|
||||
inkscape:original-d="m 21.302752,75.891056 c -0.691514,0 -1.383027,0 -2.074541,0 -0.970183,-0.763761 -1.940367,-1.527523 -2.91055,-2.291284 -0.65023,-0.505734 -1.300459,-1.011469 -1.950689,-1.517203 C 13.654816,70.338303 12.942661,68.594036 12.230505,66.84977 11.177753,65.415137 10.125,63.980505 9.0722478,62.545872 8.4529817,62.391055 7.8337156,62.236239 7.2144495,62.081422 6.1100917,61.224771 5.005734,60.36812 3.9013762,59.511469 3.6227064,59.212156 3.3440367,58.912844 3.0653669,58.613531 2.1603479,57.383023 1.2553288,56.152515 0.35030978,54.922007 c 0.003649,-1.445028 0.007298,-2.890057 0.0109471,-4.335085 0.36125697,-1.813583 0.72251392,-3.627165 1.08377092,-5.440748 0.839425,-2.53955 1.6788499,-5.079101 2.5182749,-7.618651 1.2385321,-2.982798 2.4770643,-5.965595 3.7155964,-8.948393 1.6823393,-2.910551 3.3646789,-5.821102 5.0470179,-8.731653 1.899083,-2.538991 3.798165,-5.077981 5.697248,-7.616972 2.538991,-2.446101 5.077982,-4.8922021 7.616973,-7.3383031 1.69266,-1.1043578 3.385321,-2.2087156 5.077981,-3.3130734 1.279817,-0.3818808 2.559634,-0.76376151 3.839451,-1.14564226 0.443807,-0.0516055 0.887613,-0.10321101 1.33142,-0.15481652 0.949542,0.0928899 1.899084,0.18577981 2.848626,0.27866972 2.239678,0.61926606 4.479357,1.23853206 6.719035,1.85779816 1.475917,0.2993119 2.951835,0.5986238 4.427752,0.8979357 0.309633,0.061927 0.619266,0.1238532 0.928899,0.1857798 0.701835,0.2683486 1.403669,0.5366973 2.105504,0.8050459 0.660551,0.3199542 1.321102,0.6399083 1.981653,0.9598625 0.949541,0.619266 1.899082,1.2385321 2.848623,1.8577981 0.670872,0.4954129 1.341744,0.9908257 2.012616,1.4862386 1.021789,0.7224769 2.043579,1.4449538 3.065368,2.1674308 0.299312,0.18578 0.598623,0.37156 0.897935,0.55734 0.75344,0.794725 1.506879,1.589449 2.260319,2.384174 0.712156,0.608945 1.424312,1.21789 2.136468,1.826835 0.309633,0.288991 0.619266,0.577982 0.928899,0.866973 1.527523,0.815367 3.055047,1.630734 4.58257,2.446101 1.300459,-0.227064 2.600918,-0.454129 3.901377,-0.681193 0.331513,-0.08498 0.663026,-0.169949 0.994539,-0.254924 1.729655,-0.686023 3.459309,-1.372047 5.188964,-2.05807 0.872126,-0.42694 1.674426,-1.045002 2.616377,-1.28082 0.720313,-0.02549 1.474723,-0.05219 2.20945,-0.07819 0.867245,0.08946 1.756848,0.18122 2.607953,0.269012 0.606407,0.192807 1.10907,0.624593 1.663328,0.936734 2.546995,1.522183 5.01381,3.174683 7.520715,4.762024 1.33555,-0.06933 2.67111,-0.138664 4.00666,-0.207996 1.98874,-0.182453 3.97748,-0.364907 5.96622,-0.54736 2.17119,-2.474063 4.34238,-4.948125 6.51357,-7.422188 0.61669,-0.452483 1.23338,-0.904967 1.85007,-1.35745 1.39759,-0.580201 2.79518,-1.1604015 4.19277,-1.7406023 1.70776,-0.5327628 3.41552,-1.0655255 5.12328,-1.5982883 1.24068,-0.6276383 2.48137,-1.2552767 3.72205,-1.882915 1.32096,-0.2335398 2.64192,-0.4670797 3.96288,-0.7006195 0.99254,0.080279 1.98509,0.1605585 2.97763,0.2408377 0.91226,0.6057441 1.82453,1.2114881 2.73679,1.8172322 0.49627,0.5254647 0.99255,1.0509294 1.48882,1.5763941 0.48168,0.8903707 0.96335,1.7807411 1.44503,2.6711121 0.10947,1.67127 0.21895,3.342539 0.32842,5.013809 -0.69332,2.583535 -1.38665,5.167069 -2.07997,7.750604 -0.35761,2.094561 -0.71521,4.189121 -1.07282,6.283682 0.35031,2.554342 0.70062,5.108685 1.05093,7.663027 0.66413,2.612727 1.32825,5.225453 1.99238,7.83818 -0.0876,1.262575 -0.17515,2.52515 -0.26273,3.787725 -1.33556,1.59099 -2.67111,3.18198 -4.00667,4.77297 -1.62018,0.08758 -3.23877,0.312749 -4.86055,0.262733 -2.18883,-0.254302 -4.42311,-0.513883 -6.5902,-0.765659 -1.72792,0.37417 -3.50459,0.758897 -5.25465,1.137862 -2.06002,0.53587 -4.07235,1.240681 -6.10852,1.861021 -4.13074,0.138665 -8.26147,0.277329 -12.39221,0.415994 -4.15993,-0.175155 -8.319858,-0.35031 -12.479787,-0.525465 -4.262102,0.124068 -8.524205,0.248137 -12.786307,0.372205 -4.692691,-0.05109 -9.385383,-0.102175 -14.078074,-0.153263 -0.729812,0.240839 -1.459625,0.481678 -2.189437,0.722517 -1.379344,0.817389 -2.758689,1.634777 -4.138033,2.452166 -1.138507,0.912266 -2.277015,1.824531 -3.415522,2.736797 -1.342854,0.649533 -2.685708,1.299065 -4.028562,1.948598 -1.408538,0.518166 -2.817075,1.036332 -4.225613,1.554498 -2.955738,0.729813 -5.911476,1.459625 -8.867214,2.189438 -1.620183,0.583849 -3.240366,1.167698 -4.860549,1.751547 -0.751707,0.372204 -1.503414,0.744409 -2.255121,1.116613 -1.335556,0.780899 -2.671111,1.561799 -4.006667,2.342698 -0.85388,0.561955 -1.70776,1.123909 -2.56164,1.685864 -0.707918,0.11677 -1.415835,0.233541 -2.123753,0.350311 -0.71537,0.0017 -1.430739,0.0035 -2.146109,0.0052 z"
|
||||
sodipodi:nodetypes="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" /><g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-32.146873,-110.33125)"
|
||||
style="display:inline;opacity:1"><path
|
||||
style="display:inline;fill:#ff2500;fill-opacity:1;stroke:none;stroke-width:0.250889"
|
||||
d="m 80.95419,150.8289 c 0.691236,0.96533 2.035742,1.27689 3.166324,1.10031 0.590818,-0.0922 2.217659,-0.60588 2.217659,-1.07918 v -3.36013 c 0,-0.069 -1.165318,-1.34371 -3.547531,-1.01206 -1.952335,0.21432 -3.085228,2.60709 -1.836452,4.35106 z"
|
||||
id="path19" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.250889"
|
||||
d="m 81.13336,135.05935 c -2.562928,0.34888 -4.598977,2.14544 -6.250134,4.02102 -3.393658,3.85496 -6.461012,8.93964 -6.691599,14.2056 -0.06234,1.42355 0.01809,2.8981 0.508204,4.2484 1.613307,4.44467 6.794341,4.64804 10.641236,3.40234 2.417384,-0.78278 4.907188,-2.27103 6.704505,-4.06615 0.638393,-0.63761 1.628076,-1.70902 1.19425,-2.71876 -0.202704,-0.4718 -0.782987,-0.44442 -1.19425,-0.31091 -0.947618,0.30765 -1.76984,0.95715 -2.588867,1.50289 -2.156496,1.43698 -4.662182,2.65628 -7.301941,2.65526 -1.333335,-5e-4 -2.776062,-0.38616 -3.581718,-1.52678 -0.875345,-1.23926 -0.695536,-2.90697 -0.450943,-4.31477 0.611778,-3.52124 2.533483,-7.18254 4.654937,-10.02357 0.873192,-1.16937 2.144513,-2.99169 3.758888,-3.11367 0.670659,-0.0506 1.116987,0.43373 1.408297,0.98948 0.545003,1.03973 0.573135,2.25152 1.039561,3.31906 0.291107,0.66626 0.981242,1.49322 1.800288,1.09911 1.109752,-0.53395 1.395945,-2.19764 1.39426,-3.28969 -0.0041,-2.67006 -1.897081,-6.50736 -5.044974,-6.07886"
|
||||
id="path14" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 81.65895,149.35674 v -0.30278 h 0.787228 v -0.81953 h 0.294706 v 0.81953 h 0.771081 v 0.30278 h -0.771081 v 0.80337 h -0.294706 v -0.80337 z"
|
||||
id="path15"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 83.782802,149.35674 v -0.30278 h 0.787231 v -0.81953 h 0.294707 v 0.81953 h 0.77108 v 0.30278 h -0.77108 v 0.80337 h -0.294707 v -0.80337 z"
|
||||
id="path16"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
d="m 164.85789,130.59556 c 0.4642,-0.42537 1.08982,-0.66203 1.62919,-1.08343 1.9002,-1.4847 5.14786,-4.48328 4.44823,-6.80658 -0.26492,-0.87983 -1.26145,-1.35951 -2.21547,-1.29658 -0.98523,0.0649 -1.98724,0.50977 -2.64007,0.84484 -0.6864,0.35231 -1.37265,0.32755 -1.59243,0.87281 -0.30817,0.76454 0.49873,1.79683 1.28659,1.69784 0.23602,-0.0295 0.4698,-0.14082 0.56812,-0.35185 0.21882,-0.46933 0.58753,-0.58023 1.34113,-0.93846 0.73235,-0.34812 1.52921,-0.50494 1.03038,0.7483 -0.71596,1.79868 -3.74234,3.95101 -5.65111,5.2911 0,0 -0.87845,0.57891 -1.09797,0.6564 -0.47551,0.16781 -0.91536,0.19794 -0.84393,0.67269 0.0807,0.5363 0.64891,1.04684 1.12086,1.12458 1.12086,0.18468 1.25286,0.0172 3.02378,0.34516 0.68608,0.12686 1.73627,0.72085 2.01516,0.71659 0.4288,-0.006 0.91785,-2e-4 1.19241,-0.36589 0.38604,-0.51416 0.0632,-1.40966 -0.46279,-1.70348 -0.7765,-0.43372 -2.62935,-0.31806 -3.15208,-0.42404"
|
||||
style="display:inline;fill:#ff2500;fill-opacity:1;stroke:none;stroke-width:0.384847"
|
||||
id="path1-4"
|
||||
inkscape:label="path2"
|
||||
sodipodi:nodetypes="csssssssssssssssssc" /><circle
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
id="path20"
|
||||
cx="88.551903"
|
||||
cy="148.34044"
|
||||
r="0.28118241" /><circle
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
id="circle21"
|
||||
cx="88.551903"
|
||||
cy="150.06178"
|
||||
r="0.28118241" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 86.654979,150.81969 v -3.2857 c 0.179844,0.0571 1.027671,0.55011 1.027671,1.63571 0,1.0856 -0.755414,1.60237 -1.027671,1.64999 z"
|
||||
id="path21"
|
||||
sodipodi:nodetypes="cczc" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 87.542772,148.61874 0.859248,-0.33398 0.05138,0.23408 -0.91634,0.3397 z"
|
||||
id="path22" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 87.548483,149.78059 0.776462,0.27976 0.102767,-0.18555 -0.853537,-0.35969 z"
|
||||
id="path23" /><path
|
||||
style="display:inline;fill:#000000;stroke-width:0.251618"
|
||||
d="m 53.365672,180.24507 c -0.3637,-0.24337 -0.722092,-0.77863 -0.78984,-1.17963 -0.09983,-0.59091 0.204006,-1.10636 1.297083,-2.20043 5.140978,-5.14565 11.697013,-7.92364 23.168383,-9.81711 0.56754,-0.0937 1.238338,-0.23174 1.490665,-0.30682 1.011859,-0.30107 2.325926,-0.97015 5.000265,-2.54594 2.479307,-1.46091 3.050796,-1.70859 3.942317,-1.70859 0.518171,0 1.150566,0.67347 1.150566,1.22529 0,0.425 -0.679012,1.52428 -1.185643,1.91949 -0.57421,0.44794 -1.656275,1.15781 -2.94583,1.9326 -2.280231,1.36999 -3.014427,1.68943 -5.388463,2.34435 -1.27004,0.35037 -4.122609,1.01365 -6.424451,1.4938 -6.325272,1.31945 -6.291838,1.31134 -7.489532,1.81791 -1.769123,0.74828 -4.248215,2.15803 -7.127375,4.05307 -1.251238,0.82355 -1.316194,0.87715 -1.660467,1.37023 -0.51091,0.73176 -1.212354,1.44725 -1.616051,1.64842 -0.508953,0.25361 -0.996853,0.23763 -1.421627,-0.0466 z m -12.67358,-15.16209 c -1.117114,-0.29682 -1.582673,-0.72112 -1.636159,-1.49113 -0.01411,-0.20337 -0.08617,-0.54929 -0.160079,-0.76872 -0.07391,-0.21941 -0.134398,-0.53487 -0.134398,-0.70099 0,-0.61695 2.410337,-8.2439 3.713963,-11.75198 3.193966,-8.59503 6.760455,-15.28845 11.227138,-21.07057 3.000239,-3.88379 6.730729,-7.60101 10.390169,-10.3532 1.484468,-1.11645 2.957235,-1.93293 3.905921,-2.16542 0.712713,-0.17466 1.633772,-0.11481 2.150608,0.13975 0.218773,0.10778 0.523051,0.31574 0.67617,0.46219 0.312953,0.29934 0.3976,0.61273 0.343077,1.27018 -0.04907,0.5917 -0.25443,0.81335 -1.568046,1.69235 -0.629278,0.42108 -1.886286,1.35259 -2.793347,2.07005 -2.170567,1.71681 -3.189387,2.46922 -4.678307,3.45496 -1.150216,0.76149 -1.306538,0.89075 -2.365342,1.95583 -1.698584,1.70864 -4.618708,5.28287 -5.389113,6.59626 -1.828972,3.11804 -4.78794,9.6032 -6.91187,15.14872 -1.798512,4.69589 -3.846964,10.85701 -4.247495,12.77525 -0.344636,1.65049 -0.602466,2.23034 -1.167259,2.62515 -0.357651,0.24998 -0.721358,0.27984 -1.355631,0.11132 z m 20.716887,-20.76104 c -0.683356,-0.36433 -1.104849,-1.1204 -0.983924,-1.76497 0.05627,-0.29992 0.54589,-1.0378 1.243028,-1.87329 0.699338,-0.83811 3.395984,-3.54431 4.32199,-4.33732 5.249523,-4.4955 11.27839,-7.69801 18.274464,-9.70734 3.519236,-1.01076 5.446721,-1.15198 7.289115,-0.53399 0.676845,0.22703 0.986378,0.41335 1.240742,0.74684 0.610689,0.80066 0.346547,1.87808 -0.575798,2.34864 -0.434322,0.22155 -1.334341,0.4329 -4.661064,1.09445 -8.719062,1.73387 -11.376528,2.63789 -16.108419,5.47979 -1.234418,0.74136 -3.203445,2.2573 -4.93395,3.79859 -1.060656,0.94467 -1.416377,1.36021 -1.993509,2.32877 -0.658285,1.10475 -0.91811,1.48204 -1.286545,1.86821 -0.58619,0.6144 -1.302525,0.83079 -1.82613,0.55162 z m -4.866609,-1.8552 c -0.169358,-0.0598 -0.441793,-0.24795 -0.643122,-0.44412 -0.393278,-0.38317 -0.535787,-0.75247 -0.464232,-1.20299 0.125276,-0.7887 1.684629,-3.43102 3.301847,-5.59497 4.280257,-5.7273 10.433175,-10.52319 17.539062,-13.67083 2.257142,-0.99983 3.606682,-1.36208 5.092658,-1.367 1.551331,-0.005 2.533355,0.27242 3.053214,0.86301 0.700352,0.79565 0.711968,1.62161 0.03125,2.22082 -0.386196,0.33993 -1.209978,0.66386 -4.58236,1.80187 -8.015835,2.70495 -10.715836,4.06305 -14.717787,7.40307 -1.428546,1.19226 -3.325785,3.23175 -4.724883,5.07912 -0.630645,0.83273 -0.860401,1.26441 -1.275526,2.39667 -0.573656,1.56462 -0.972669,2.18868 -1.580271,2.47163 -0.386663,0.18004 -0.616285,0.18979 -1.02984,0.0437 z"
|
||||
id="path1"
|
||||
sodipodi:nodetypes="sssssssssssssssssscssssssssssssssssssssscssssssssssssssssssssssss" /><path
|
||||
style="display:inline;fill:#000000"
|
||||
d="m 133.48506,160.85705 c -1.47006,-0.34869 -2.86219,-1.46379 -3.53601,-2.83237 -0.53009,-1.07667 -0.6102,-1.73748 -0.61653,-3.78777 -0.011,-3.55286 1.28597,-6.9802 3.99822,-10.78446 3.43411,-4.81674 7.24916,-6.89675 9.52931,-5.1955 1.72479,1.2869 2.67857,4.71416 1.81712,6.52955 -0.91147,1.92077 -2.00698,1.48885 -2.77637,-1.09461 -0.2958,-0.99324 -0.76382,-2.01041 -1.04004,-2.2604 -1.06699,-0.9656 -3.02778,0.57303 -5.16237,4.05092 -2.47566,4.03359 -3.69767,8.15661 -3.01852,10.18444 0.54006,1.61256 1.47424,2.14444 3.73914,2.12893 2.12704,-0.0146 3.80866,-0.64763 6.67945,-2.51452 1.66456,-1.08247 2.6727,-1.3143 2.91942,-0.67136 0.40619,1.05851 -1.98505,3.43599 -4.97282,4.94421 -2.71974,1.37292 -5.35218,1.82661 -7.56,1.30294 z m -26.78525,-0.34019 c -1.00102,-0.4946 -2.07206,-2.89401 -2.37957,-5.33083 -0.14531,-1.15147 -0.29901,-2.12839 -0.34156,-2.17094 -0.0425,-0.0425 -0.6917,0.63471 -1.44256,1.50503 -5.097966,5.90905 -10.482428,7.32464 -12.29287,3.23184 -1.649103,-3.72807 1.189051,-10.83392 6.372938,-15.95586 2.290109,-2.26273 4.183682,-3.38708 6.083252,-3.61206 1.87581,-0.22216 2.58127,0.036 3.3272,1.21764 0.43316,0.68618 0.91266,1.08745 1.43709,1.20263 1.44053,0.3164 1.4918,0.5906 0.83147,4.44616 -0.77497,4.52496 -0.95582,7.82865 -0.5391,9.8479 0.26514,1.28476 0.52698,1.77788 1.37305,2.58583 1.26224,1.20536 1.25691,1.90371 -0.0211,2.76289 -1.01949,0.68539 -1.46589,0.7354 -2.40826,0.26977 z m -10.504047,-4.06394 c 2.39178,-1.21409 6.010807,-5.18201 7.530037,-8.25596 0.84799,-1.7158 0.96989,-2.20587 0.97911,-3.93623 0.009,-1.76456 -0.0564,-2.03067 -0.6141,-2.48242 -0.34354,-0.27829 -0.91383,-0.50598 -1.26731,-0.50598 -2.55868,0 -7.424923,5.64575 -9.066579,10.51894 -1.294302,3.84207 -0.172132,5.98701 2.438842,4.66165 z m 20.405737,3.87902 c -1.50995,-0.76805 -2.28207,-2.23504 -2.43136,-4.61949 -0.0912,-1.45637 0.0947,-2.89929 0.83642,-6.49387 1.31879,-6.39083 1.39459,-5.96188 -1.05348,-5.96188 -1.79007,0 -2.06198,-0.0676 -2.51357,-0.62462 -0.57501,-0.7093 -0.65793,-1.63152 -0.18886,-2.10059 0.20399,-0.20399 1.24978,-0.3175 2.92529,-0.3175 h 2.60779 l 0.49503,-1.12448 c 0.27227,-0.61846 0.80837,-2.36434 1.19133,-3.87972 0.93274,-3.69084 1.24255,-4.25731 2.32558,-4.25216 0.99699,0.005 1.32698,0.18687 1.73146,0.95566 0.23837,0.45307 0.10873,1.24024 -0.66474,4.03611 -0.52847,1.91029 -0.90529,3.52883 -0.83737,3.59675 0.0679,0.0679 1.20789,0.002 2.53328,-0.14556 1.32538,-0.14798 3.28341,-0.23385 4.35117,-0.19084 l 1.94138,0.0782 0.0795,0.94868 c 0.0522,0.62233 -0.0652,1.06877 -0.34106,1.29774 -0.23669,0.19645 -1.87597,0.49966 -3.74941,0.69353 -4.15959,0.43044 -5.47316,0.62595 -5.87528,0.87448 -0.38262,0.23647 -2.08696,7.65943 -2.31923,10.10102 -0.17528,1.84246 0.15441,3.38458 0.84635,3.95884 0.56488,0.46881 2.24338,0.39367 3.28943,-0.14727 0.49891,-0.258 1.66261,-1.04814 2.58598,-1.75587 1.71946,-1.31789 2.60511,-1.59187 2.8747,-0.88931 0.31079,0.80989 -0.24712,1.89088 -1.71559,3.3241 -2.85613,2.78757 -6.50841,3.86714 -8.92476,2.63804 z m 31.63789,-0.2742 c -0.29104,-0.29104 -0.52916,-0.76168 -0.52916,-1.04587 0,-0.2842 0.40859,-2.75474 0.90798,-5.49011 1.14588,-6.27647 2.06795,-12.24512 2.93464,-18.99631 0.79357,-6.18156 1.28854,-7.61865 2.67041,-7.75318 0.6526,-0.0635 0.96978,0.0924 1.52135,0.7479 1.14432,1.35994 0.92382,3.48988 -1.30042,12.56153 -1.19529,4.87502 -2.76521,12.47087 -2.76521,13.37907 0,0.67095 0.58017,0.0743 1.46322,-1.50471 1.77764,-3.17873 4.68194,-7.30062 6.31849,-8.96744 2.7637,-2.81483 5.25631,-3.57476 6.57703,-2.00518 0.7946,0.94434 1.09911,2.12146 1.64895,6.3743 0.6711,5.19068 1.02259,6.40843 2.52592,8.75117 0.92415,1.44017 0.94813,1.66501 0.2518,2.36133 -0.76353,0.76353 -2.14817,0.69113 -3.1663,-0.16557 -1.5783,-1.32805 -2.14482,-3.12236 -2.66271,-8.43339 -0.33195,-3.40418 -0.45519,-4.02701 -0.95544,-4.82864 -1.22199,-1.9582 -4.06707,1.17361 -9.63303,10.60387 -2.31481,3.92193 -3.2163,4.9404 -4.37293,4.9404 -0.55264,0 -1.1116,-0.20618 -1.43459,-0.52917 z"
|
||||
id="path2"
|
||||
sodipodi:nodetypes="ssssssscsssssssssssssssssssssssssssssssssssscsscssssscsssssssssssssssssssscsssssssssss" /></g></svg>
|
Before Width: | Height: | Size: 23 KiB |
@@ -1,88 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="132.82083mm"
|
||||
height="64.029167mm"
|
||||
viewBox="0 0 132.82083 64.029167"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.4-beta (62f545ba5e, 2024-04-22)"
|
||||
sodipodi:docname="catch2-logo.svg"
|
||||
xml:space="preserve"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="false"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="2.1362654"
|
||||
inkscape:cx="252.77758"
|
||||
inkscape:cy="71.854367"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1411"
|
||||
inkscape:window-x="-9"
|
||||
inkscape:window-y="-6"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" /><defs
|
||||
id="defs1" /><g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(-38.629169,-116.41666)"
|
||||
style="display:inline;opacity:1"><path
|
||||
style="display:inline;fill:#ff2500;fill-opacity:1;stroke:none;stroke-width:0.250889"
|
||||
d="m 81.146047,150.57948 c 0.691236,0.96533 2.035742,1.27689 3.166324,1.10031 0.590818,-0.0922 2.217659,-0.60588 2.217659,-1.07918 v -3.36013 c 0,-0.069 -1.165318,-1.34371 -3.547531,-1.01206 -1.952335,0.21432 -3.085228,2.60709 -1.836452,4.35106 z"
|
||||
id="path19" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.250889"
|
||||
d="m 81.325217,134.80993 c -2.562928,0.34888 -4.598977,2.14544 -6.250134,4.02102 -3.393658,3.85496 -6.461012,8.93964 -6.691599,14.2056 -0.06234,1.42355 0.01809,2.8981 0.508204,4.2484 1.613307,4.44467 6.794341,4.64804 10.641236,3.40234 2.417384,-0.78278 4.907188,-2.27103 6.704505,-4.06615 0.638393,-0.63761 1.628076,-1.70902 1.19425,-2.71876 -0.202704,-0.4718 -0.782987,-0.44442 -1.19425,-0.31091 -0.947618,0.30765 -1.76984,0.95715 -2.588867,1.50289 -2.156496,1.43698 -4.662182,2.65628 -7.301941,2.65526 -1.333335,-5e-4 -2.776062,-0.38616 -3.581718,-1.52678 -0.875345,-1.23926 -0.695536,-2.90697 -0.450943,-4.31477 0.611778,-3.52124 2.533483,-7.18254 4.654937,-10.02357 0.873192,-1.16937 2.144513,-2.99169 3.758888,-3.11367 0.670659,-0.0506 1.116987,0.43373 1.408297,0.98948 0.545003,1.03973 0.573135,2.25152 1.039561,3.31906 0.291107,0.66626 0.981242,1.49322 1.800288,1.09911 1.109752,-0.53395 1.395945,-2.19764 1.39426,-3.28969 -0.0041,-2.67006 -1.897081,-6.50736 -5.044974,-6.07886"
|
||||
id="path14" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 81.850807,149.10732 v -0.30278 h 0.787228 v -0.81953 h 0.294706 v 0.81953 h 0.771081 v 0.30278 h -0.771081 v 0.80337 h -0.294706 v -0.80337 z"
|
||||
id="path15"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 83.974659,149.10732 v -0.30278 h 0.787231 v -0.81953 h 0.294707 v 0.81953 h 0.77108 v 0.30278 h -0.77108 v 0.80337 H 84.76189 v -0.80337 z"
|
||||
id="path16"
|
||||
sodipodi:nodetypes="ccccccccccccc" /><path
|
||||
d="m 165.04975,130.34614 c 0.4642,-0.42537 1.08982,-0.66203 1.62919,-1.08343 1.9002,-1.4847 5.14786,-4.48328 4.44823,-6.80658 -0.26492,-0.87983 -1.26145,-1.35951 -2.21547,-1.29658 -0.98523,0.0649 -1.98724,0.50977 -2.64007,0.84484 -0.6864,0.35231 -1.37265,0.32755 -1.59243,0.87281 -0.30817,0.76454 0.49873,1.79683 1.28659,1.69784 0.23602,-0.0295 0.4698,-0.14082 0.56812,-0.35185 0.21882,-0.46933 0.58753,-0.58023 1.34113,-0.93846 0.73235,-0.34812 1.52921,-0.50494 1.03038,0.7483 -0.71596,1.79868 -3.74234,3.95101 -5.65111,5.2911 0,0 -0.87845,0.57891 -1.09797,0.6564 -0.47551,0.16781 -0.91536,0.19794 -0.84393,0.67269 0.0807,0.5363 0.64891,1.04684 1.12086,1.12458 1.12086,0.18468 1.25286,0.0172 3.02378,0.34516 0.68608,0.12686 1.73627,0.72085 2.01516,0.71659 0.4288,-0.006 0.91785,-2e-4 1.19241,-0.36589 0.38604,-0.51416 0.0632,-1.40966 -0.46279,-1.70348 -0.7765,-0.43372 -2.62935,-0.31806 -3.15208,-0.42404"
|
||||
style="display:inline;fill:#ff2500;fill-opacity:1;stroke:none;stroke-width:0.384847"
|
||||
id="path1-4"
|
||||
inkscape:label="path2"
|
||||
sodipodi:nodetypes="csssssssssssssssssc" /><circle
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
id="path20"
|
||||
cx="88.743759"
|
||||
cy="148.09102"
|
||||
r="0.28118241" /><circle
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
id="circle21"
|
||||
cx="88.743759"
|
||||
cy="149.81236"
|
||||
r="0.28118241" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 86.846836,150.57027 v -3.2857 c 0.179844,0.0571 1.027671,0.55011 1.027671,1.63571 0,1.0856 -0.755414,1.60237 -1.027671,1.64999 z"
|
||||
id="path21"
|
||||
sodipodi:nodetypes="cczc" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 87.734629,148.36932 0.859248,-0.33398 0.05138,0.23408 -0.91634,0.3397 z"
|
||||
id="path22" /><path
|
||||
style="display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.0366197;stroke-linecap:round"
|
||||
d="m 87.74034,149.53117 0.776462,0.27976 0.102767,-0.18555 -0.853537,-0.35969 z"
|
||||
id="path23" /><path
|
||||
style="display:inline;fill:#000000;stroke-width:0.251618"
|
||||
d="m 53.557529,179.99565 c -0.3637,-0.24337 -0.722092,-0.77863 -0.78984,-1.17963 -0.09983,-0.59091 0.204006,-1.10636 1.297083,-2.20043 5.140978,-5.14565 11.697013,-7.92364 23.168383,-9.81711 0.56754,-0.0937 1.238338,-0.23174 1.490665,-0.30682 1.011859,-0.30107 2.325926,-0.97015 5.000265,-2.54594 2.479307,-1.46091 3.050796,-1.70859 3.942317,-1.70859 0.518171,0 1.150566,0.67347 1.150566,1.22529 0,0.425 -0.679012,1.52428 -1.185643,1.91949 -0.57421,0.44794 -1.656275,1.15781 -2.94583,1.9326 -2.280231,1.36999 -3.014427,1.68943 -5.388463,2.34435 -1.27004,0.35037 -4.122609,1.01365 -6.424451,1.4938 -6.325272,1.31945 -6.291838,1.31134 -7.489532,1.81791 -1.769123,0.74828 -4.248215,2.15803 -7.127375,4.05307 -1.251238,0.82355 -1.316194,0.87715 -1.660467,1.37023 -0.51091,0.73176 -1.212354,1.44725 -1.616051,1.64842 -0.508953,0.25361 -0.996853,0.23763 -1.421627,-0.0466 z m -12.67358,-15.16209 c -1.117114,-0.29682 -1.582673,-0.72112 -1.636159,-1.49113 -0.01411,-0.20337 -0.08617,-0.54929 -0.160079,-0.76872 -0.07391,-0.21941 -0.134398,-0.53487 -0.134398,-0.70099 0,-0.61695 2.410337,-8.2439 3.713963,-11.75198 3.193966,-8.59503 6.760455,-15.28845 11.227138,-21.07057 3.000239,-3.88379 6.730729,-7.60101 10.390169,-10.3532 1.484468,-1.11645 2.957235,-1.93293 3.905921,-2.16542 0.712713,-0.17466 1.633772,-0.11481 2.150608,0.13975 0.218773,0.10778 0.523051,0.31574 0.67617,0.46219 0.312953,0.29934 0.3976,0.61273 0.343077,1.27018 -0.04907,0.5917 -0.25443,0.81335 -1.568046,1.69235 -0.629278,0.42108 -1.886286,1.35259 -2.793347,2.07005 -2.170567,1.71681 -3.189387,2.46922 -4.678307,3.45496 -1.150216,0.76149 -1.306538,0.89075 -2.365342,1.95583 -1.698584,1.70864 -4.618708,5.28287 -5.389113,6.59626 -1.828972,3.11804 -4.78794,9.6032 -6.91187,15.14872 -1.798512,4.69589 -3.846964,10.85701 -4.247495,12.77525 -0.344636,1.65049 -0.602466,2.23034 -1.167259,2.62515 -0.357651,0.24998 -0.721358,0.27984 -1.355631,0.11132 z m 20.716887,-20.76104 c -0.683356,-0.36433 -1.104849,-1.1204 -0.983924,-1.76497 0.05627,-0.29992 0.54589,-1.0378 1.243028,-1.87329 0.699338,-0.83811 3.395984,-3.54431 4.32199,-4.33732 5.249523,-4.4955 11.27839,-7.69801 18.274464,-9.70734 3.519236,-1.01076 5.446721,-1.15198 7.289115,-0.53399 0.676845,0.22703 0.986378,0.41335 1.240742,0.74684 0.610689,0.80066 0.346547,1.87808 -0.575798,2.34864 -0.434322,0.22155 -1.334341,0.4329 -4.661064,1.09445 -8.719062,1.73387 -11.376528,2.63789 -16.108419,5.47979 -1.234418,0.74136 -3.203445,2.2573 -4.93395,3.79859 -1.060656,0.94467 -1.416377,1.36021 -1.993509,2.32877 -0.658285,1.10475 -0.91811,1.48204 -1.286545,1.86821 -0.58619,0.6144 -1.302525,0.83079 -1.82613,0.55162 z m -4.866609,-1.8552 c -0.169358,-0.0598 -0.441793,-0.24795 -0.643122,-0.44412 -0.393278,-0.38317 -0.535787,-0.75247 -0.464232,-1.20299 0.125276,-0.7887 1.684629,-3.43102 3.301847,-5.59497 4.280257,-5.7273 10.433175,-10.52319 17.539062,-13.67083 2.257142,-0.99983 3.606682,-1.36208 5.092658,-1.367 1.551331,-0.005 2.533355,0.27242 3.053214,0.86301 0.700352,0.79565 0.711968,1.62161 0.03125,2.22082 -0.386196,0.33993 -1.209978,0.66386 -4.58236,1.80187 -8.015835,2.70495 -10.715836,4.06305 -14.717787,7.40307 -1.428546,1.19226 -3.325785,3.23175 -4.724883,5.07912 -0.630645,0.83273 -0.860401,1.26441 -1.275526,2.39667 -0.573656,1.56462 -0.972669,2.18868 -1.580271,2.47163 -0.386663,0.18004 -0.616285,0.18979 -1.02984,0.0437 z"
|
||||
id="path1"
|
||||
sodipodi:nodetypes="sssssssssssssssssscssssssssssssssssssssscssssssssssssssssssssssss" /><path
|
||||
style="fill:#000000"
|
||||
d="m 95.04775,44.190968 c -1.470062,-0.348685 -2.86219,-1.463789 -3.53601,-2.832367 -0.530096,-1.076667 -0.610204,-1.737477 -0.616532,-3.787771 -0.01096,-3.55286 1.285971,-6.980203 3.998224,-10.784456 3.434108,-4.81674 7.249158,-6.896758 9.529308,-5.195505 1.72479,1.286898 2.67857,4.714164 1.81712,6.529548 -0.91147,1.920769 -2.00698,1.488854 -2.77637,-1.094605 -0.2958,-0.993237 -0.76382,-2.010416 -1.04004,-2.260399 -1.06699,-0.965607 -3.02778,0.573029 -5.162374,4.05092 -2.47566,4.033589 -3.697664,8.156608 -3.01852,10.184435 0.540066,1.612562 1.474242,2.144447 3.739143,2.12893 2.127041,-0.01457 3.808661,-0.647627 6.679451,-2.514514 1.66456,-1.082469 2.6727,-1.314304 2.91942,-0.671359 0.40619,1.058506 -1.98505,3.435985 -4.97282,4.944207 -2.719738,1.372918 -5.35218,1.826609 -7.56,1.302936 z M 68.262499,43.850784 c -1.001018,-0.494607 -2.072065,-2.894018 -2.379571,-5.330829 -0.145306,-1.151471 -0.299007,-2.128397 -0.341557,-2.170948 -0.04255,-0.04255 -0.691704,0.634714 -1.442562,1.505034 -5.097967,5.90905 -10.482429,7.324644 -12.292871,3.231839 -1.649103,-3.72807 1.189051,-10.833924 6.372938,-15.955855 2.290109,-2.262738 4.183677,-3.387085 6.08325,-3.612061 1.875807,-0.222162 2.581271,0.03601 3.327199,1.217639 0.433165,0.686179 0.912665,1.087449 1.437088,1.202632 1.44053,0.316394 1.491808,0.590591 0.831478,4.446159 -0.774974,4.524958 -0.955828,7.828642 -0.539105,9.847894 0.265143,1.284765 0.526984,1.777882 1.373056,2.58583 1.262237,1.205362 1.25691,1.903716 -0.02107,2.762891 -1.019495,0.685396 -1.465899,0.735403 -2.408269,0.269775 z M 57.758451,39.78684 c 2.39178,-1.214093 6.010805,-5.182007 7.530034,-8.255959 0.847994,-1.715798 0.969897,-2.205874 0.979113,-3.93623 0.0094,-1.764565 -0.05643,-2.03067 -0.614098,-2.482417 -0.343543,-0.278293 -0.913833,-0.505987 -1.267311,-0.505987 -2.558681,0 -7.424924,5.645757 -9.06658,10.51894 -1.294302,3.842075 -0.172132,5.987013 2.438842,4.661653 z m 20.405739,3.879018 c -1.509951,-0.768049 -2.282068,-2.235036 -2.431367,-4.619485 -0.09119,-1.456372 0.09466,-2.899291 0.836427,-6.49387 1.318788,-6.390829 1.394584,-5.961881 -1.053485,-5.961881 -1.790069,0 -2.061979,-0.06757 -2.513567,-0.624624 -0.57501,-0.709301 -0.657928,-1.631522 -0.188865,-2.100585 0.203993,-0.203993 1.249787,-0.3175 2.925294,-0.3175 h 2.607794 l 0.495029,-1.124479 c 0.272266,-0.618463 0.808364,-2.364341 1.191329,-3.879728 0.932738,-3.690834 1.242549,-4.257301 2.325577,-4.252158 0.99699,0.0047 1.326986,0.186873 1.731464,0.955664 0.23837,0.453069 0.108725,1.240237 -0.664738,4.036104 -0.528474,1.910294 -0.905292,3.528832 -0.837374,3.596751 0.06792,0.06792 1.207892,0.0024 2.533275,-0.145559 1.325383,-0.147975 3.28341,-0.233853 4.351172,-0.190841 l 1.941386,0.07821 0.07952,0.948687 c 0.05217,0.622322 -0.06516,1.068768 -0.341058,1.29774 -0.236699,0.196443 -1.875978,0.499659 -3.749412,0.693525 -4.159592,0.430442 -5.473168,0.625955 -5.875288,0.874479 -0.382617,0.23647 -2.086955,7.659434 -2.319229,10.101025 -0.175277,1.842453 0.154409,3.384573 0.846351,3.958834 0.564887,0.468815 2.243378,0.393671 3.289429,-0.147263 0.498916,-0.258 1.662611,-1.048142 2.585987,-1.755871 1.719461,-1.317895 2.605103,-1.591876 2.874701,-0.889315 0.310783,0.809889 -0.247128,1.890887 -1.715596,3.324104 -2.856133,2.787571 -6.508412,3.867137 -8.92476,2.638041 z m 31.63789,-0.274194 c -0.29104,-0.291042 -0.52916,-0.761687 -0.52916,-1.045878 0,-0.284191 0.40859,-2.754738 0.90798,-5.490105 1.14588,-6.276471 2.06795,-12.245122 2.93464,-18.996309 0.79357,-6.181563 1.28854,-7.618653 2.67041,-7.753186 0.6526,-0.06353 0.96978,0.09239 1.52135,0.747904 1.14432,1.359943 0.92382,3.489885 -1.30042,12.561532 -1.19529,4.87502 -2.76521,12.47087 -2.76521,13.379072 0,0.670944 0.58017,0.07431 1.46322,-1.504712 1.77764,-3.17873 4.68194,-7.300625 6.31849,-8.967446 2.7637,-2.814823 5.25631,-3.574759 6.57703,-2.005173 0.7946,0.944334 1.09911,2.121456 1.64895,6.3743 0.6711,5.190681 1.02259,6.408426 2.52592,8.751165 0.92415,1.440168 0.94813,1.66501 0.2518,2.361335 -0.76353,0.763532 -2.14817,0.691125 -3.1663,-0.165573 -1.5783,-1.32805 -2.14482,-3.122356 -2.66271,-8.433385 -0.33195,-3.404186 -0.45519,-4.027014 -0.95544,-4.828646 -1.22199,-1.958203 -4.06707,1.173608 -9.63303,10.60387 -2.31481,3.921927 -3.2163,4.940401 -4.37293,4.940401 -0.55264,0 -1.1116,-0.206177 -1.43459,-0.529166 z"
|
||||
id="path2"
|
||||
sodipodi:nodetypes="ssssssscsssssssssssssssssssssssssssssssssssscsscssssscsssssssssssssssssssscsssssssssss"
|
||||
transform="translate(38.629169,116.41666)" /></g></svg>
|
Before Width: | Height: | Size: 14 KiB |
@@ -4,41 +4,38 @@
|
||||
To get the most out of Catch2, start with the [tutorial](tutorial.md#top).
|
||||
Once you're up and running consider the following reference material.
|
||||
|
||||
**Writing tests:**
|
||||
Writing tests:
|
||||
* [Assertion macros](assertions.md#top)
|
||||
* [Matchers (asserting complex properties)](matchers.md#top)
|
||||
* [Comparing floating point numbers](comparing-floating-point-numbers.md#top)
|
||||
* [Matchers](matchers.md#top)
|
||||
* [Logging macros](logging.md#top)
|
||||
* [Test cases and sections](test-cases-and-sections.md#top)
|
||||
* [Test fixtures](test-fixtures.md#top)
|
||||
* [Explicitly skipping, passing, and failing tests at runtime](skipping-passing-failing.md#top)
|
||||
* [Reporters (output customization)](reporters.md#top)
|
||||
* [Reporters](reporters.md#top)
|
||||
* [Event Listeners](event-listeners.md#top)
|
||||
* [Data Generators (value parameterized tests)](generators.md#top)
|
||||
* [Data Generators](generators.md#top)
|
||||
* [Other macros](other-macros.md#top)
|
||||
* [Micro benchmarking](benchmarks.md#top)
|
||||
|
||||
**Fine tuning:**
|
||||
Fine tuning:
|
||||
* [Supplying your own main()](own-main.md#top)
|
||||
* [Compile-time configuration](configuration.md#top)
|
||||
* [String Conversions](tostring.md#top)
|
||||
|
||||
**Running:**
|
||||
Running:
|
||||
* [Command line](command-line.md#top)
|
||||
|
||||
**Odds and ends:**
|
||||
* [Frequently Asked Questions (FAQ)](faq.md#top)
|
||||
* [Best practices and other tips](usage-tips.md#top)
|
||||
Odds and ends:
|
||||
* [CMake integration](cmake-integration.md#top)
|
||||
* [Tooling integration (CI, test runners, other)](ci-and-misc.md#top)
|
||||
* [Known limitations](limitations.md#top)
|
||||
* [Thread safety in Catch2](thread-safety.md#top)
|
||||
* [CI and other miscellaneous pieces](ci-and-misc.md#top)
|
||||
|
||||
**Other:**
|
||||
* [Why Catch2?](why-catch.md#top)
|
||||
* [Migrating from v2 to v3](migrate-v2-to-v3.md#top)
|
||||
* [Open Source Projects using Catch2](opensource-users.md#top)
|
||||
* [Commercial Projects using Catch2](commercial-users.md#top)
|
||||
FAQ:
|
||||
* [Why are my tests slow to compile?](slow-compiles.md#top)
|
||||
* [Known limitations](limitations.md#top)
|
||||
|
||||
Other:
|
||||
* [Why Catch?](why-catch.md#top)
|
||||
* [Open Source Projects using Catch](opensource-users.md#top)
|
||||
* [Commercial Projects using Catch](commercial-users.md#top)
|
||||
* [Contributing](contributing.md#top)
|
||||
* [Release Notes](release-notes.md#top)
|
||||
* [Deprecations and incoming changes](deprecations.md#top)
|
||||
|
@@ -3,7 +3,6 @@
|
||||
|
||||
**Contents**<br>
|
||||
[Natural Expressions](#natural-expressions)<br>
|
||||
[Floating point comparisons](#floating-point-comparisons)<br>
|
||||
[Exceptions](#exceptions)<br>
|
||||
[Matcher expressions](#matcher-expressions)<br>
|
||||
[Thread Safety](#thread-safety)<br>
|
||||
@@ -20,7 +19,7 @@ Most of these macros come in two forms:
|
||||
The ```REQUIRE``` family of macros tests an expression and aborts the test case if it fails.
|
||||
The ```CHECK``` family are equivalent but execution continues in the same test case even if the assertion fails. This is useful if you have a series of essentially orthogonal assertions and it is useful to see all the results rather than stopping at the first failure.
|
||||
|
||||
* **REQUIRE(** _expression_ **)** and
|
||||
* **REQUIRE(** _expression_ **)** and
|
||||
* **CHECK(** _expression_ **)**
|
||||
|
||||
Evaluates the expression and records the result. If an exception is thrown, it is caught, reported, and counted as a failure. These are the macros you will use most of the time.
|
||||
@@ -32,85 +31,105 @@ CHECK( thisReturnsTrue() );
|
||||
REQUIRE( i == 42 );
|
||||
```
|
||||
|
||||
Expressions prefixed with `!` cannot be decomposed. If you have a type
|
||||
that is convertible to bool and you want to assert that it evaluates to
|
||||
false, use the two forms below:
|
||||
|
||||
|
||||
* **REQUIRE_FALSE(** _expression_ **)** and
|
||||
* **REQUIRE_FALSE(** _expression_ **)** and
|
||||
* **CHECK_FALSE(** _expression_ **)**
|
||||
|
||||
Note that there is no reason to use these forms for plain bool variables,
|
||||
because there is no added value in decomposing them.
|
||||
Evaluates the expression and records the _logical NOT_ of the result. If an exception is thrown it is caught, reported, and counted as a failure.
|
||||
(these forms exist as a workaround for the fact that ! prefixed expressions cannot be decomposed).
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
Status ret = someFunction();
|
||||
REQUIRE_FALSE(ret); // ret must evaluate to false, and Catch2 will print
|
||||
// out the value of ret if possibly
|
||||
```
|
||||
REQUIRE_FALSE( thisReturnsFalse() );
|
||||
```
|
||||
|
||||
Do note that "overly complex" expressions cannot be decomposed and thus will not compile. This is done partly for practical reasons (to keep the underlying expression template machinery to minimum) and partly for philosophical reasons (assertions should be simple and deterministic).
|
||||
|
||||
### Other limitations
|
||||
|
||||
Note that expressions containing either of the binary logical operators,
|
||||
`&&` or `||`, cannot be decomposed and will not compile. The reason behind
|
||||
this is that it is impossible to overload `&&` and `||` in a way that
|
||||
keeps their short-circuiting semantics, and expression decomposition
|
||||
relies on overloaded operators to work.
|
||||
|
||||
Simple example of an issue with overloading binary logical operators
|
||||
is a common pointer idiom, `p && p->foo == 2`. Using the built-in `&&`
|
||||
operator, `p` is only dereferenced if it is not null. With overloaded
|
||||
`&&`, `p` is always dereferenced, thus causing a segfault if
|
||||
`p == nullptr`.
|
||||
|
||||
If you want to test expression that contains `&&` or `||`, you have two
|
||||
options.
|
||||
|
||||
1) Enclose it in parentheses. Parentheses force evaluation of the expression
|
||||
before the expression decomposition can touch it, and thus it cannot
|
||||
be used.
|
||||
|
||||
2) Rewrite the expression. `REQUIRE(a == 1 && b == 2)` can always be split
|
||||
into `REQUIRE(a == 1); REQUIRE(b == 2);`. Alternatively, if this is a
|
||||
common pattern in your tests, think about using [Matchers](#matcher-expressions).
|
||||
instead. There is no simple rewrite rule for `||`, but I generally
|
||||
believe that if you have `||` in your test expression, you should rethink
|
||||
your tests.
|
||||
Examples:
|
||||
* `CHECK(a == 1 && b == 2);`
|
||||
This expression is too complex because of the `&&` operator. If you want to check that 2 or more properties hold, you can either put the expression into parenthesis, which stops decomposition from working, or you need to decompose the expression into two assertions: `CHECK( a == 1 ); CHECK( b == 2);`
|
||||
* `CHECK( a == 2 || b == 1 );`
|
||||
This expression is too complex because of the `||` operator. If you want to check that one of several properties hold, you can put the expression into parenthesis (unlike with `&&`, expression decomposition into several `CHECK`s is not possible).
|
||||
|
||||
|
||||
## Floating point comparisons
|
||||
### Floating point comparisons
|
||||
|
||||
Comparing floating point numbers is complex, and [so it has its own
|
||||
documentation page](comparing-floating-point-numbers.md#top).
|
||||
When comparing floating point numbers - especially if at least one of them has been computed - great care must be taken to allow for rounding errors and inexact representations.
|
||||
|
||||
Catch provides a way to perform tolerant comparisons of floating point values through use of a wrapper class called `Approx`. `Approx` can be used on either side of a comparison expression. It overloads the comparisons operators to take a tolerance into account. Here's a simple example:
|
||||
|
||||
```cpp
|
||||
REQUIRE( performComputation() == Approx( 2.1 ) );
|
||||
```
|
||||
|
||||
Catch also provides a user-defined literal for `Approx`; `_a`. It resides in
|
||||
the `Catch::literals` namespace and can be used like so:
|
||||
```cpp
|
||||
using namespace Catch::literals;
|
||||
REQUIRE( performComputation() == 2.1_a );
|
||||
```
|
||||
|
||||
`Approx` is constructed with defaults that should cover most simple cases.
|
||||
For the more complex cases, `Approx` provides 3 customization points:
|
||||
|
||||
* __epsilon__ - epsilon serves to set the coefficient by which a result
|
||||
can differ from `Approx`'s value before it is rejected.
|
||||
_By default set to `std::numeric_limits<float>::epsilon()*100`._
|
||||
* __margin__ - margin serves to set the the absolute value by which
|
||||
a result can differ from `Approx`'s value before it is rejected.
|
||||
_By default set to `0.0`._
|
||||
* __scale__ - scale is used to change the magnitude of `Approx` for relative check.
|
||||
_By default set to `0.0`._
|
||||
|
||||
#### epsilon example
|
||||
```cpp
|
||||
Approx target = Approx(100).epsilon(0.01);
|
||||
100.0 == target; // Obviously true
|
||||
200.0 == target; // Obviously still false
|
||||
100.5 == target; // True, because we set target to allow up to 1% difference
|
||||
```
|
||||
|
||||
#### margin example
|
||||
```cpp
|
||||
Approx target = Approx(100).margin(5);
|
||||
100.0 == target; // Obviously true
|
||||
200.0 == target; // Obviously still false
|
||||
104.0 == target; // True, because we set target to allow absolute difference of at most 5
|
||||
```
|
||||
|
||||
#### scale
|
||||
Scale can be useful if the computation leading to the result worked
|
||||
on different scale than is used by the results. Since allowed difference
|
||||
between Approx's value and compared value is based primarily on Approx's value
|
||||
(the allowed difference is computed as
|
||||
`(Approx::scale + Approx::value) * epsilon`), the resulting comparison could
|
||||
need rescaling to be correct.
|
||||
|
||||
|
||||
## Exceptions
|
||||
|
||||
* **REQUIRE_NOTHROW(** _expression_ **)** and
|
||||
* **REQUIRE_NOTHROW(** _expression_ **)** and
|
||||
* **CHECK_NOTHROW(** _expression_ **)**
|
||||
|
||||
Expects that no exception is thrown during evaluation of the expression.
|
||||
|
||||
* **REQUIRE_THROWS(** _expression_ **)** and
|
||||
* **REQUIRE_THROWS(** _expression_ **)** and
|
||||
* **CHECK_THROWS(** _expression_ **)**
|
||||
|
||||
Expects that an exception (of any type) is be thrown during evaluation of the expression.
|
||||
|
||||
* **REQUIRE_THROWS_AS(** _expression_, _exception type_ **)** and
|
||||
* **REQUIRE_THROWS_AS(** _expression_, _exception type_ **)** and
|
||||
* **CHECK_THROWS_AS(** _expression_, _exception type_ **)**
|
||||
|
||||
Expects that an exception of the _specified type_ is thrown during evaluation of the expression. Note that the _exception type_ is extended with `const&` and you should not include it yourself.
|
||||
|
||||
* **REQUIRE_THROWS_WITH(** _expression_, _string or string matcher_ **)** and
|
||||
* **REQUIRE_THROWS_WITH(** _expression_, _string or string matcher_ **)** and
|
||||
* **CHECK_THROWS_WITH(** _expression_, _string or string matcher_ **)**
|
||||
|
||||
Expects that an exception is thrown that, when converted to a string, matches the _string_ or _string matcher_ provided (see next section for Matchers).
|
||||
|
||||
e.g.
|
||||
```cpp
|
||||
REQUIRE_THROWS_WITH( openThePodBayDoors(), ContainsSubstring( "afraid" ) && ContainsSubstring( "can't do that" ) );
|
||||
REQUIRE_THROWS_WITH( openThePodBayDoors(), Contains( "afraid" ) && Contains( "can't do that" ) );
|
||||
REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
|
||||
```
|
||||
|
||||
@@ -139,8 +158,8 @@ REQUIRE_NOTHROW([&](){
|
||||
|
||||
To support Matchers a slightly different form is used. Matchers have [their own documentation](matchers.md#top).
|
||||
|
||||
* **REQUIRE_THAT(** _lhs_, _matcher expression_ **)** and
|
||||
* **CHECK_THAT(** _lhs_, _matcher expression_ **)**
|
||||
* **REQUIRE_THAT(** _lhs_, _matcher expression_ **)** and
|
||||
* **CHECK_THAT(** _lhs_, _matcher expression_ **)**
|
||||
|
||||
Matchers can be composed using `&&`, `||` and `!` operators.
|
||||
|
||||
|
@@ -1,7 +1,11 @@
|
||||
<a id="top"></a>
|
||||
# Authoring benchmarks
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 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
|
||||
always need to take care about various aspects. Understanding a few things about
|
||||
@@ -11,8 +15,7 @@ First off, let's go over some terminology that will be used throughout this
|
||||
guide.
|
||||
|
||||
- *User code*: user code is the code that the user provides to be measured.
|
||||
- *Run*: one run is one execution of the user code. Sometimes also referred
|
||||
to as an _iteration_.
|
||||
- *Run*: one run is one execution of the user code.
|
||||
- *Sample*: one sample is one data point obtained by measuring the time it takes
|
||||
to perform a certain number of runs. One sample can consist of more than one
|
||||
run if the clock available does not have enough resolution to accurately
|
||||
@@ -93,7 +96,7 @@ Fibonacci
|
||||
-------------------------------------------------------------------------------
|
||||
C:\path\to\Catch2\Benchmark.tests.cpp(10)
|
||||
...............................................................................
|
||||
benchmark name samples iterations est run time
|
||||
benchmark name samples iterations estimated
|
||||
mean low mean high mean
|
||||
std dev low std dev high std dev
|
||||
-------------------------------------------------------------------------------
|
||||
|
@@ -1,15 +1,14 @@
|
||||
<a id="top"></a>
|
||||
# Tooling integration (CI, test runners and so on)
|
||||
# CI and other odd pieces
|
||||
|
||||
**Contents**<br>
|
||||
[Continuous Integration systems](#continuous-integration-systems)<br>
|
||||
[Bazel test runner integration](#bazel-test-runner-integration)<br>
|
||||
[Other reporters](#other-reporters)<br>
|
||||
[Low-level tools](#low-level-tools)<br>
|
||||
[CMake](#cmake)<br>
|
||||
|
||||
This page talks about Catch2's integration with other related tooling,
|
||||
like Continuous Integration and 3rd party test runners.
|
||||
|
||||
This page talks about how Catch integrates with Continuous Integration
|
||||
Build Systems may refer to low-level tools, like CMake, or larger systems that run on servers, like Jenkins or TeamCity. This page will talk about both.
|
||||
|
||||
## Continuous Integration systems
|
||||
|
||||
@@ -18,9 +17,9 @@ Probably the most important aspect to using Catch with a build server is the use
|
||||
Two of these reporters are built in (XML and JUnit) and the third (TeamCity) is included as a separate header. It's possible that the other two may be split out in the future too - as that would make the core of Catch smaller for those that don't need them.
|
||||
|
||||
### XML Reporter
|
||||
```-r xml```
|
||||
```-r xml```
|
||||
|
||||
The XML Reporter writes in an XML format that is specific to Catch.
|
||||
The XML Reporter writes in an XML format that is specific to Catch.
|
||||
|
||||
The advantage of this format is that it corresponds well to the way Catch works (especially the more unusual features, such as nested sections) and is a fully streaming format - that is it writes output as it goes, without having to store up all its results before it can start writing.
|
||||
|
||||
@@ -35,6 +34,19 @@ The advantage of this format is that the JUnit Ant schema is widely understood b
|
||||
|
||||
The disadvantage is that this schema was designed to correspond to how JUnit works - and there is a significant mismatch with how Catch works. Additionally the format is not streamable (because opening elements hold counts of failed and passing tests as attributes) - so the whole test run must complete before it can be written.
|
||||
|
||||
## Other reporters
|
||||
Other reporters are not part of the single-header distribution and need
|
||||
to be downloaded and included separately. All reporters are stored in
|
||||
`single_include` directory in the git repository, and are named
|
||||
`catch_reporter_*.hpp`. For example, to use the TeamCity reporter you
|
||||
need to download `single_include/catch_reporter_teamcity.hpp` and include
|
||||
it after Catch itself.
|
||||
|
||||
```cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
#include "catch_reporter_teamcity.hpp"
|
||||
```
|
||||
|
||||
### TeamCity Reporter
|
||||
```-r teamcity```
|
||||
@@ -57,32 +69,22 @@ Because of the incremental nature of Catch's test suites and ability to run spec
|
||||
```-r sonarqube```
|
||||
[SonarQube Generic Test Data](https://docs.sonarqube.org/latest/analysis/generic-test/) XML format for tests metrics.
|
||||
|
||||
|
||||
## Bazel test runner integration
|
||||
|
||||
Catch2 understands some of the environment variables Bazel uses to control
|
||||
test execution. Specifically it understands
|
||||
|
||||
* JUnit output path via `XML_OUTPUT_FILE`
|
||||
* Test filtering via `TESTBRIDGE_TEST_ONLY`
|
||||
* Test sharding via `TEST_SHARD_INDEX`, `TEST_TOTAL_SHARDS`, and `TEST_SHARD_STATUS_FILE`
|
||||
|
||||
> Support for `XML_OUTPUT_FILE` was [introduced](https://github.com/catchorg/Catch2/pull/2399) in Catch2 3.0.1
|
||||
|
||||
> Support for `TESTBRIDGE_TEST_ONLY` and sharding was introduced in Catch2 3.2.0
|
||||
|
||||
This integration is enabled via either a [compile time configuration
|
||||
option](configuration.md#bazel-support), or via `BAZEL_TEST` environment
|
||||
variable set to "1".
|
||||
|
||||
> Support for `BAZEL_TEST` was [introduced](https://github.com/catchorg/Catch2/pull/2459) in Catch2 3.1.0
|
||||
|
||||
|
||||
## Low-level tools
|
||||
|
||||
### Precompiled headers (PCHs)
|
||||
|
||||
Catch offers prototypal support for being included in precompiled headers, but because of its single-header nature it does need some actions by the user:
|
||||
* The precompiled header needs to define `CATCH_CONFIG_ALL_PARTS`
|
||||
* The implementation file needs to
|
||||
* undefine `TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED`
|
||||
* define `CATCH_CONFIG_IMPL_ONLY`
|
||||
* define `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`
|
||||
* include "catch.hpp" again
|
||||
|
||||
|
||||
### CodeCoverage module (GCOV, LCOV...)
|
||||
|
||||
If you are using GCOV tool to get testing coverage of your code, and are not sure how to integrate it with CMake and Catch, there should be an external example over at https://github.com/claremacrae/catch_cmake_coverage
|
||||
If you are using GCOV tool to get testing coverage of your code, and are not sure how to integrate it with CMake and Catch, there should be an external example over at https://github.com/fkromer/catch_cmake_coverage
|
||||
|
||||
|
||||
### pkg-config
|
||||
@@ -93,7 +95,7 @@ can use `pkg-config` to get its include path: `pkg-config --cflags catch2`.
|
||||
|
||||
### gdb and lldb scripts
|
||||
|
||||
Catch2's `extras` folder also contains two simple debugger scripts,
|
||||
Catch2's `contrib` folder also contains two simple debugger scripts,
|
||||
`gdbinit` for `gdb` and `lldbinit` for `lldb`. If loaded into their
|
||||
respective debugger, these will tell it to step over Catch2's internals
|
||||
when stepping through code.
|
||||
|
@@ -2,13 +2,11 @@
|
||||
# CMake integration
|
||||
|
||||
**Contents**<br>
|
||||
[CMake targets](#cmake-targets)<br>
|
||||
[CMake target](#cmake-target)<br>
|
||||
[Automatic test registration](#automatic-test-registration)<br>
|
||||
[CMake project options](#cmake-project-options)<br>
|
||||
[`CATCH_CONFIG_*` customization options in CMake](#catch_config_-customization-options-in-cmake)<br>
|
||||
[Installing Catch2 from git repository](#installing-catch2-from-git-repository)<br>
|
||||
[Installing Catch2 from vcpkg](#installing-catch2-from-vcpkg)<br>
|
||||
[Installing Catch2 from Bazel](#installing-catch2-from-bazel)<br>
|
||||
|
||||
Because we use CMake to build Catch2, we also provide a couple of
|
||||
integration points for our users.
|
||||
@@ -17,102 +15,65 @@ integration points for our users.
|
||||
2) Catch2's repository contains CMake scripts for automatic registration
|
||||
of `TEST_CASE`s in CTest
|
||||
|
||||
## CMake targets
|
||||
## CMake target
|
||||
|
||||
Catch2's CMake build exports two targets, `Catch2::Catch2`, and
|
||||
`Catch2::Catch2WithMain`. If you do not need custom `main` function,
|
||||
you should be using the latter (and only the latter). Linking against
|
||||
it will add the proper include paths and link your target together with
|
||||
2 static libraries that implement Catch2 and its main respectively.
|
||||
If you need custom `main`, you should link only against `Catch2::Catch2`.
|
||||
Catch2's CMake build exports an interface target `Catch2::Catch2`. Linking
|
||||
against it will add the proper include path and all necessary capabilities
|
||||
to the resulting binary.
|
||||
|
||||
This means that if Catch2 has been installed on the system, it should
|
||||
be enough to do
|
||||
This means that if Catch2 has been installed on the system, it should be
|
||||
enough to do:
|
||||
```cmake
|
||||
find_package(Catch2 3 REQUIRED)
|
||||
# These tests can use the Catch2-provided main
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
|
||||
|
||||
# These tests need their own main
|
||||
add_executable(custom-main-tests test.cpp test-main.cpp)
|
||||
target_link_libraries(custom-main-tests PRIVATE Catch2::Catch2)
|
||||
find_package(Catch2 REQUIRED)
|
||||
target_link_libraries(tests Catch2::Catch2)
|
||||
```
|
||||
|
||||
These targets are also provided when Catch2 is used as a subdirectory.
|
||||
Assuming Catch2 has been cloned to `lib/Catch2`, you only need to replace
|
||||
the `find_package` call with `add_subdirectory(lib/Catch2)` and the snippet
|
||||
above still works.
|
||||
|
||||
|
||||
Another possibility is to use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html):
|
||||
This target is also provided when Catch2 is used as a subdirectory.
|
||||
Assuming that Catch2 has been cloned to `lib/Catch2`:
|
||||
```cmake
|
||||
Include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.8.1 # or a later release
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain)
|
||||
add_subdirectory(lib/Catch2)
|
||||
target_link_libraries(tests Catch2::Catch2)
|
||||
```
|
||||
|
||||
|
||||
## Automatic test registration
|
||||
|
||||
Catch2's repository also contains three CMake scripts that help users
|
||||
Catch2's repository also contains two CMake scripts that help users
|
||||
with automatically registering their `TEST_CASE`s with CTest. They
|
||||
can be found in the `extras` folder, and are
|
||||
can be found in the `contrib` folder, and are
|
||||
|
||||
1) `Catch.cmake` (and its dependency `CatchAddTests.cmake`)
|
||||
2) `ParseAndAddCatchTests.cmake` (deprecated)
|
||||
3) `CatchShardTests.cmake` (and its dependency `CatchShardTestsImpl.cmake`)
|
||||
2) `ParseAndAddCatchTests.cmake`
|
||||
|
||||
If Catch2 has been installed in system, both of these can be used after
|
||||
doing `find_package(Catch2 REQUIRED)`. Otherwise you need to add them
|
||||
to your CMake module path.
|
||||
|
||||
<a id="catch_discover_tests"></a>
|
||||
### `Catch.cmake` and `CatchAddTests.cmake`
|
||||
|
||||
`Catch.cmake` provides function `catch_discover_tests` to get tests from
|
||||
a target. This function works by running the resulting executable with
|
||||
`--list-test` flag, and then parsing the output to find all existing tests.
|
||||
`--list-test-names-only` flag, and then parsing the output to find all
|
||||
existing tests.
|
||||
|
||||
#### Usage
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(baz LANGUAGES CXX VERSION 0.0.1)
|
||||
|
||||
find_package(Catch2 REQUIRED)
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2)
|
||||
add_executable(foo test.cpp)
|
||||
target_link_libraries(foo Catch2::Catch2)
|
||||
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
catch_discover_tests(tests)
|
||||
catch_discover_tests(foo)
|
||||
```
|
||||
|
||||
When using `FetchContent`, `include(Catch)` will fail unless
|
||||
`CMAKE_MODULE_PATH` is explicitly updated to include the extras
|
||||
directory.
|
||||
|
||||
```cmake
|
||||
# ... FetchContent ...
|
||||
#
|
||||
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
catch_discover_tests(tests)
|
||||
```
|
||||
|
||||
#### Customization
|
||||
`catch_discover_tests` can be given several extra arguments:
|
||||
`catch_discover_tests` can be given several extra argumets:
|
||||
```cmake
|
||||
catch_discover_tests(target
|
||||
[TEST_SPEC arg1...]
|
||||
@@ -122,13 +83,6 @@ catch_discover_tests(target
|
||||
[TEST_SUFFIX suffix]
|
||||
[PROPERTIES name1 value1...]
|
||||
[TEST_LIST var]
|
||||
[REPORTER reporter]
|
||||
[OUTPUT_DIR dir]
|
||||
[OUTPUT_PREFIX prefix]
|
||||
[OUTPUT_SUFFIX suffix]
|
||||
[DISCOVERY_MODE <POST_BUILD|PRE_TEST>]
|
||||
[SKIP_IS_FAILURE]
|
||||
[ADD_TAGS_AS_LABELS]
|
||||
)
|
||||
```
|
||||
|
||||
@@ -175,81 +129,29 @@ default `<target>_TESTS`. This can be useful when the same test
|
||||
executable is being used in multiple calls to `catch_discover_tests()`.
|
||||
Note that this variable is only available in CTest.
|
||||
|
||||
* `REPORTER reporter`
|
||||
|
||||
Use the specified reporter when running the test case. The reporter will
|
||||
be passed to the test runner as `--reporter reporter`.
|
||||
|
||||
* `OUTPUT_DIR dir`
|
||||
|
||||
If specified, the parameter is passed along as
|
||||
`--out dir/<test_name>` to test executable. The actual file name is the
|
||||
same as the test name. This should be used instead of
|
||||
`EXTRA_ARGS --out foo` to avoid race conditions writing the result output
|
||||
when using parallel test execution.
|
||||
|
||||
* `OUTPUT_PREFIX prefix`
|
||||
|
||||
May be used in conjunction with `OUTPUT_DIR`.
|
||||
If specified, `prefix` is added to each output file name, like so
|
||||
`--out dir/prefix<test_name>`.
|
||||
|
||||
* `OUTPUT_SUFFIX suffix`
|
||||
|
||||
May be used in conjunction with `OUTPUT_DIR`.
|
||||
If specified, `suffix` is added to each output file name, like so
|
||||
`--out dir/<test_name>suffix`. This can be used to add a file extension to
|
||||
the output file name e.g. ".xml".
|
||||
|
||||
* `DISCOVERY_MODE mode`
|
||||
|
||||
If specified allows control over when test discovery is performed.
|
||||
For a value of `POST_BUILD` (default) test discovery is performed at build time.
|
||||
For a value of `PRE_TEST` test discovery is delayed until just prior to test
|
||||
execution (useful e.g. in cross-compilation environments).
|
||||
``DISCOVERY_MODE`` defaults to the value of the
|
||||
``CMAKE_CATCH_DISCOVER_TESTS_DISCOVERY_MODE`` variable if it is not passed when
|
||||
calling ``catch_discover_tests``. This provides a mechanism for globally
|
||||
selecting a preferred test discovery behavior.
|
||||
|
||||
* `SKIP_IS_FAILURE`
|
||||
|
||||
Skipped tests will be marked as failed instead.
|
||||
|
||||
* `ADD_TAGS_AS_LABELS`
|
||||
|
||||
Add the tags from tests as labels to CTest.
|
||||
|
||||
|
||||
### `ParseAndAddCatchTests.cmake`
|
||||
|
||||
⚠ This script is [deprecated](https://github.com/catchorg/Catch2/pull/2120)
|
||||
in Catch2 2.13.4 and superseded by the above approach using `catch_discover_tests`.
|
||||
See [#2092](https://github.com/catchorg/Catch2/issues/2092) for details.
|
||||
|
||||
`ParseAndAddCatchTests` works by parsing all implementation files
|
||||
associated with the provided target, and registering them via CTest's
|
||||
`add_test`. This approach has some limitations, such as the fact that
|
||||
commented-out tests will be registered anyway. More serious, only a
|
||||
subset of the assertion macros currently available in Catch can be
|
||||
detected by this script and tests with any macros that cannot be
|
||||
parsed are *silently ignored*.
|
||||
commented-out tests will be registered anyway.
|
||||
|
||||
|
||||
#### Usage
|
||||
|
||||
```cmake
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(baz LANGUAGES CXX VERSION 0.0.1)
|
||||
|
||||
find_package(Catch2 REQUIRED)
|
||||
add_executable(tests test.cpp)
|
||||
target_link_libraries(tests PRIVATE Catch2::Catch2)
|
||||
add_executable(foo test.cpp)
|
||||
target_link_libraries(foo Catch2::Catch2)
|
||||
|
||||
include(CTest)
|
||||
include(ParseAndAddCatchTests)
|
||||
ParseAndAddCatchTests(tests)
|
||||
ParseAndAddCatchTests(foo)
|
||||
```
|
||||
|
||||
|
||||
@@ -259,7 +161,7 @@ ParseAndAddCatchTests(tests)
|
||||
* `PARSE_CATCH_TESTS_VERBOSE` -- When `ON`, the script prints debug
|
||||
messages. Defaults to `OFF`.
|
||||
* `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`.
|
||||
* `PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME` -- When `ON`, adds fixture
|
||||
class name to the test name in CTest. Defaults to `ON`.
|
||||
@@ -281,68 +183,10 @@ unset(OptionalCatchTestLauncher)
|
||||
ParseAndAddCatchTests(bar)
|
||||
```
|
||||
|
||||
|
||||
### `CatchShardTests.cmake`
|
||||
|
||||
> `CatchShardTests.cmake` was introduced in Catch2 3.1.0.
|
||||
|
||||
`CatchShardTests.cmake` provides a function
|
||||
`catch_add_sharded_tests(TEST_BINARY)` that splits tests from `TEST_BINARY`
|
||||
into multiple shards. The tests in each shard and their order is randomized,
|
||||
and the seed changes every invocation of CTest.
|
||||
|
||||
Currently there are 3 customization points for this script:
|
||||
|
||||
* SHARD_COUNT - number of shards to split target's tests into
|
||||
* REPORTER - reporter spec to use for tests
|
||||
* TEST_SPEC - test spec used for filtering tests
|
||||
|
||||
Example usage:
|
||||
|
||||
```
|
||||
include(CatchShardTests)
|
||||
|
||||
catch_add_sharded_tests(foo-tests
|
||||
SHARD_COUNT 4
|
||||
REPORTER "xml::out=-"
|
||||
TEST_SPEC "A"
|
||||
)
|
||||
|
||||
catch_add_sharded_tests(tests
|
||||
SHARD_COUNT 8
|
||||
REPORTER "xml::out=-"
|
||||
TEST_SPEC "B"
|
||||
)
|
||||
```
|
||||
|
||||
This registers total of 12 CTest tests (4 + 8 shards) to run shards
|
||||
from `foo-tests` test binary, filtered by a test spec.
|
||||
|
||||
_Note that this script is currently a proof-of-concept for reseeding
|
||||
shards per CTest run, and thus does not support (nor does it currently
|
||||
aim to support) all customization points from
|
||||
[`catch_discover_tests`](#catch_discover_tests)._
|
||||
|
||||
|
||||
## CMake project options
|
||||
|
||||
Catch2's CMake project also provides some options for other projects
|
||||
that consume it. These are:
|
||||
|
||||
* `BUILD_TESTING` -- When `ON` and the project is not used as a subproject,
|
||||
Catch2's test binary will be built. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_DOCS` -- When `ON`, Catch2's documentation will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_EXTRAS` -- When `ON`, Catch2's extras folder (the CMake
|
||||
scripts mentioned above, debugger helpers) will be included in the
|
||||
installation. Defaults to `ON`.
|
||||
* `CATCH_DEVELOPMENT_BUILD` -- When `ON`, configures the build for development
|
||||
of Catch2. This means enabling test projects, warnings and so on.
|
||||
Defaults to `OFF`.
|
||||
|
||||
|
||||
Enabling `CATCH_DEVELOPMENT_BUILD` also enables further configuration
|
||||
customization options:
|
||||
that consume it. These are
|
||||
|
||||
* `CATCH_BUILD_TESTING` -- When `ON`, Catch2's SelfTest project will be
|
||||
built. Defaults to `ON`. Note that Catch2 also obeys `BUILD_TESTING` CMake
|
||||
@@ -350,40 +194,12 @@ variable, so _both_ of them need to be `ON` for the SelfTest to be built,
|
||||
and either of them can be set to `OFF` to disable building SelfTest.
|
||||
* `CATCH_BUILD_EXAMPLES` -- When `ON`, Catch2's usage examples will be
|
||||
built. Defaults to `OFF`.
|
||||
* `CATCH_BUILD_EXTRA_TESTS` -- When `ON`, Catch2's extra tests will be
|
||||
built. Defaults to `OFF`.
|
||||
* `CATCH_BUILD_FUZZERS` -- When `ON`, Catch2 fuzzing entry points will
|
||||
be built. Defaults to `OFF`.
|
||||
* `CATCH_ENABLE_WERROR` -- When `ON`, adds `-Werror` or equivalent flag
|
||||
to the compilation. Defaults to `ON`.
|
||||
* `CATCH_BUILD_SURROGATES` -- When `ON`, each header in Catch2 will be
|
||||
compiled separately to ensure that they are self-sufficient.
|
||||
Defaults to `OFF`.
|
||||
|
||||
|
||||
## `CATCH_CONFIG_*` customization options in CMake
|
||||
|
||||
> CMake support for `CATCH_CONFIG_*` options was introduced in Catch2 3.0.1
|
||||
|
||||
Due to the new separate compilation model, all the options from the
|
||||
[Compile-time configuration docs](configuration.md#top) can also be set
|
||||
through Catch2's CMake. To set them, define the option you want as `ON`,
|
||||
e.g. `-DCATCH_CONFIG_NOSTDOUT=ON`.
|
||||
|
||||
Note that setting the option to `OFF` doesn't disable it. To force disable
|
||||
an option, you need to set the `_NO_` form of it to `ON`, e.g.
|
||||
`-DCATCH_CONFIG_NO_COLOUR_WIN32=ON`.
|
||||
|
||||
|
||||
To summarize the configuration option behaviour with an example:
|
||||
|
||||
| `-DCATCH_CONFIG_COLOUR_WIN32` | `-DCATCH_CONFIG_NO_COLOUR_WIN32` | Result |
|
||||
|-------------------------------|----------------------------------|-------------|
|
||||
| `ON` | `ON` | error |
|
||||
| `ON` | `OFF` | force-on |
|
||||
| `OFF` | `ON` | force-off |
|
||||
| `OFF` | `OFF` | auto-detect |
|
||||
|
||||
* `CATCH_INSTALL_DOCS` -- When `ON`, Catch2's documentation will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `CATCH_INSTALL_HELPERS` -- When `ON`, Catch2's contrib folder will be
|
||||
included in the installation. Defaults to `ON`.
|
||||
* `BUILD_TESTING` -- When `ON` and the project is not used as a subproject,
|
||||
Catch2's test binary will be built. Defaults to `ON`.
|
||||
|
||||
|
||||
## Installing Catch2 from git repository
|
||||
@@ -395,7 +211,7 @@ install it to the default location, like so:
|
||||
```
|
||||
$ git clone https://github.com/catchorg/Catch2.git
|
||||
$ cd Catch2
|
||||
$ cmake -B build -S . -DBUILD_TESTING=OFF
|
||||
$ cmake -Bbuild -H. -DBUILD_TESTING=OFF
|
||||
$ sudo cmake --build build/ --target install
|
||||
```
|
||||
|
||||
@@ -419,24 +235,6 @@ cd vcpkg
|
||||
The catch2 port in vcpkg is kept up to date by microsoft team members and community contributors.
|
||||
If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
## Installing Catch2 from Bazel
|
||||
|
||||
Catch2 is now a supported module in the Bazel Central Registry. You only need to add one line to your MODULE.bazel file;
|
||||
please see https://registry.bazel.build/modules/catch2 for the latest supported version.
|
||||
|
||||
You can then add `catch2_main` to each of your C++ test build rules as follows:
|
||||
|
||||
```
|
||||
cc_test(
|
||||
name = "example_test",
|
||||
srcs = ["example_test.cpp"],
|
||||
deps = [
|
||||
":example",
|
||||
"@catch2//:catch2_main",
|
||||
],
|
||||
)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
@@ -15,11 +15,11 @@
|
||||
[Warnings](#warnings)<br>
|
||||
[Reporting timings](#reporting-timings)<br>
|
||||
[Load test names to run from a file](#load-test-names-to-run-from-a-file)<br>
|
||||
[Just test names](#just-test-names)<br>
|
||||
[Specify the order test cases are run](#specify-the-order-test-cases-are-run)<br>
|
||||
[Specify a seed for the Random Number Generator](#specify-a-seed-for-the-random-number-generator)<br>
|
||||
[Identify framework and version according to the libIdentify standard](#identify-framework-and-version-according-to-the-libidentify-standard)<br>
|
||||
[Wait for key before continuing](#wait-for-key-before-continuing)<br>
|
||||
[Skip all benchmarks](#skip-all-benchmarks)<br>
|
||||
[Specify the number of benchmark samples to collect](#specify-the-number-of-benchmark-samples-to-collect)<br>
|
||||
[Specify the number of resamples for bootstrapping](#specify-the-number-of-resamples-for-bootstrapping)<br>
|
||||
[Specify the confidence-interval for bootstrapping](#specify-the-confidence-interval-for-bootstrapping)<br>
|
||||
@@ -29,15 +29,14 @@
|
||||
[Specify the section to run](#specify-the-section-to-run)<br>
|
||||
[Filenames as tags](#filenames-as-tags)<br>
|
||||
[Override output colouring](#override-output-colouring)<br>
|
||||
[Test Sharding](#test-sharding)<br>
|
||||
[Allow running the binary without tests](#allow-running-the-binary-without-tests)<br>
|
||||
[Output verbosity](#output-verbosity)<br>
|
||||
|
||||
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available.
|
||||
Click one of the following links to take you straight to that option - or scroll on to browse the available options.
|
||||
|
||||
<a href="#specifying-which-tests-to-run"> ` <test-spec> ...`</a><br />
|
||||
<a href="#usage"> ` -h, -?, --help`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` -l, --list-tests`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` -t, --list-tags`</a><br />
|
||||
<a href="#showing-results-for-successful-tests"> ` -s, --success`</a><br />
|
||||
<a href="#breaking-into-the-debugger"> ` -b, --break`</a><br />
|
||||
<a href="#eliding-assertions-expected-to-throw"> ` -e, --nothrow`</a><br />
|
||||
@@ -56,25 +55,18 @@ Click one of the following links to take you straight to that option - or scroll
|
||||
|
||||
</br>
|
||||
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-tests`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-tags`</a><br />
|
||||
<a href="#list-test-names-only"> ` --list-test-names-only`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-reporters`</a><br />
|
||||
<a href="#listing-available-tests-tags-or-reporters"> ` --list-listeners`</a><br />
|
||||
<a href="#order"> ` --order`</a><br />
|
||||
<a href="#rng-seed"> ` --rng-seed`</a><br />
|
||||
<a href="#libidentify"> ` --libidentify`</a><br />
|
||||
<a href="#wait-for-keypress"> ` --wait-for-keypress`</a><br />
|
||||
<a href="#skip-benchmarks"> ` --skip-benchmarks`</a><br />
|
||||
<a href="#benchmark-samples"> ` --benchmark-samples`</a><br />
|
||||
<a href="#benchmark-resamples"> ` --benchmark-resamples`</a><br />
|
||||
<a href="#benchmark-confidence-interval"> ` --benchmark-confidence-interval`</a><br />
|
||||
<a href="#benchmark-no-analysis"> ` --benchmark-no-analysis`</a><br />
|
||||
<a href="#benchmark-warmup-time"> ` --benchmark-warmup-time`</a><br />
|
||||
<a href="#colour-mode"> ` --colour-mode`</a><br />
|
||||
<a href="#test-sharding"> ` --shard-count`</a><br />
|
||||
<a href="#test-sharding"> ` --shard-index`</a><br />
|
||||
<a href=#no-tests-override> ` --allow-running-no-tests`</a><br />
|
||||
<a href=#output-verbosity> ` --verbosity`</a><br />
|
||||
<a href="#use-colour"> ` --use-colour`</a><br />
|
||||
|
||||
</br>
|
||||
|
||||
@@ -85,149 +77,57 @@ Click one of the following links to take you straight to that option - or scroll
|
||||
|
||||
<pre><test-spec> ...</pre>
|
||||
|
||||
By providing a test spec, you filter which tests will be run. If you call
|
||||
Catch2 without any test spec, then it will run all non-hidden test
|
||||
cases. A test case is hidden if it has the `[!benchmark]` tag, any tag
|
||||
with a dot at the start, e.g. `[.]` or `[.foo]`.
|
||||
Test cases, wildcarded test cases, tags and tag expressions are all passed directly as arguments. Tags are distinguished by being enclosed in square brackets.
|
||||
|
||||
There are three basic test specs that can then be combined into more
|
||||
complex specs:
|
||||
If no test specs are supplied then all test cases, except "hidden" tests, are run.
|
||||
A test is hidden by giving it any tag starting with (or just) a period (```.```) - or, in the deprecated case, tagged ```[hide]``` or given name starting with `'./'`. To specify hidden tests from the command line ```[.]``` or ```[hide]``` can be used *regardless of how they were declared*.
|
||||
|
||||
* Full test name, e.g. `"Test 1"`.
|
||||
Specs must be enclosed in quotes if they contain spaces. If they do not contain spaces the quotes are optional.
|
||||
|
||||
This allows only test cases whose name is "Test 1".
|
||||
Wildcards consist of the `*` character at the beginning and/or end of test case names and can substitute for any number of any characters (including none).
|
||||
|
||||
* Wildcarded test name, e.g. `"*Test"`, or `"Test*"`, or `"*Test*"`.
|
||||
Test specs are case insensitive.
|
||||
|
||||
This allows any test case whose name ends with, starts with, or contains
|
||||
in the middle the string "Test". Note that the wildcard can only be at
|
||||
the start or end.
|
||||
If a spec is prefixed with `exclude:` or the `~` character then the pattern matches an exclusion. This means that tests matching the pattern are excluded from the set - even if a prior inclusion spec included them. Subsequent inclusion specs will take precedence, however.
|
||||
Inclusions and exclusions are evaluated in left-to-right order.
|
||||
|
||||
* Tag name, e.g. `[some-tag]`.
|
||||
Test case examples:
|
||||
|
||||
This allows any test case tagged with "[some-tag]". Remember that some
|
||||
tags are special, e.g. those that start with "." or with "!".
|
||||
<pre>thisTestOnly Matches the test case called, 'thisTestOnly'
|
||||
"this test only" Matches the test case called, 'this test only'
|
||||
these* Matches all cases starting with 'these'
|
||||
exclude:notThis Matches all tests except, 'notThis'
|
||||
~notThis Matches all tests except, 'notThis'
|
||||
~*private* Matches all tests except those that contain 'private'
|
||||
a* ~ab* abc Matches all tests that start with 'a', except those that
|
||||
start with 'ab', except 'abc', which is included
|
||||
-# [#somefile] Matches all tests from the file 'somefile.cpp'
|
||||
</pre>
|
||||
|
||||
Names within square brackets are interpreted as tags.
|
||||
A series of tags form an AND expression whereas a comma-separated sequence forms an OR expression. e.g.:
|
||||
|
||||
You can also combine the basic test specs to create more complex test
|
||||
specs. You can:
|
||||
|
||||
* Concatenate specs to apply all of them, e.g. `[some-tag][other-tag]`.
|
||||
|
||||
This allows test cases that are tagged with **both** "[some-tag]" **and**
|
||||
"[other-tag]". A test case with just "[some-tag]" will not pass the filter,
|
||||
nor will test case with just "[other-tag]".
|
||||
|
||||
* Comma-join specs to apply any of them, e.g. `[some-tag],[other-tag]`.
|
||||
|
||||
This allows test cases that are tagged with **either** "[some-tag]" **or**
|
||||
"[other-tag]". A test case with both will obviously also pass the filter.
|
||||
|
||||
Note that commas take precedence over simple concatenation. This means
|
||||
that `[a][b],[c]` accepts tests that are tagged with either both "[a]" and
|
||||
"[b]", or tests that are tagged with just "[c]".
|
||||
|
||||
* Negate the spec by prepending it with `~`, e.g. `~[some-tag]`.
|
||||
|
||||
This rejects any test case that is tagged with "[some-tag]". Note that
|
||||
rejection takes precedence over other filters.
|
||||
|
||||
Note that negations always binds to the following _basic_ test spec.
|
||||
This means that `~[foo][bar]` negates only the "[foo]" tag and not the
|
||||
"[bar]" tag.
|
||||
|
||||
Note that when Catch2 is deciding whether to include a test, first it
|
||||
checks whether the test matches any negative filters. If it does,
|
||||
the test is rejected. After that, the behaviour depends on whether there
|
||||
are positive filters as well. If there are no positive filters, all
|
||||
remaining non-hidden tests are included. If there are positive filters,
|
||||
only tests that match the positive filters are included.
|
||||
|
||||
You can also match test names with special characters by escaping them
|
||||
with a backslash (`"\"`), e.g. a test named `"Do A, then B"` is matched
|
||||
by `"Do A\, then B"` test spec. Backslash also escapes itself.
|
||||
|
||||
|
||||
### Examples
|
||||
|
||||
Given these TEST_CASEs,
|
||||
```
|
||||
TEST_CASE("Test 1") {}
|
||||
|
||||
TEST_CASE("Test 2", "[.foo]") {}
|
||||
|
||||
TEST_CASE("Test 3", "[.bar]") {}
|
||||
|
||||
TEST_CASE("Test 4", "[.][foo][bar]") {}
|
||||
```
|
||||
|
||||
this is the result of these filters
|
||||
```
|
||||
./tests # Selects only the first test, others are hidden
|
||||
./tests "Test 1" # Selects only the first test, other do not match
|
||||
./tests ~"Test 1" # Selects no tests. Test 1 is rejected, other tests are hidden
|
||||
./tests "Test *" # Selects all tests.
|
||||
./tests [bar] # Selects tests 3 and 4. Other tests are not tagged [bar]
|
||||
./tests ~[foo] # Selects test 1, because it is the only non-hidden test without [foo] tag
|
||||
./tests [foo][bar] # Selects test 4.
|
||||
./tests [foo],[bar] # Selects tests 2, 3, 4.
|
||||
./tests ~[foo][bar] # Selects test 3. 2 and 4 are rejected due to having [foo] tag
|
||||
./tests ~"Test 2"[foo] # Selects test 4, because test 2 is explicitly rejected
|
||||
./tests [foo][bar],"Test 1" # Selects tests 1 and 4.
|
||||
./tests "Test 1*" # Selects test 1, wildcard can match zero characters
|
||||
```
|
||||
|
||||
_Note: Using plain asterisk on a command line can cause issues with shell
|
||||
expansion. Make sure that the asterisk is passed to Catch2 and is not
|
||||
interpreted by the shell._
|
||||
<pre>[one][two],[three]</pre>
|
||||
This matches all tests tagged `[one]` and `[two]`, as well as all tests tagged `[three]`
|
||||
|
||||
Test names containing special characters, such as `,` or `[` can specify them on the command line using `\`.
|
||||
`\` also escapes itself.
|
||||
|
||||
<a id="choosing-a-reporter-to-use"></a>
|
||||
## Choosing a reporter to use
|
||||
|
||||
<pre>-r, --reporter <reporter[::key=value]*></pre>
|
||||
<pre>-r, --reporter <reporter></pre>
|
||||
|
||||
Reporters are how the output from Catch2 (results of assertions, tests,
|
||||
benchmarks and so on) is formatted and written out. The default reporter
|
||||
is called the "Console" reporter and is intended to provide relatively
|
||||
verbose and human-friendly output.
|
||||
A reporter is an object that formats and structures the output of running tests, and potentially summarises the results. By default a console reporter is used that writes, IDE friendly, textual output. Catch comes bundled with some alternative reporters, but more can be added in client code.<br />
|
||||
The bundled reporters are:
|
||||
|
||||
Reporters are also individually configurable. To pass configuration options
|
||||
to the reporter, you append `::key=value` to the reporter specification
|
||||
as many times as you want, e.g. `--reporter xml::out=someFile.xml` or
|
||||
`--reporter custom::colour-mode=ansi::Xoption=2`.
|
||||
|
||||
The keys must either be prefixed by "X", in which case they are not parsed
|
||||
by Catch2 and are only passed down to the reporter, or one of options
|
||||
hardcoded into Catch2. Currently there are only 2,
|
||||
["out"](#sending-output-to-a-file), and ["colour-mode"](#colour-mode).
|
||||
|
||||
_Note that the reporter might still check the X-prefixed options for
|
||||
validity, and throw an error if they are wrong._
|
||||
|
||||
> Support for passing arguments to reporters through the `-r`, `--reporter` flag was introduced in Catch2 3.0.1
|
||||
|
||||
There are multiple built-in reporters, you can see what they do by using the
|
||||
[`--list-reporters`](command-line.md#listing-available-tests-tags-or-reporters)
|
||||
flag. If you need a reporter providing custom format outside of the already
|
||||
provided ones, look at the ["write your own reporter" part of the reporter
|
||||
documentation](reporters.md#writing-your-own-reporter).
|
||||
|
||||
This option may be passed multiple times to use multiple (different)
|
||||
reporters at the same time. See the [reporter documentation](reporters.md#multiple-reporters)
|
||||
for details on what the resulting behaviour is. Also note that at most one
|
||||
reporter can be provided without the output-file part of reporter spec.
|
||||
This reporter will use the "default" output destination, based on
|
||||
the [`-o`, `--out`](#sending-output-to-a-file) option.
|
||||
|
||||
> Support for using multiple different reporters at the same time was [introduced](https://github.com/catchorg/Catch2/pull/2183) in Catch2 3.0.1
|
||||
|
||||
|
||||
_Note: There is currently no way to escape `::` in the reporter spec,
|
||||
and thus the reporter names, or configuration keys and values, cannot
|
||||
contain `::`. As `::` in paths is relatively obscure (unlike ':'), we do
|
||||
not consider this an issue._
|
||||
<pre>-r console
|
||||
-r compact
|
||||
-r xml
|
||||
-r junit
|
||||
</pre>
|
||||
|
||||
The JUnit reporter is an xml format that follows the structure of the JUnit XML Report ANT task, as consumed by a number of third-party tools, including Continuous Integration servers such as Hudson. If not otherwise needed, the standard XML reporter is preferred as this is a streaming reporter, whereas the Junit reporter needs to hold all its results until the end so it can write the overall results into attributes of the root node.
|
||||
|
||||
<a id="breaking-into-the-debugger"></a>
|
||||
## Breaking into the debugger
|
||||
@@ -257,62 +157,24 @@ Sometimes this results in a flood of failure messages and you'd rather just see
|
||||
|
||||
<a id="listing-available-tests-tags-or-reporters"></a>
|
||||
## Listing available tests, tags or reporters
|
||||
```
|
||||
--list-tests
|
||||
--list-tags
|
||||
<pre>-l, --list-tests
|
||||
-t, --list-tags
|
||||
--list-reporters
|
||||
--list-listeners
|
||||
```
|
||||
</pre>
|
||||
|
||||
> The `--list*` options became customizable through reporters in Catch2 3.0.1
|
||||
```-l``` or ```--list-tests``` will list all registered tests, along with any tags.
|
||||
If one or more test-specs have been supplied too then only the matching tests will be listed.
|
||||
|
||||
> The `--list-listeners` option was added in Catch2 3.0.1
|
||||
```-t``` or ```--list-tags``` lists all available tags, along with the number of test cases they match. Again, supplying test specs limits the tags that match.
|
||||
|
||||
`--list-tests` lists all registered tests matching specified test spec.
|
||||
Usually this listing also includes tags, and potentially also other
|
||||
information, like source location, based on verbosity and reporter's design.
|
||||
|
||||
`--list-tags` lists all tags from registered tests matching specified test
|
||||
spec. Usually this also includes number of tests cases they match and
|
||||
similar information.
|
||||
|
||||
`--list-reporters` lists all available reporters and their descriptions.
|
||||
|
||||
`--list-listeners` lists all registered listeners and their descriptions.
|
||||
|
||||
The [`--verbosity` argument](#output-verbosity) modifies the level of detail provided by the default `--list*` options
|
||||
as follows:
|
||||
|
||||
| Option | `normal` (default) | `quiet` | `high` |
|
||||
|--------------------|---------------------------------|---------------------|-----------------------------------------|
|
||||
| `--list-tests` | Test names and tags | Test names only | Same as `normal`, plus source code line |
|
||||
| `--list-tags` | Tags and counts | Same as `normal` | Same as `normal` |
|
||||
| `--list-reporters` | Reporter names and descriptions | Reporter names only | Same as `normal` |
|
||||
| `--list-listeners` | Listener names and descriptions | Same as `normal` | Same as `normal` |
|
||||
```--list-reporters``` lists the available reporters.
|
||||
|
||||
<a id="sending-output-to-a-file"></a>
|
||||
## Sending output to a file
|
||||
<pre>-o, --out <filename>
|
||||
<pre>-o, --out <filename>
|
||||
</pre>
|
||||
|
||||
Use this option to send all output to a file, instead of stdout. You can
|
||||
use `-` as the filename to explicitly send the output to stdout (this is
|
||||
useful e.g. when using multiple reporters).
|
||||
|
||||
> Support for `-` as the filename was introduced in Catch2 3.0.1
|
||||
|
||||
Filenames starting with "%" (percent symbol) are reserved by Catch2 for
|
||||
meta purposes, e.g. using `%debug` as the filename opens stream that
|
||||
writes to platform specific debugging/logging mechanism.
|
||||
|
||||
Catch2 currently recognizes 3 meta streams:
|
||||
|
||||
* `%debug` - writes to platform specific debugging/logging output
|
||||
* `%stdout` - writes to stdout
|
||||
* `%stderr` - writes to stderr
|
||||
|
||||
> Support for `%stdout` and `%stderr` was introduced in Catch2 3.0.1
|
||||
|
||||
Use this option to send all output to a file. By default output is sent to stdout (note that uses of stdout and stderr *from within test cases* are redirected and included in the report - so even stderr will effectively end up on stdout).
|
||||
|
||||
<a id="naming-a-test-run"></a>
|
||||
## Naming a test run
|
||||
@@ -343,37 +205,29 @@ This option transforms tabs and newline characters into ```\t``` and ```\n``` re
|
||||
## Warnings
|
||||
<pre>-w, --warn <warning name></pre>
|
||||
|
||||
You can think of Catch2's warnings as the equivalent of `-Werror` (`/WX`)
|
||||
flag for C++ compilers. It turns some suspicious occurrences, like a section
|
||||
without assertions, into errors. Because these might be intended, warnings
|
||||
are not enabled by default, but user can opt in.
|
||||
|
||||
You can enable multiple warnings at the same time.
|
||||
|
||||
There are currently two warnings implemented:
|
||||
Enables reporting of suspicious test states. There are currently two
|
||||
available warnings
|
||||
|
||||
```
|
||||
NoAssertions // Fail test case / leaf section if no assertions
|
||||
// (e.g. `REQUIRE`) is encountered.
|
||||
UnmatchedTestSpec // Fail test run if any of the CLI test specs did
|
||||
// not match any tests.
|
||||
NoAssertions // Fail test case / leaf section if no assertions
|
||||
// (e.g. `REQUIRE`) is encountered.
|
||||
NoTests // Return non-zero exit code when no test cases were run
|
||||
// Also calls reporter's noMatchingTestCases method
|
||||
```
|
||||
|
||||
> `UnmatchedTestSpec` was introduced in Catch2 3.0.1.
|
||||
|
||||
|
||||
<a id="reporting-timings"></a>
|
||||
## Reporting timings
|
||||
<pre>-d, --durations <yes/no></pre>
|
||||
|
||||
When set to ```yes``` Catch will report the duration of each test case, in seconds with millisecond precision. Note that it does this regardless of whether a test case passes or fails. Note, also, the certain reporters (e.g. Junit) always report test case durations regardless of this option being set or not.
|
||||
When set to ```yes``` Catch will report the duration of each test case, in milliseconds. Note that it does this regardless of whether a test case passes or fails. Note, also, the certain reporters (e.g. Junit) always report test case durations regardless of this option being set or not.
|
||||
|
||||
<pre>-D, --min-duration <value></pre>
|
||||
|
||||
> `--min-duration` was [introduced](https://github.com/catchorg/Catch2/pull/1910) in Catch2 2.13.0
|
||||
> `--min-duration` was [introduced](https://github.com/catchorg/Catch2/pull/1910) in Catch 2.13.0
|
||||
|
||||
When set, Catch will report the duration of each test case that took more
|
||||
than <value> seconds, in seconds with millisecond precision. This option is overridden by both
|
||||
than <value> seconds, in milliseconds. This option is overriden by both
|
||||
`-d yes` and `-d no`, so that either all durations are reported, or none
|
||||
are.
|
||||
|
||||
@@ -382,13 +236,15 @@ are.
|
||||
## Load test names to run from a file
|
||||
<pre>-f, --input-file <filename></pre>
|
||||
|
||||
Provide the name of a file that contains a list of test case names,
|
||||
one per line. Blank lines are skipped.
|
||||
Provide the name of a file that contains a list of test case names - one per line. Blank lines are skipped and anything after the comment character, ```#```, is ignored.
|
||||
|
||||
A useful way to generate an initial instance of this file is to combine
|
||||
the [`--list-tests`](#listing-available-tests-tags-or-reporters) flag with
|
||||
the [`--verbosity quiet`](#output-verbosity) option. You can also
|
||||
use test specs to filter this list down to what you want first.
|
||||
A useful way to generate an initial instance of this file is to use the <a href="#list-test-names-only">list-test-names-only</a> option. This can then be manually curated to specify a specific subset of tests - or in a specific order.
|
||||
|
||||
<a id="list-test-names-only"></a>
|
||||
## Just test names
|
||||
<pre>--list-test-names-only</pre>
|
||||
|
||||
This option lists all available tests in a non-indented form, one on each line. This makes it ideal for saving to a file and feeding back into the <a href="#input-file">```-f``` or ```--input-file```</a> option.
|
||||
|
||||
|
||||
<a id="order"></a>
|
||||
@@ -398,53 +254,34 @@ use test specs to filter this list down to what you want first.
|
||||
Test cases are ordered one of three ways:
|
||||
|
||||
### decl
|
||||
Declaration order.
|
||||
|
||||
Tests in the same translation unit are sorted using their declaration orders,
|
||||
different TUs are sorted in an implementation (linking) dependent order.
|
||||
Declaration order (this is the default order if no --order argument is provided).
|
||||
Tests in the same TU are sorted using their declaration orders, different
|
||||
TUs are in an implementation (linking) dependent order.
|
||||
|
||||
|
||||
### lex
|
||||
Lexicographic order.
|
||||
|
||||
Tests are sorted by their name, their tags are ignored.
|
||||
Lexicographic order. Tests are sorted by their name, their tags are ignored.
|
||||
|
||||
|
||||
### rand
|
||||
Randomized order. The default order.
|
||||
|
||||
> Randomized order has been made default in Catch2 3.9.0
|
||||
|
||||
The order is dependent on Catch2's random seed (see
|
||||
Randomly sorted. The order is dependent on Catch2's random seed (see
|
||||
[`--rng-seed`](#rng-seed)), and is subset invariant. What this means
|
||||
is that as long as the random seed is fixed, running only some tests
|
||||
(e.g. via tag) does not change their relative order.
|
||||
|
||||
> The subset stability was introduced in Catch2 v2.12.0
|
||||
|
||||
Since the random order was made subset stable, we promise that given
|
||||
the same random seed, the order of test cases will be the same across
|
||||
different platforms, as long as the tests were compiled against identical
|
||||
version of Catch2. We reserve the right to change the relative order
|
||||
of tests cases between Catch2 versions, but it is unlikely to happen often.
|
||||
|
||||
|
||||
<a id="rng-seed"></a>
|
||||
## Specify a seed for the Random Number Generator
|
||||
<pre>--rng-seed <'time'|'random-device'|number></pre>
|
||||
<pre>--rng-seed <'time'|number></pre>
|
||||
|
||||
Sets the seed for random number generators used by Catch2. These are used
|
||||
e.g. to shuffle tests when user asks for tests to be in random order.
|
||||
|
||||
Using `time` as the argument asks Catch2 generate the seed through call
|
||||
to `std::time(nullptr)`. This provides very weak randomness and multiple
|
||||
runs of the binary can generate the same seed if they are started close
|
||||
to each other.
|
||||
|
||||
Using `random-device` asks for `std::random_device` to be used instead.
|
||||
If your implementation provides working `std::random_device`, it should
|
||||
be preferred to using `time`. Catch2 uses `std::random_device` by default.
|
||||
Sets a seed for the random number generator using ```std::srand()```.
|
||||
If a number is provided this is used directly as the seed so the random pattern is repeatable.
|
||||
Alternatively if the keyword ```time``` is provided then the result of calling ```std::time(0)``` is used and so the pattern becomes unpredictable. In some cases, you might need to pass the keyword ```time``` in double quotes instead of single quotes.
|
||||
|
||||
In either case the actual value for the seed is printed as part of Catch's output so if an issue is discovered that is sensitive to test ordering the ordering can be reproduced - even if it was originally seeded from ```std::time(0)```.
|
||||
|
||||
<a id="libidentify"></a>
|
||||
## Identify framework and version according to the libIdentify standard
|
||||
@@ -459,21 +296,11 @@ See [The LibIdentify repo for more information and examples](https://github.com/
|
||||
Will cause the executable to print a message and wait until the return/ enter key is pressed before continuing -
|
||||
either before running any tests, after running all tests - or both, depending on the argument.
|
||||
|
||||
<a id="skip-benchmarks"></a>
|
||||
## Skip all benchmarks
|
||||
<pre>--skip-benchmarks</pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/2408) in Catch2 3.0.1.
|
||||
|
||||
This flag tells Catch2 to skip running all benchmarks. Benchmarks in this
|
||||
case mean code blocks in `BENCHMARK` and `BENCHMARK_ADVANCED` macros, not
|
||||
test cases with the `[!benchmark]` tag.
|
||||
|
||||
<a id="benchmark-samples"></a>
|
||||
## Specify the number of benchmark samples to collect
|
||||
<pre>--benchmark-samples <# of samples></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
|
||||
When running benchmarks a number of "samples" is collected. This is the base data for later statistical analysis.
|
||||
Per sample a clock resolution dependent number of iterations of the user code is run, which is independent of the number of samples. Defaults to 100.
|
||||
@@ -482,7 +309,7 @@ Per sample a clock resolution dependent number of iterations of the user code is
|
||||
## Specify the number of resamples for bootstrapping
|
||||
<pre>--benchmark-resamples <# of resamples></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
|
||||
After the measurements are performed, statistical [bootstrapping] is performed
|
||||
on the samples. The number of resamples for that bootstrapping is configurable
|
||||
@@ -497,7 +324,7 @@ defaults to 95%).
|
||||
## Specify the confidence-interval for bootstrapping
|
||||
<pre>--benchmark-confidence-interval <confidence-interval></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
|
||||
The confidence-interval is used for statistical bootstrapping on the samples to
|
||||
calculate the upper and lower bounds of mean and standard deviation.
|
||||
@@ -507,7 +334,7 @@ Must be between 0 and 1 and defaults to 0.95.
|
||||
## Disable statistical analysis of collected benchmark samples
|
||||
<pre>--benchmark-no-analysis</pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch 2.9.0.
|
||||
|
||||
When this flag is specified no bootstrapping or any other statistical analysis is performed.
|
||||
Instead the user code is only measured and the plain mean from the samples is reported.
|
||||
@@ -516,7 +343,7 @@ Instead the user code is only measured and the plain mean from the samples is re
|
||||
## Specify the amount of time in milliseconds spent on warming up each test
|
||||
<pre>--benchmark-warmup-time</pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1844) in Catch2 2.11.2.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1844) in Catch 2.11.2.
|
||||
|
||||
Configure the amount of time spent warming up each test.
|
||||
|
||||
@@ -565,7 +392,7 @@ There are some limitations of this feature to be aware of:
|
||||
- Code outside of sections being skipped will still be executed - e.g. any set-up code in the TEST_CASE before the
|
||||
start of the first section.</br>
|
||||
- At time of writing, wildcards are not supported in section names.
|
||||
- If you specify a section without narrowing to a test case first then all test cases will be executed
|
||||
- If you specify a section without narrowing to a test case first then all test cases will be executed
|
||||
(but only matching sections within them).
|
||||
|
||||
|
||||
@@ -573,81 +400,21 @@ start of the first section.</br>
|
||||
## Filenames as tags
|
||||
<pre>-#, --filenames-as-tags</pre>
|
||||
|
||||
This option adds an extra tag to all test cases. The tag is `#` followed
|
||||
by the unqualified filename the test case is defined in, with the _last_
|
||||
extension stripped out.
|
||||
When this option is used then every test is given an additional tag which is formed of the unqualified
|
||||
filename it is found in, with any extension stripped, prefixed with the `#` character.
|
||||
|
||||
For example, tests within the file `tests\SelfTest\UsageTests\BDD.tests.cpp`
|
||||
will be given the `[#BDD.tests]` tag.
|
||||
So, for example, tests within the file `~\Dev\MyProject\Ferrets.cpp` would be tagged `[#Ferrets]`.
|
||||
|
||||
|
||||
<a id="colour-mode"></a>
|
||||
<a id="use-colour"></a>
|
||||
## Override output colouring
|
||||
<pre>--colour-mode <ansi|win32|none|default></pre>
|
||||
<pre>--use-colour <yes|no|auto></pre>
|
||||
|
||||
> The `--colour-mode` option replaced the old `--colour` option in Catch2 3.0.1
|
||||
|
||||
|
||||
Catch2 support two different ways of colouring terminal output, and by
|
||||
default it attempts to make a good guess on which implementation to use
|
||||
(and whether to even use it, e.g. Catch2 tries to avoid writing colour
|
||||
codes when writing the results into a file).
|
||||
|
||||
`--colour-mode` allows the user to explicitly select what happens.
|
||||
|
||||
* `--colour-mode ansi` tells Catch2 to always use ANSI colour codes, even
|
||||
when writing to a file
|
||||
* `--colour-mode win32` tells Catch2 to use colour implementation based
|
||||
on Win32 terminal API
|
||||
* `--colour-mode none` tells Catch2 to disable colours completely
|
||||
* `--colour-mode default` lets Catch2 decide
|
||||
|
||||
`--colour-mode default` is the default setting.
|
||||
|
||||
|
||||
<a id="test-sharding"></a>
|
||||
## Test Sharding
|
||||
<pre>--shard-count <#number of shards>, --shard-index <#shard index to run></pre>
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/2257) in Catch2 3.0.1.
|
||||
|
||||
When `--shard-count <#number of shards>` is used, the tests to execute
|
||||
will be split evenly in to the given number of sets, identified by indices
|
||||
starting at 0. The tests in the set given by
|
||||
`--shard-index <#shard index to run>` will be executed. The default shard
|
||||
count is `1`, and the default index to run is `0`.
|
||||
|
||||
_Shard index must be less than number of shards. As the name suggests,
|
||||
it is treated as an index of the shard to run._
|
||||
|
||||
Sharding is useful when you want to split test execution across multiple
|
||||
processes, as is done with the [Bazel test sharding](https://docs.bazel.build/versions/main/test-encyclopedia.html#test-sharding).
|
||||
|
||||
|
||||
<a id="no-tests-override"></a>
|
||||
## Allow running the binary without tests
|
||||
<pre>--allow-running-no-tests</pre>
|
||||
|
||||
> Introduced in Catch2 3.0.1.
|
||||
|
||||
By default, Catch2 test binaries return non-0 exit code if no tests were run,
|
||||
e.g. if the binary was compiled with no tests, the provided test spec matched no
|
||||
tests, or all tests [were skipped at runtime](skipping-passing-failing.md#top). This flag
|
||||
overrides that, so a test run with no tests still returns 0.
|
||||
|
||||
## Output verbosity
|
||||
```
|
||||
-v, --verbosity <quiet|normal|high>
|
||||
```
|
||||
|
||||
Changing verbosity might change how many details Catch2's reporters output.
|
||||
However, you should consider changing the verbosity level as a _suggestion_.
|
||||
Not all reporters support all verbosity levels, e.g. because the reporter's
|
||||
format cannot meaningfully change. In that case, the verbosity level is
|
||||
ignored.
|
||||
|
||||
Verbosity defaults to _normal_.
|
||||
Catch colours output for terminals, but omits colouring when it detects that
|
||||
output is being sent to a pipe. This is done to avoid interfering with automated
|
||||
processing of output.
|
||||
|
||||
`--use-colour yes` forces coloured output, `--use-colour no` disables coloured
|
||||
output. The default behaviour is `--use-colour auto`.
|
||||
|
||||
---
|
||||
|
||||
|
@@ -1,23 +1,22 @@
|
||||
<a id="top"></a>
|
||||
# Commercial users of Catch2
|
||||
# Commercial users of Catch
|
||||
|
||||
Catch2 is also widely used in proprietary code bases. This page contains
|
||||
some of them that are willing to share this information.
|
||||
|
||||
If you want to add your organisation, please check that there is no issue
|
||||
with you sharing this fact.
|
||||
As well as [Open Source](opensource-users.md#top) users Catch is widely used within proprietary code bases too.
|
||||
Many organisations like to keep this information internal, and that's fine,
|
||||
but if you're more open it would be great if we could list the names of as
|
||||
many organisations as possible that use Catch somewhere in their codebase.
|
||||
Enterprise environments often tend to be far more conservative in their tool adoption -
|
||||
and being aware that other companies are using Catch can ease the path in.
|
||||
|
||||
So if you are aware of Catch usage in your organisation, and are fairly confident there is no issue with sharing this
|
||||
fact then please let us know - either directly, via a PR or
|
||||
[issue](https://github.com/philsquared/Catch/issues), or on the [forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum).
|
||||
|
||||
- Bloomberg
|
||||
- [Bloomlife](https://bloomlife.com)
|
||||
- [Inscopix Inc.](https://www.inscopix.com/)
|
||||
- Locksley.CZ
|
||||
- [Makimo](https://makimo.pl/)
|
||||
- NASA
|
||||
- [Nexus Software Systems](https://nexwebsites.com)
|
||||
- [Inscopix Inc.](https://www.inscopix.com/)
|
||||
- [Makimo](https://makimo.pl/)
|
||||
- [UX3D](https://ux3d.io)
|
||||
- [King](https://king.com)
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
||||
|
@@ -1,192 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Comparing floating point numbers with Catch2
|
||||
|
||||
If you are not deeply familiar with them, floating point numbers can be
|
||||
unintuitive. This also applies to comparing floating point numbers for
|
||||
(in)equality.
|
||||
|
||||
This page assumes that you have some understanding of both FP, and the
|
||||
meaning of different kinds of comparisons, and only goes over what
|
||||
functionality Catch2 provides to help you with comparing floating point
|
||||
numbers. If you do not have this understanding, we recommend that you first
|
||||
study up on floating point numbers and their comparisons, e.g. by [reading
|
||||
this blog post](https://codingnest.com/the-little-things-comparing-floating-point-numbers/).
|
||||
|
||||
|
||||
## Floating point matchers
|
||||
|
||||
```
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
```
|
||||
|
||||
[Matchers](matchers.md#top) are the preferred way of comparing floating
|
||||
point numbers in Catch2. We provide 3 of them:
|
||||
|
||||
* `WithinAbs(double target, double margin)`,
|
||||
* `WithinRel(FloatingPoint target, FloatingPoint eps)`, and
|
||||
* `WithinULP(FloatingPoint target, uint64_t maxUlpDiff)`.
|
||||
|
||||
> `WithinRel` matcher was introduced in Catch2 2.10.0
|
||||
|
||||
As with all matchers, you can combine multiple floating point matchers
|
||||
in a single assertion. For example, to check that some computation matches
|
||||
a 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) );
|
||||
```
|
||||
|
||||
|
||||
### WithinAbs
|
||||
|
||||
`WithinAbs` creates a matcher that accepts floating point numbers whose
|
||||
difference with `target` is less-or-equal to the `margin`. Since `float`
|
||||
can be converted to `double` without losing precision, only `double`
|
||||
overload exists.
|
||||
|
||||
```cpp
|
||||
REQUIRE_THAT(1.0, WithinAbs(1.2, 0.2));
|
||||
REQUIRE_THAT(0.f, !WithinAbs(1.0, 0.5));
|
||||
// Notice that infinity == infinity for WithinAbs
|
||||
REQUIRE_THAT(INFINITY, WithinAbs(INFINITY, 0));
|
||||
```
|
||||
|
||||
|
||||
### WithinRel
|
||||
|
||||
`WithinRel` creates a matcher that accepts floating point numbers that
|
||||
are _approximately equal_ to the `target` with a 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.
|
||||
|
||||
```cpp
|
||||
// Notice that WithinRel comparison is symmetric, unlike Approx's.
|
||||
REQUIRE_THAT(1.0, WithinRel(1.1, 0.1));
|
||||
REQUIRE_THAT(1.1, WithinRel(1.0, 0.1));
|
||||
// Notice that inifnity == infinity for WithinRel
|
||||
REQUIRE_THAT(INFINITY, WithinRel(INFINITY));
|
||||
```
|
||||
|
||||
|
||||
### WithinULP
|
||||
|
||||
`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` representable floating
|
||||
point numbers between the argument for matching and the `target` value.
|
||||
|
||||
When using the ULP matcher in Catch2, it is important to keep in mind
|
||||
that Catch2 interprets ULP distance slightly differently than
|
||||
e.g. `std::nextafter` does.
|
||||
|
||||
Catch2's ULP calculation obeys these relations:
|
||||
* `ulpDistance(-x, x) == 2 * ulpDistance(x, 0)`
|
||||
* `ulpDistance(-0, 0) == 0` (due to the above)
|
||||
* `ulpDistance(DBL_MAX, INFINITY) == 1`
|
||||
* `ulpDistancE(NaN, x) == infinity`
|
||||
|
||||
|
||||
**Important**: The WithinULP matcher requires the platform to use the
|
||||
[IEEE-754](https://en.wikipedia.org/wiki/IEEE_754) representation for
|
||||
floating point numbers.
|
||||
|
||||
```cpp
|
||||
REQUIRE_THAT( -0.f, WithinULP( 0.f, 0 ) );
|
||||
```
|
||||
|
||||
|
||||
## `Approx`
|
||||
|
||||
```
|
||||
#include <catch2/catch_approx.hpp>
|
||||
```
|
||||
|
||||
**We strongly recommend against using `Approx` when writing new code.**
|
||||
You should be using floating point matchers instead.
|
||||
|
||||
Catch2 provides one more way to handle floating point comparisons. It is
|
||||
`Approx`, a special type with overloaded comparison operators, that can
|
||||
be used in standard assertions, e.g.
|
||||
|
||||
```cpp
|
||||
REQUIRE(0.99999 == Catch::Approx(1));
|
||||
```
|
||||
|
||||
`Approx` supports four comparison operators, `==`, `!=`, `<=`, `>=`, and can
|
||||
also be used with strong typedefs over `double`s. It can be used for both
|
||||
relative and margin comparisons by using its three customization points.
|
||||
Note that the semantics of this is always that of an _or_, so if either
|
||||
the relative or absolute margin comparison passes, then the whole comparison
|
||||
passes.
|
||||
|
||||
The downside to `Approx` is that it has a couple of issues that we cannot
|
||||
fix without breaking backwards compatibility. Because Catch2 also provides
|
||||
complete set of matchers that implement different floating point comparison
|
||||
methods, `Approx` is left as-is, is considered deprecated, and should
|
||||
not be used in new code.
|
||||
|
||||
The issues are
|
||||
* All internal computation is done in `double`s, leading to slightly
|
||||
different results if the inputs were floats.
|
||||
* `Approx`'s relative margin comparison is not symmetric. This means
|
||||
that `Approx( 10 ).epsilon(0.1) != 11.1` but `Approx( 11.1 ).epsilon(0.1) == 10`.
|
||||
* By default, `Approx` only uses relative margin comparison. This means
|
||||
that `Approx(0) == X` only passes for `X == 0`.
|
||||
|
||||
|
||||
### Approx details
|
||||
|
||||
If you still want/need to know more about `Approx`, read on.
|
||||
|
||||
Catch2 provides a UDL for `Approx`; `_a`. It resides in the `Catch::literals`
|
||||
namespace, and can be used like this:
|
||||
|
||||
```cpp
|
||||
using namespace Catch::literals;
|
||||
REQUIRE( performComputation() == 2.1_a );
|
||||
```
|
||||
|
||||
`Approx` has three customization points for the comparison:
|
||||
|
||||
* **epsilon** - epsilon sets the coefficient by which a result
|
||||
can differ from `Approx`'s value before it is rejected.
|
||||
_Defaults to `std::numeric_limits<float>::epsilon()*100`._
|
||||
|
||||
```cpp
|
||||
Approx target = Approx(100).epsilon(0.01);
|
||||
100.0 == target; // Obviously true
|
||||
200.0 == target; // Obviously still false
|
||||
100.5 == target; // True, because we set target to allow up to 1% difference
|
||||
```
|
||||
|
||||
|
||||
* **margin** - margin sets the absolute value by which
|
||||
a result can differ from `Approx`'s value before it is rejected.
|
||||
_Defaults to `0.0`._
|
||||
|
||||
```cpp
|
||||
Approx target = Approx(100).margin(5);
|
||||
100.0 == target; // Obviously true
|
||||
200.0 == target; // Obviously still false
|
||||
104.0 == target; // True, because we set target to allow absolute difference of at most 5
|
||||
```
|
||||
|
||||
* **scale** - scale is used to change the magnitude of `Approx` for the relative check.
|
||||
_By default, set to `0.0`._
|
||||
|
||||
Scale could be useful if the computation leading to the result worked
|
||||
on a different scale than is used by the results. Approx's scale is added
|
||||
to Approx's value when computing the allowed relative margin from the
|
||||
Approx's value.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -2,52 +2,63 @@
|
||||
# Compile-time configuration
|
||||
|
||||
**Contents**<br>
|
||||
[main()/ implementation](#main-implementation)<br>
|
||||
[Reporter / Listener interfaces](#reporter--listener-interfaces)<br>
|
||||
[Prefixing Catch macros](#prefixing-catch-macros)<br>
|
||||
[Terminal colour](#terminal-colour)<br>
|
||||
[Console width](#console-width)<br>
|
||||
[stdout](#stdout)<br>
|
||||
[Fallback stringifier](#fallback-stringifier)<br>
|
||||
[Default reporter](#default-reporter)<br>
|
||||
[Bazel support](#bazel-support)<br>
|
||||
[C++11 toggles](#c11-toggles)<br>
|
||||
[C++17 toggles](#c17-toggles)<br>
|
||||
[Other toggles](#other-toggles)<br>
|
||||
[Windows header clutter](#windows-header-clutter)<br>
|
||||
[Enabling stringification](#enabling-stringification)<br>
|
||||
[Disabling exceptions](#disabling-exceptions)<br>
|
||||
[Disabling deprecation warnings](#disabling-deprecation-warnings)<br>
|
||||
[Overriding Catch's debug break (`-b`)](#overriding-catchs-debug-break--b)<br>
|
||||
[Static analysis support](#static-analysis-support)<br>
|
||||
[Experimental thread safety](#experimental-thread-safety)<br>
|
||||
|
||||
Catch2 is designed to "just work" as much as possible, and most of the
|
||||
configuration options below are changed automatically during compilation,
|
||||
according to the detected environment. However, this detection can also
|
||||
be overridden by users, using macros documented below, and/or CMake options
|
||||
with the same name.
|
||||
Catch is designed to "just work" as much as possible. For most people the only configuration needed is telling Catch which source file should host all the implementation code (```CATCH_CONFIG_MAIN```).
|
||||
|
||||
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
|
||||
|
||||
CATCH_CONFIG_PREFIX_ALL // Prefix all macros with CATCH_
|
||||
CATCH_CONFIG_PREFIX_MESSAGES // Prefix only INFO, UNSCOPED_INFO, WARN and CAPTURE
|
||||
CATCH_CONFIG_PREFIX_ALL
|
||||
|
||||
To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```).
|
||||
|
||||
|
||||
## Terminal colour
|
||||
|
||||
CATCH_CONFIG_COLOUR_WIN32 // Force enables compiling colouring impl based on Win32 console API
|
||||
CATCH_CONFIG_NO_COLOUR_WIN32 // Force disables ...
|
||||
CATCH_CONFIG_COLOUR_NONE // completely disables all text colouring
|
||||
CATCH_CONFIG_COLOUR_WINDOWS // forces the Win32 console API to be used
|
||||
CATCH_CONFIG_COLOUR_ANSI // forces ANSI colour codes to be used
|
||||
|
||||
Yes, Catch2 uses the british spelling of colour.
|
||||
Yes, I am English, so I will continue to spell "colour" with a 'u'.
|
||||
|
||||
Catch2 attempts to autodetect whether the Win32 console colouring API,
|
||||
`SetConsoleTextAttribute`, is available, and if it is available it compiles
|
||||
in a console colouring implementation that uses it.
|
||||
When sending output to the terminal, if it detects that it can, Catch will use colourised text. On Windows the Win32 API, ```SetConsoleTextAttribute```, is used. On POSIX systems ANSI colour escape codes are inserted into the stream.
|
||||
|
||||
This option can be used to override Catch2's autodetection and force the
|
||||
compilation either ON or OFF.
|
||||
For finer control you can define one of the above identifiers (these are mutually exclusive - but that is not checked so may behave unexpectedly if you mix them):
|
||||
|
||||
Note that when ANSI colour codes are used "unistd.h" must be includable - along with a definition of ```isatty()```
|
||||
|
||||
Typically you should place the ```#define``` before #including "catch.hpp" in your main source file - but if you prefer you can define it for your whole project by whatever your IDE or build system provides for you to do so.
|
||||
|
||||
## Console width
|
||||
|
||||
@@ -61,7 +72,7 @@ By default a console width of 80 is assumed but this can be controlled by defini
|
||||
CATCH_CONFIG_NOSTDOUT
|
||||
|
||||
To support platforms that do not provide `std::cout`, `std::cerr` and
|
||||
`std::clog`, Catch does not use them directly, but rather calls
|
||||
`std::clog`, Catch does not usem the directly, but rather calls
|
||||
`Catch::cout`, `Catch::cerr` and `Catch::clog`. You can replace their
|
||||
implementation by defining `CATCH_CONFIG_NOSTDOUT` and implementing
|
||||
them yourself, their signatures are:
|
||||
@@ -101,20 +112,6 @@ This means that defining `CATCH_CONFIG_DEFAULT_REPORTER` to `"console"`
|
||||
is equivalent with the out-of-the-box experience.
|
||||
|
||||
|
||||
## Bazel support
|
||||
|
||||
Compiling Catch2 with `CATCH_CONFIG_BAZEL_SUPPORT` force-enables Catch2's
|
||||
support for Bazel's environment variables (normally Catch2 looks for
|
||||
`BAZEL_TEST=1` env var first).
|
||||
|
||||
This can be useful if you are using older versions of Bazel, that do not
|
||||
yet have `BAZEL_TEST` env var support.
|
||||
|
||||
> `CATCH_CONFIG_BAZEL_SUPPORT` was [introduced](https://github.com/catchorg/Catch2/pull/2399) in Catch2 3.0.1.
|
||||
|
||||
> `CATCH_CONFIG_BAZEL_SUPPORT` was [deprecated](https://github.com/catchorg/Catch2/pull/2459) in Catch2 3.1.0.
|
||||
|
||||
|
||||
## C++11 toggles
|
||||
|
||||
CATCH_CONFIG_CPP11_TO_STRING // Use `std::to_string`
|
||||
@@ -130,13 +127,13 @@ Catch's selection, by defining either `CATCH_CONFIG_CPP11_TO_STRING` or
|
||||
|
||||
## C++17 toggles
|
||||
|
||||
CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS // Override std::uncaught_exceptions (instead of std::uncaught_exception) support detection
|
||||
CATCH_CONFIG_CPP17_STRING_VIEW // Override std::string_view support detection (Catch provides a StringMaker specialization by default)
|
||||
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_VARIANT // Override std::variant support detection (checked by CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER)
|
||||
CATCH_CONFIG_CPP17_OPTIONAL // Override std::optional support detection (checked by CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER)
|
||||
CATCH_CONFIG_CPP17_BYTE // Override std::byte support detection (Catch provides a StringMaker specialization by default)
|
||||
|
||||
> `CATCH_CONFIG_CPP17_STRING_VIEW` was [introduced](https://github.com/catchorg/Catch2/issues/1376) in Catch2 2.4.1.
|
||||
> `CATCH_CONFIG_CPP17_STRING_VIEW` was [introduced](https://github.com/catchorg/Catch2/issues/1376) in Catch 2.4.1.
|
||||
|
||||
Catch contains basic compiler/standard detection and attempts to use
|
||||
some C++17 features whenever appropriate. This automatic detection
|
||||
@@ -150,36 +147,25 @@ 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_WINDOWS_SEH // Enable SEH handling on Windows
|
||||
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_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
||||
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
||||
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
||||
CATCH_CONFIG_WCHAR // Enables use of wchart_t
|
||||
CATCH_CONFIG_EXPERIMENTAL_REDIRECT // Enables the new (experimental) way of capturing stdout/stderr
|
||||
CATCH_CONFIG_ENABLE_BENCHMARKING // Enables the integrated benchmarking features (has a significant effect on compilation speed)
|
||||
CATCH_CONFIG_USE_ASYNC // Force parallel statistical processing of samples during benchmarking
|
||||
CATCH_CONFIG_ANDROID_LOGWRITE // Use android's logging system for debug output
|
||||
CATCH_CONFIG_GLOBAL_NEXTAFTER // Use nextafter{,f,l} instead of std::nextafter
|
||||
CATCH_CONFIG_GETENV // System has a working `getenv`
|
||||
CATCH_CONFIG_USE_BUILTIN_CONSTANT_P // Use __builtin_constant_p to trigger warnings
|
||||
|
||||
> [`CATCH_CONFIG_ANDROID_LOGWRITE`](https://github.com/catchorg/Catch2/issues/1743) and [`CATCH_CONFIG_GLOBAL_NEXTAFTER`](https://github.com/catchorg/Catch2/pull/1739) were introduced in Catch2 2.10.0
|
||||
|
||||
> `CATCH_CONFIG_GETENV` was [introduced](https://github.com/catchorg/Catch2/pull/2562) in Catch2 3.2.0
|
||||
|
||||
> `CATCH_CONFIG_USE_BUILTIN_CONSTANT_P` was introduced in Catch2 3.8.0
|
||||
> [`CATCH_CONFIG_ANDROID_LOGWRITE`](https://github.com/catchorg/Catch2/issues/1743) and [`CATCH_CONFIG_GLOBAL_NEXTAFTER`](https://github.com/catchorg/Catch2/pull/1739) were introduced in Catch 2.10.0
|
||||
|
||||
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
|
||||
|
||||
`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_GETENV` is on by default, except when Catch2 is compiled for
|
||||
platforms that lacks working `std::getenv` (currently Windows UWP and
|
||||
Playstation).
|
||||
|
||||
`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. This option only works when linking against the default
|
||||
main, and must be defined for the whole library build.
|
||||
`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.
|
||||
|
||||
`CATCH_CONFIG_WCHAR` is on by default, but can be disabled. Currently
|
||||
it is only used in support for DJGPP cross-compiler.
|
||||
@@ -188,12 +174,6 @@ With the exception of `CATCH_CONFIG_EXPERIMENTAL_REDIRECT`,
|
||||
these toggles can be disabled by using `_NO_` form of the toggle,
|
||||
e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
|
||||
|
||||
`CATCH_CONFIG_USE_BUILTIN_CONSTANT_P` is ON by default for Clang and GCC
|
||||
(but as far as possible, not for other compilers masquerading for these
|
||||
two). However, it can cause bugs where the enclosed code is evaluated, even
|
||||
though it should not be, e.g. in [#2925](https://github.com/catchorg/Catch2/issues/2925).
|
||||
|
||||
|
||||
### `CATCH_CONFIG_FAST_COMPILE`
|
||||
This compile-time flag speeds up compilation of assertion macros by ~20%,
|
||||
by disabling the generation of assertion-local try-catch blocks for
|
||||
@@ -204,6 +184,11 @@ should not lead to false negatives.
|
||||
`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined,
|
||||
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`
|
||||
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).
|
||||
|
||||
@@ -214,6 +199,13 @@ This feature is considered experimental and might change at any point.
|
||||
|
||||
_Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`_
|
||||
|
||||
## Windows header clutter
|
||||
|
||||
On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros:
|
||||
|
||||
CATCH_CONFIG_NO_NOMINMAX // Stops Catch from using NOMINMAX macro
|
||||
CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN // Stops Catch from using WIN32_LEAN_AND_MEAN macro
|
||||
|
||||
|
||||
## Enabling stringification
|
||||
|
||||
@@ -221,17 +213,18 @@ 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_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_OPTIONAL_STRINGMAKER // Provide StringMaker specialization for std::optional (on C++17)
|
||||
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS // Defines all of the above
|
||||
|
||||
> `CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1380) in Catch2 2.4.1.
|
||||
> `CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1380) in Catch 2.4.1.
|
||||
|
||||
> `CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1510) in Catch2 2.6.0.
|
||||
> `CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER` was [introduced](https://github.com/catchorg/Catch2/issues/1510) in Catch 2.6.0.
|
||||
|
||||
## Disabling exceptions
|
||||
|
||||
> Introduced in Catch2 2.4.0.
|
||||
> Introduced in Catch 2.4.0.
|
||||
|
||||
By default, Catch2 uses exceptions to signal errors and to abort tests
|
||||
when an assertion from the `REQUIRE` family of assertions fails. We also
|
||||
@@ -265,24 +258,9 @@ namespace Catch {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Disabling deprecation warnings
|
||||
|
||||
> Introduced in Catch2 3.9.0
|
||||
|
||||
Catch2 has started using the C++ macro `[[deprecated]]` to mark things
|
||||
that are deprecated and should not be used any more. If you need to
|
||||
temporarily disable these warnings, use
|
||||
|
||||
CATCH_CONFIG_NO_DEPRECATION_ANNOTATIONS
|
||||
|
||||
Catch2 currently does not support more fine-grained deprecation warning
|
||||
control, nor do we plan to.
|
||||
|
||||
|
||||
## Overriding Catch's debug break (`-b`)
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1846) in Catch2 2.11.2.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/1846) in Catch 2.11.2.
|
||||
|
||||
You can override Catch2's break-into-debugger code by defining the
|
||||
`CATCH_BREAK_INTO_DEBUGGER()` macro. This can be used if e.g. Catch2 does
|
||||
@@ -292,46 +270,6 @@ The macro will be used as is, that is, `CATCH_BREAK_INTO_DEBUGGER();`
|
||||
must compile and must break into debugger.
|
||||
|
||||
|
||||
## Static analysis support
|
||||
|
||||
> Introduced in Catch2 3.4.0.
|
||||
|
||||
Some parts of Catch2, e.g. `SECTION`s, can be hard for static analysis
|
||||
tools to reason about. Catch2 can change its internals to help static
|
||||
analysis tools reason about the tests.
|
||||
|
||||
Catch2 automatically detects some static analysis tools (initial
|
||||
implementation checks for clang-tidy and Coverity), but you can override
|
||||
its detection (in either direction) via
|
||||
|
||||
```
|
||||
CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT // force enables static analysis help
|
||||
CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT // force disables static analysis help
|
||||
```
|
||||
|
||||
_As the name suggests, this is currently experimental, and thus we provide
|
||||
no backwards compatibility guarantees._
|
||||
|
||||
**DO NOT ENABLE THIS FOR BUILDS YOU INTEND TO RUN.** The changed internals
|
||||
are not meant to be runnable, only "scannable".
|
||||
|
||||
|
||||
## Experimental thread safety
|
||||
|
||||
> Introduced in Catch2 3.9.0
|
||||
|
||||
Catch2 can optionally support thread-safe assertions, that means, multiple
|
||||
user-spawned threads can use the assertion macros at the same time. Due
|
||||
to the performance cost this imposes even on single-threaded usage, Catch2
|
||||
defaults to non-thread-safe assertions.
|
||||
|
||||
CATCH_CONFIG_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS // enables thread safe assertions
|
||||
CATCH_CONFIG_NO_EXPERIMENTAL_THREAD_SAFE_ASSERTIONS // force-disables thread safe assertions
|
||||
|
||||
See [the documentation on thread safety in Catch2](thread-safety.md#top)
|
||||
for details on which macros are safe and other notes.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
@@ -21,17 +21,17 @@ to the codebase itself.
|
||||
|
||||
## Using Git(Hub)
|
||||
|
||||
Ongoing development happens in the `devel` branch for Catch2 v3, and in
|
||||
`v2.x` for maintenance updates to the v2 versions.
|
||||
Ongoing development happens in the `master` branch for Catch2 v2, and in
|
||||
`dev-v3` for the next major version, v3.
|
||||
|
||||
Commits should be small and atomic. A commit is atomic when, after it is
|
||||
applied, the codebase, tests and all, still works as expected. Small
|
||||
commits are also preferred, as they make later operations with git history,
|
||||
commits are also prefered, as they make later operations with git history,
|
||||
whether it is bisecting, reverting, or something else, easier.
|
||||
|
||||
_When submitting a pull request please do not include changes to the
|
||||
amalgamated distribution files. This means do not include them in your
|
||||
git commits!_
|
||||
single include. This means do not include them in your git commits!_
|
||||
|
||||
|
||||
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,
|
||||
@@ -55,15 +55,6 @@ tests from `SelfTest` through a specific reporter and then compare the
|
||||
generated output with a known good output ("Baseline"). By default, new
|
||||
tests should be placed here.
|
||||
|
||||
To configure a Catch2 build with just the basic tests, use the `basic-tests`
|
||||
preset, like so:
|
||||
|
||||
```
|
||||
# Assuming you are in Catch2's root folder
|
||||
|
||||
cmake -B basic-test-build -S . -DCMAKE_BUILD_TYPE=Debug --preset basic-tests
|
||||
```
|
||||
|
||||
However, not all tests can be written as plain unit tests. For example,
|
||||
checking that Catch2 orders tests randomly when asked to, and that this
|
||||
random ordering is subset-invariant, is better done as an integration
|
||||
@@ -71,60 +62,42 @@ test using an external check script. Catch2 integration tests are written
|
||||
using CTest, either as a direct command invocation + pass/fail regex,
|
||||
or by delegating the check to a Python script.
|
||||
|
||||
Catch2 is slowly gaining more and more types of tests, currently Catch2
|
||||
project also has buildable examples, "ExtraTests", and CMake config tests.
|
||||
Examples present a small and self-contained snippets of code that
|
||||
use Catch2's facilities for specific purpose. Currently they are assumed
|
||||
passing if they compile.
|
||||
There are also two more kinds of tests, examples and "ExtraTests".
|
||||
Examples serve as a compilation test on the single-header distribution,
|
||||
and present a small and self-contained snippets of using Catch2 for
|
||||
writing tests. ExtraTests then are tests that either take a long time
|
||||
to run, or require separate compilation, e.g. because of testing compile
|
||||
time configuration options, and take a long time because of that.
|
||||
|
||||
ExtraTests then are expensive tests, that we do not want to run all the
|
||||
time. This can be either because they take a long time to run, or because
|
||||
they take a long time to compile, e.g. 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`.
|
||||
|
||||
Finally, CMake config tests test that you set Catch2's compile-time
|
||||
configuration options through CMake, using CMake options of the same name.
|
||||
Examples and ExtraTests are not compiled by default. To compile them,
|
||||
add `-DCATCH_BUILD_EXAMPLES=ON` and `-DCATCH_BUILD_EXTRA_TESTS=ON` to
|
||||
the invocation of CMake configuration step.
|
||||
|
||||
These test categories can be enabled one by one, by passing
|
||||
`-DCATCH_BUILD_EXAMPLES=ON`, `-DCATCH_BUILD_EXTRA_TESTS=ON`, and
|
||||
`-DCATCH_ENABLE_CONFIGURE_TESTS=ON` when configuring the build.
|
||||
Bringing this all together, the steps below should configure, build,
|
||||
and run all tests in the `Debug` compilation.
|
||||
|
||||
Catch2 also provides a preset that promises to enable _all_ test types,
|
||||
`all-tests`.
|
||||
|
||||
The snippet below will build & run all tests, in `Debug` compilation mode.
|
||||
|
||||
<!-- snippet: catch2-build-and-test -->
|
||||
<a id='snippet-catch2-build-and-test'></a>
|
||||
```sh
|
||||
# 1. Regenerate the amalgamated distribution (some tests are built against it)
|
||||
./tools/scripts/generateAmalgamatedFiles.py
|
||||
|
||||
# 2. Configure the full test build
|
||||
cmake -B debug-build -S . -DCMAKE_BUILD_TYPE=Debug --preset all-tests
|
||||
|
||||
# 3. Run the actual build
|
||||
cmake --build debug-build
|
||||
|
||||
# 4. Run the tests using CTest
|
||||
ctest -j 4 --output-on-failure -C Debug --test-dir debug-build
|
||||
1. Regenerate the single header distribution
|
||||
```
|
||||
<sup><a href='/tools/scripts/buildAndTest.sh#L6-L19' title='File snippet `catch2-build-and-test` was extracted from'>snippet source</a> | <a href='#snippet-catch2-build-and-test' title='Navigate to start of snippet `catch2-build-and-test`'>anchor</a></sup>
|
||||
<!-- endSnippet -->
|
||||
|
||||
For convenience, the above commands are in the script `tools/scripts/buildAndTest.sh`, and can be run like this:
|
||||
|
||||
```bash
|
||||
cd Catch2
|
||||
./tools/scripts/buildAndTest.sh
|
||||
$ cd Catch2
|
||||
$ ./scripts/generateSingleHeader.py
|
||||
```
|
||||
2. Configure the full test build
|
||||
```
|
||||
$ cmake -Bdebug-build -H. -DCMAKE_BUILD_TYPE=Debug -DCATCH_BUILD_EXAMPLES=ON -DCATCH_BUILD_EXTRA_TESTS=ON
|
||||
```
|
||||
3. Run the actual build
|
||||
```
|
||||
$ cmake --build debug-build
|
||||
```
|
||||
4. Run the tests using CTest
|
||||
```
|
||||
$ cd debug-build
|
||||
$ ctest -j 4 --output-on-failure -C Debug
|
||||
```
|
||||
|
||||
A Windows version of the script is available at `tools\scripts\buildAndTest.cmd`.
|
||||
|
||||
If you added new tests, you will likely see `ApprovalTests` failure.
|
||||
After you check that the output difference is expected, you should
|
||||
run `tools/scripts/approve.py` to confirm them, and include these changes
|
||||
in your commit.
|
||||
|
||||
|
||||
## Writing documentation
|
||||
@@ -134,8 +107,7 @@ other people can use it as well. This section collects some technical
|
||||
information that you will need for updating Catch2's documentation, and
|
||||
possibly some generic advise as well.
|
||||
|
||||
|
||||
### Technicalities
|
||||
### Technicalities
|
||||
|
||||
First, the technicalities:
|
||||
|
||||
@@ -146,8 +118,6 @@ should use. It provides you with the top anchor mentioned to link to
|
||||
<a id="top"></a>
|
||||
# Cool feature
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/123456) in Catch2 X.Y.Z
|
||||
|
||||
Text that explains how to use the cool feature.
|
||||
|
||||
|
||||
@@ -166,9 +136,9 @@ be replaced with the actual version upon release. There are 2 styles
|
||||
of placeholders used through the documentation, you should pick one that
|
||||
fits your text better (if in doubt, take a look at the existing version
|
||||
tags for other features).
|
||||
* `> [Introduced](link-to-issue-or-PR) in Catch2 X.Y.Z` - this
|
||||
* `> [Introduced](link-to-issue-or-PR) in Catch X.Y.Z` - this
|
||||
placeholder is usually used after a section heading
|
||||
* `> X (Y and Z) was [introduced](link-to-issue-or-PR) in Catch2 X.Y.Z`
|
||||
* `> X (Y and Z) was [introduced](link-to-issue-or-PR) in Catch X.Y.Z`
|
||||
- this placeholder is used when you need to tag a subpart of something,
|
||||
e.g. a list
|
||||
|
||||
@@ -209,24 +179,6 @@ If want to contribute code, this section contains some simple rules
|
||||
and tips on things like code formatting, code constructions to avoid,
|
||||
and so on.
|
||||
|
||||
### C++ standard version
|
||||
|
||||
Catch2 currently targets C++14 as the minimum supported C++ version.
|
||||
Features from higher language versions should be used only sparingly,
|
||||
when the benefits from using them outweigh the maintenance overhead.
|
||||
|
||||
Example of good use of polyfilling features is our use of `conjunction`,
|
||||
where if available we use `std::conjunction` and otherwise provide our
|
||||
own implementation. The reason it is good is that the surface area for
|
||||
maintenance is quite small, and `std::conjunction` can directly use
|
||||
compiler built-ins, thus providing significant compilation benefits.
|
||||
|
||||
Example of bad use of polyfilling features would be to keep around two
|
||||
sets of metaprogramming in the stringification implementation, once
|
||||
using C++14 compliant TMP and once using C++17's `if constexpr`. While
|
||||
the C++17 would provide significant compilation speedups, the maintenance
|
||||
cost would be too high.
|
||||
|
||||
|
||||
### Formatting
|
||||
|
||||
@@ -247,7 +199,7 @@ are problematic and are not always caught by our CI infrastructure.
|
||||
#### Naked exceptions and exceptions-related function
|
||||
|
||||
If you are throwing an exception, it should be done via `CATCH_ERROR`
|
||||
or `CATCH_RUNTIME_ERROR` in `internal/catch_enforce.hpp`. These macros will handle
|
||||
or `CATCH_RUNTIME_ERROR` in `catch_enforce.h`. These macros will handle
|
||||
the differences between compilation with or without exceptions for you.
|
||||
However, some platforms (IAR) also have problems with exceptions-related
|
||||
functions, such as `std::current_exceptions`. We do not have IAR in our
|
||||
@@ -256,18 +208,6 @@ However, if you do, they should be kept behind a
|
||||
`CATCH_CONFIG_DISABLE_EXCEPTIONS` macro.
|
||||
|
||||
|
||||
#### Avoid `std::move` and `std::forward`
|
||||
|
||||
`std::move` and `std::forward` provide nice semantic name for a specific
|
||||
`static_cast`. However, being function templates they have surprisingly
|
||||
high cost during compilation, and can also have a negative performance
|
||||
impact for low-optimization builds.
|
||||
|
||||
You should be using `CATCH_MOVE` and `CATCH_FORWARD` macros from
|
||||
`internal/catch_move_and_forward.hpp` instead. They expand into the proper
|
||||
`static_cast`, and avoid the overhead of `std::move` and `std::forward`.
|
||||
|
||||
|
||||
#### Unqualified usage of functions from C's stdlib
|
||||
|
||||
If you are using a function from C's stdlib, please include the header
|
||||
@@ -276,57 +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.
|
||||
|
||||
|
||||
#### User-Defined Literals (UDL) for Catch2' types
|
||||
|
||||
Due to messy standardese and ... not great ... implementation of
|
||||
`-Wreserved-identifier` in Clang, avoid declaring UDLs as
|
||||
```cpp
|
||||
Approx operator "" _a(long double);
|
||||
```
|
||||
and instead declare them as
|
||||
```cpp
|
||||
Approx operator ""_a(long double);
|
||||
```
|
||||
|
||||
Notice that the second version does not have a space between the `""` and
|
||||
the literal suffix.
|
||||
|
||||
|
||||
|
||||
### New source file template
|
||||
|
||||
If you are adding new source file, there is a template you should use.
|
||||
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.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.hpp`, the include guard should
|
||||
be `CATCH_MATCHERS_FOO_HPP_INCLUDED`, for `catch_generators_bar.hpp`, the include
|
||||
guard should be `CATCH_GENERATORS_BAR_HPP_INCLUDED`, and so on.
|
||||
|
||||
|
||||
### Adding new `CATCH_CONFIG` option
|
||||
|
||||
When adding new `CATCH_CONFIG` option, there are multiple places to edit:
|
||||
* `CMake/CatchConfigOptions.cmake` - this is used to generate the
|
||||
configuration options in CMake, so that CMake frontends know about them.
|
||||
* `docs/configuration.md` - this is where the options are documented
|
||||
* `src/catch2/catch_user_config.hpp.in` - this is template for generating
|
||||
`catch_user_config.hpp` which contains the materialized configuration
|
||||
* `BUILD.bazel` - Bazel does not have configuration support like CMake,
|
||||
and all expansions need to be done manually
|
||||
* other files as needed, e.g. `catch2/internal/catch_config_foo.hpp`
|
||||
for the logic that guards the configuration
|
||||
|
||||
|
||||
## CoC
|
||||
|
||||
This project has a [CoC](../CODE_OF_CONDUCT.md). Please adhere to it
|
||||
|
@@ -9,43 +9,127 @@ either of these is a breaking change, and thus will not happen until
|
||||
at least the next major release.
|
||||
|
||||
|
||||
### `ParseAndAddCatchTests.cmake`
|
||||
## Deprecations
|
||||
|
||||
The CMake/CTest integration using `ParseAndAddCatchTests.cmake` is deprecated,
|
||||
as it can be replaced by `Catch.cmake` that provides the function
|
||||
`catch_discover_tests` to get tests directly from a CMake target via the
|
||||
command line interface instead of parsing C++ code with regular expressions.
|
||||
### `--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.
|
||||
|
||||
|
||||
### `CATCH_CONFIG_BAZEL_SUPPORT`
|
||||
### `--list-test-names-only`
|
||||
|
||||
Catch2 supports writing the Bazel JUnit XML output file when it is aware
|
||||
that is within a bazel testing environment. Originally there was no way
|
||||
to accurately probe the environment for this information so the flag
|
||||
`CATCH_CONFIG_BAZEL_SUPPORT` was added. This now deprecated. Bazel has now had a change
|
||||
where it will export `BAZEL_TEST=1` for purposes like the above. Catch2
|
||||
will now instead inspect the environment instead of relying on build configuration.
|
||||
|
||||
### `IEventLister::skipTest( TestCaseInfo const& testInfo )`
|
||||
|
||||
This event (including implementations in derived classes such as `ReporterBase`)
|
||||
is deprecated and will be removed in the next major release. It is currently
|
||||
invoked for all test cases that are not going to be executed due to the test run
|
||||
being aborted (when using `--abort` or `--abortx`). It is however
|
||||
**NOT** invoked for test cases that are [explicitly skipped using the `SKIP`
|
||||
macro](skipping-passing-failing.md#top).
|
||||
`--list-test-names-only` command line argument will be removed.
|
||||
|
||||
|
||||
### Non-const function for `TEST_CASE_METHOD`
|
||||
### `ANON_TEST_CASE`
|
||||
|
||||
> Deprecated in Catch2 3.7.0
|
||||
`ANON_TEST_CASE` is scheduled for removal, as it can be fully replaced
|
||||
by a `TEST_CASE` with no arguments.
|
||||
|
||||
Currently, the member function generated for `TEST_CASE_METHOD` is
|
||||
not `const` qualified. In the future, the generated member function will
|
||||
be `const` qualified, just as `TEST_CASE_PERSISTENT_FIXTURE` does.
|
||||
|
||||
If you are mutating the fixture instance from within the test case, and
|
||||
want to keep doing so in the future, mark the mutated members as `mutable`.
|
||||
### 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
|
||||
|
||||
|
||||
### 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`
|
||||
|
||||
To make the `CHECKED_IF` and `CHECKED_ELSE` macros more useful, they will
|
||||
be marked as "OK to fail" (`Catch::ResultDisposition::SuppressFail` flag
|
||||
will be added), which means that their failure will not fail the test,
|
||||
making the `else` actually useful.
|
||||
|
||||
|
||||
### 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
|
||||
|
||||
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.
|
||||
|
||||
|
||||
### 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.
|
||||
|
||||
|
||||
---
|
||||
|
@@ -1,43 +1,74 @@
|
||||
<a id="top"></a>
|
||||
# Event Listeners
|
||||
|
||||
An event listener is a bit like a reporter, in that it responds to various
|
||||
reporter events in Catch2, but it is not expected to write any output.
|
||||
Instead, an event listener performs actions within the test process, such
|
||||
as performing global initialization (e.g. of a C library), or cleaning out
|
||||
in-memory logs if they are not needed (the test case passed).
|
||||
A `Listener` is a class you can register with Catch that will then be passed events,
|
||||
such as a test case starting or ending, as they happen during a test run.
|
||||
`Listeners` are actually types of `Reporters`, with a few small differences:
|
||||
|
||||
1. Once registered in code they are automatically used - you don't need to specify them on the command line
|
||||
2. They are called in addition to (just before) any reporters, and you can register multiple listeners.
|
||||
3. They derive from `Catch::TestEventListenerBase`, which has default stubs for all the events,
|
||||
so you are not forced to implement events you're not interested in.
|
||||
4. You register a listener with `CATCH_REGISTER_LISTENER`
|
||||
|
||||
Unlike reporters, each registered event listener is always active. Event
|
||||
listeners are always notified before reporter(s).
|
||||
|
||||
To write your own event listener, you should derive from `Catch::TestEventListenerBase`,
|
||||
as it provides empty stubs for all reporter events, allowing you to
|
||||
only override events you care for. Afterwards you have to register it
|
||||
with Catch2 using `CATCH_REGISTER_LISTENER` macro, so that Catch2 knows
|
||||
about it and instantiates it before running tests.
|
||||
## Implementing a Listener
|
||||
Simply derive a class from `Catch::TestEventListenerBase` and implement the methods you are interested in, either in
|
||||
the main source file (i.e. the one that defines `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`), or in a
|
||||
file that defines `CATCH_CONFIG_EXTERNAL_INTERFACES`.
|
||||
|
||||
Example event listener:
|
||||
```cpp
|
||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
Then register it using `CATCH_REGISTER_LISTENER`.
|
||||
|
||||
class testRunListener : public Catch::EventListenerBase {
|
||||
public:
|
||||
using Catch::EventListenerBase::EventListenerBase;
|
||||
For example ([complete source code](../examples/210-Evt-EventListeners.cpp)):
|
||||
|
||||
void testRunStarting(Catch::TestRunInfo const&) override {
|
||||
lib_foo_init();
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
struct MyListener : Catch::TestEventListenerBase {
|
||||
|
||||
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
|
||||
|
||||
void testCaseStarting( Catch::TestCaseInfo const& testInfo ) override {
|
||||
// Perform some setup before a test case is run
|
||||
}
|
||||
|
||||
void testCaseEnded( Catch::TestCaseStats const& testCaseStats ) override {
|
||||
// Tear-down after a test case is run
|
||||
}
|
||||
};
|
||||
|
||||
CATCH_REGISTER_LISTENER(testRunListener)
|
||||
CATCH_REGISTER_LISTENER( MyListener )
|
||||
```
|
||||
|
||||
_Note that you should not use any assertion macros within a Listener!_
|
||||
_Note that you should not use any assertion macros within a Listener!_
|
||||
|
||||
[You can find the list of events that the listeners can react to on its
|
||||
own page](reporter-events.md#top).
|
||||
## Events that can be hooked
|
||||
|
||||
The following are the methods that can be overridden in the Listener:
|
||||
|
||||
```c++
|
||||
// The whole test run, starting and ending
|
||||
virtual void testRunStarting( TestRunInfo const& testRunInfo );
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats );
|
||||
|
||||
// Test cases starting and ending
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo );
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats );
|
||||
|
||||
// Sections starting and ending
|
||||
virtual void sectionStarting( SectionInfo const& sectionInfo );
|
||||
virtual void sectionEnded( SectionStats const& sectionStats );
|
||||
|
||||
// Assertions before/ after
|
||||
virtual void assertionStarting( AssertionInfo const& assertionInfo );
|
||||
virtual bool assertionEnded( AssertionStats const& assertionStats );
|
||||
|
||||
// A test is being skipped (because it is "hidden")
|
||||
virtual void skipTest( TestCaseInfo const& testInfo );
|
||||
```
|
||||
|
||||
More information about the events (e.g. name of the test case) is contained in the structs passed as arguments -
|
||||
just look in the source code to see what fields are available.
|
||||
|
||||
---
|
||||
|
||||
|
113
docs/faq.md
@@ -1,113 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Frequently Asked Questions (FAQ)
|
||||
|
||||
**Contents**<br>
|
||||
[How do I run global setup/teardown only if tests will be run?](#how-do-i-run-global-setupteardown-only-if-tests-will-be-run)<br>
|
||||
[How do I clean up global state between running different tests?](#how-do-i-clean-up-global-state-between-running-different-tests)<br>
|
||||
[Why cannot I derive from the built-in reporters?](#why-cannot-i-derive-from-the-built-in-reporters)<br>
|
||||
[What is Catch2's ABI stability policy?](#what-is-catch2s-abi-stability-policy)<br>
|
||||
[What is Catch2's API stability policy?](#what-is-catch2s-api-stability-policy)<br>
|
||||
[Does Catch2 support running tests in parallel?](#does-catch2-support-running-tests-in-parallel)<br>
|
||||
[Can I compile Catch2 into a dynamic library?](#can-i-compile-catch2-into-a-dynamic-library)<br>
|
||||
[What repeatability guarantees does Catch2 provide?](#what-repeatability-guarantees-does-catch2-provide)<br>
|
||||
[My build cannot find `catch2/catch_user_config.hpp`, how can I fix it?](#my-build-cannot-find-catch2catch_user_confighpp-how-can-i-fix-it)<br>
|
||||
|
||||
|
||||
## How do I run global setup/teardown only if tests will be run?
|
||||
|
||||
Write a custom [event listener](event-listeners.md#top) and place the
|
||||
global setup/teardown code into the `testRun*` events.
|
||||
|
||||
|
||||
## How do I clean up global state between running different tests?
|
||||
|
||||
Write a custom [event listener](event-listeners.md#top) and place the
|
||||
cleanup code into either `testCase*` or `testCasePartial*` events,
|
||||
depending on how often the cleanup needs to happen.
|
||||
|
||||
|
||||
## Why cannot I derive from the built-in reporters?
|
||||
|
||||
They are not made to be overridden, in that we do not attempt to maintain
|
||||
a consistent internal state if a member function is overridden, and by
|
||||
forbidding users from using them as a base class, we can refactor them
|
||||
as needed later.
|
||||
|
||||
|
||||
## What is Catch2's ABI stability policy?
|
||||
|
||||
Catch2 provides no ABI stability guarantees whatsoever. Catch2 provides
|
||||
rich C++ interface, and trying to freeze its ABI would take a lot of
|
||||
pointless work.
|
||||
|
||||
Catch2 is not designed to be distributed as dynamic library, and you
|
||||
should really be able to compile everything with the same compiler binary.
|
||||
|
||||
|
||||
## What is Catch2's API stability policy?
|
||||
|
||||
Catch2 follows [semver](https://semver.org/) to the best of our ability.
|
||||
This means that we will not knowingly make backwards-incompatible changes
|
||||
without incrementing the major version number.
|
||||
|
||||
|
||||
## Does Catch2 support running tests in parallel?
|
||||
|
||||
Not natively, no. We see running tests in parallel as the job of an
|
||||
external test runner, that can also run them in separate processes,
|
||||
support test execution timeouts and so on.
|
||||
|
||||
However, Catch2 provides some tools that make the job of external test
|
||||
runners easier. [See the relevant section in our page on best
|
||||
practices](usage-tips.md#parallel-tests).
|
||||
|
||||
|
||||
## Can I compile Catch2 into a dynamic library?
|
||||
|
||||
Yes, Catch2 supports the [standard CMake `BUILD_SHARED_LIBS`
|
||||
option](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html).
|
||||
However, the dynamic library support is provided as-is. Catch2 does not
|
||||
provide API export annotations, and so you can only use it as a dynamic
|
||||
library on platforms that default to public visibility, or with tooling
|
||||
support to force export Catch2's API.
|
||||
|
||||
|
||||
## What repeatability guarantees does Catch2 provide?
|
||||
|
||||
There are two places where it is meaningful to talk about Catch2's
|
||||
repeatability guarantees without taking into account user-provided
|
||||
code. First one is in the test case shuffling, and the second one is
|
||||
the output from random generators.
|
||||
|
||||
Test case shuffling is repeatable across different platforms since v2.12.0,
|
||||
and it is also generally repeatable across versions, but we might break
|
||||
it from time to time. E.g. we broke repeatability with previous versions
|
||||
in v2.13.4 so that test cases with similar names are shuffled better.
|
||||
|
||||
Since Catch2 3.5.0 the random generators use custom distributions,
|
||||
that should be repeatable across different platforms, with few caveats.
|
||||
For details see the section on random generators in the [Generator
|
||||
documentation](generators.md#random-number-generators-details).
|
||||
|
||||
Before this version, random generators relied on distributions from
|
||||
platform's stdlib. We thus can provide no extra guarantee on top of the
|
||||
ones given by your platform. **Important: `<random>`'s distributions
|
||||
are not specified to be repeatable across different platforms.**
|
||||
|
||||
|
||||
## My build cannot find `catch2/catch_user_config.hpp`, how can I fix it?
|
||||
|
||||
`catch2/catch_user_config.hpp` is a generated header that contains user
|
||||
compile time configuration. It is generated by CMake/Meson/Bazel during
|
||||
build. If you are not using either of these, your three options are to
|
||||
|
||||
1) Build Catch2 separately using build tool that will generate the header
|
||||
2) Use the amalgamated files to build Catch2
|
||||
3) Use CMake to configure a build. This will generate the header and you
|
||||
can copy it into your own checkout of Catch2.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -1,7 +1,7 @@
|
||||
<a id="top"></a>
|
||||
# Data Generators
|
||||
|
||||
> Introduced in Catch2 2.6.0.
|
||||
> Introduced in Catch 2.6.0.
|
||||
|
||||
Data generators (also known as _data driven/parametrized test cases_)
|
||||
let you reuse the same set of assertions across different input values.
|
||||
@@ -21,10 +21,7 @@ The "Generators" `TEST_CASE` will be entered 3 times, and the value of
|
||||
`i` will be 1, 3, and 5 in turn. `GENERATE`s can also be used multiple
|
||||
times at the same scope, in which case the result will be a cartesian
|
||||
product of all elements in the generators. This means that in the snippet
|
||||
below, the test case will be run 6 (2\*3) times. The `GENERATE` macro
|
||||
is defined in the `catch_generators.hpp` header, so compiling
|
||||
the code examples below also requires
|
||||
`#include <catch2/generators/catch_generators.hpp>`.
|
||||
below, the test case will be run 6 (2\*3) times.
|
||||
|
||||
```cpp
|
||||
TEST_CASE("Generators") {
|
||||
@@ -45,7 +42,7 @@ that allows users to implement their own generators.
|
||||
effects. The simplest usage is shown below, where the `SECTION` "one"
|
||||
runs 4 (2\*2) times, and `SECTION` "two" is run 6 times (2\*3).
|
||||
|
||||
```cpp
|
||||
```
|
||||
TEST_CASE("Generators") {
|
||||
auto i = GENERATE(1, 2);
|
||||
SECTION("one") {
|
||||
@@ -54,7 +51,7 @@ TEST_CASE("Generators") {
|
||||
}
|
||||
SECTION("two") {
|
||||
auto k = GENERATE(4, 5, 6);
|
||||
REQUIRE(i != k);
|
||||
REQUIRE(j != k);
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -95,7 +92,7 @@ TEST_CASE("Complex mix of sections and generates") {
|
||||
}
|
||||
```
|
||||
|
||||
> The ability to place `GENERATE` between two `SECTION`s was [introduced](https://github.com/catchorg/Catch2/issues/1938) in Catch2 2.13.0.
|
||||
> The ability to place `GENERATE` between two `SECTION`s was [introduced](https://github.com/catchorg/Catch2/issues/1938) in Catch 2.13.0.
|
||||
|
||||
## Provided generators
|
||||
|
||||
@@ -106,7 +103,7 @@ a test case,
|
||||
* 2 fundamental generators
|
||||
* `SingleValueGenerator<T>` -- contains only single element
|
||||
* `FixedValuesGenerator<T>` -- contains multiple elements
|
||||
* 5 generic generators that modify other generators (defined in `catch2/generators/catch_generators_adapters.hpp`)
|
||||
* 5 generic generators that modify other generators
|
||||
* `FilterGenerator<T, Predicate>` -- filters out elements from a generator
|
||||
for which the predicate returns "false"
|
||||
* `TakeGenerator<T>` -- takes first `n` elements from a generator
|
||||
@@ -114,16 +111,15 @@ a test case,
|
||||
* `MapGenerator<T, U, Func>` -- returns the result of applying `Func`
|
||||
on elements from a different generator
|
||||
* `ChunkGenerator<T>` -- returns chunks (inside `std::vector`) of n elements from a generator
|
||||
* 2 random generators (defined in `catch2/generators/catch_generators_random.hpp`)
|
||||
* 4 specific purpose generators
|
||||
* `RandomIntegerGenerator<Integral>` -- generates random Integrals from range
|
||||
* `RandomFloatGenerator<Float>` -- generates random Floats from range
|
||||
* 2 range generators (defined in `catch2/generators/catch_generators_range.hpp`)
|
||||
* `RangeGenerator<T>(first, last)` -- generates all values inside a `[first, last)` arithmetic range
|
||||
* `RangeGenerator<T>` -- generates all values inside an arithmetic range
|
||||
* `IteratorGenerator<T>` -- copies and returns values from an iterator range
|
||||
|
||||
> `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch2 2.7.0.
|
||||
> `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch 2.7.0.
|
||||
|
||||
> `IteratorGenerator<T>` was introduced in Catch2 2.10.0.
|
||||
> `IteratorGenerator<T>` was introduced in Catch 2.10.0.
|
||||
|
||||
The generators also have associated helper functions that infer their
|
||||
type, making their usage much nicer. These are
|
||||
@@ -138,16 +134,16 @@ type, making their usage much nicer. These are
|
||||
* `map<T>(func, GeneratorWrapper<U>&&)` for `MapGenerator<T, U, Func>` (map `U` to `T`)
|
||||
* `chunk(chunk-size, GeneratorWrapper<T>&&)` for `ChunkGenerator<T>`
|
||||
* `random(IntegerOrFloat a, IntegerOrFloat b)` for `RandomIntegerGenerator` or `RandomFloatGenerator`
|
||||
* `range(Arithmetic start, Arithmetic end)` for `RangeGenerator<Arithmetic>` with a step size of `1`
|
||||
* `range(Arithemtic start, Arithmetic end)` for `RangeGenerator<Arithmetic>` with a step size of `1`
|
||||
* `range(Arithmetic start, Arithmetic end, Arithmetic step)` for `RangeGenerator<Arithmetic>` with a custom step size
|
||||
* `from_range(InputIterator from, InputIterator to)` for `IteratorGenerator<T>`
|
||||
* `from_range(Container const&)` for `IteratorGenerator<T>`
|
||||
|
||||
> `chunk()`, `random()` and both `range()` functions were introduced in Catch2 2.7.0.
|
||||
> `chunk()`, `random()` and both `range()` functions were introduced in Catch 2.7.0.
|
||||
|
||||
> `from_range` has been introduced in Catch2 2.10.0
|
||||
> `from_range` has been introduced in Catch 2.10.0
|
||||
|
||||
> `range()` for floating point numbers has been introduced in Catch2 2.11.0
|
||||
> `range()` for floating point numbers has been introduced in Catch 2.11.0
|
||||
|
||||
And can be used as shown in the example below to create a generator
|
||||
that returns 100 odd random number:
|
||||
@@ -180,7 +176,7 @@ scope and thus capturing references is dangerous. If you need to use
|
||||
variables inside the generator expression, make sure you thought through
|
||||
the lifetime implications and use `GENERATE_COPY` or `GENERATE_REF`.**
|
||||
|
||||
> `GENERATE_COPY` and `GENERATE_REF` were introduced in Catch2 2.7.1.
|
||||
> `GENERATE_COPY` and `GENERATE_REF` were introduced in Catch 2.7.1.
|
||||
|
||||
You can also override the inferred type by using `as<type>` as the first
|
||||
argument to the macro. This can be useful when dealing with string literals,
|
||||
@@ -193,45 +189,6 @@ TEST_CASE("type conversion", "[generators]") {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Random number generators: details
|
||||
|
||||
> This section applies from Catch2 3.5.0. Before that, random generators
|
||||
> were a thin wrapper around distributions from `<random>`.
|
||||
|
||||
All of the `random(a, b)` generators in Catch2 currently generate uniformly
|
||||
distributed number in closed interval \[a; b\]. This is different from
|
||||
`std::uniform_real_distribution`, which should return numbers in interval
|
||||
\[a; b) (but due to rounding can end up returning b anyway), but the
|
||||
difference is intentional, so that `random(a, a)` makes sense. If there is
|
||||
enough interest from users, we can provide API to pick any of CC, CO, OC,
|
||||
or OO ranges.
|
||||
|
||||
Unlike `std::uniform_int_distribution`, Catch2's generators also support
|
||||
various single-byte integral types, such as `char` or `bool`.
|
||||
|
||||
|
||||
#### Reproducibility
|
||||
|
||||
Given the same seed, the output from the integral generators is fully
|
||||
reproducible across different platforms.
|
||||
|
||||
For floating point generators, the situation is much more complex.
|
||||
Generally Catch2 only promises reproducibility (or even just correctness!)
|
||||
on platforms that obey the IEEE-754 standard. Furthermore, reproducibility
|
||||
only applies between binaries that perform floating point math in the
|
||||
same way, e.g. if you compile a binary targeting the x87 FPU and another
|
||||
one targeting SSE2 for floating point math, their results will vary.
|
||||
Similarly, binaries compiled with compiler flags that relax the IEEE-754
|
||||
adherence, e.g. `-ffast-math`, might provide different results than those
|
||||
compiled for strict IEEE-754 adherence.
|
||||
|
||||
Finally, we provide zero guarantees on the reproducibility of generating
|
||||
`long double`s, as the internals of `long double` varies across different
|
||||
platforms.
|
||||
|
||||
|
||||
|
||||
## Generator interface
|
||||
|
||||
You can also implement your own generators, by deriving from the
|
||||
@@ -248,37 +205,15 @@ struct IGenerator : GeneratorUntypedBase {
|
||||
// Precondition:
|
||||
// The generator is either freshly constructed or the last call to next() returned true
|
||||
virtual T const& get() const = 0;
|
||||
|
||||
// Returns user-friendly string showing the current generator element
|
||||
// Does not have to be overridden, IGenerator provides default implementation
|
||||
virtual std::string stringifyImpl() const;
|
||||
};
|
||||
```
|
||||
|
||||
However, to be able to use your custom generator inside `GENERATE`, it
|
||||
will need to be wrapped inside a `GeneratorWrapper<T>`.
|
||||
`GeneratorWrapper<T>` is a value wrapper around a
|
||||
`Catch::Detail::unique_ptr<IGenerator<T>>`.
|
||||
`std::unique_ptr<IGenerator<T>>`.
|
||||
|
||||
For full example of implementing your own generator, look into Catch2's
|
||||
examples, specifically
|
||||
[Generators: Create your own generator](../examples/300-Gen-OwnGenerator.cpp).
|
||||
|
||||
|
||||
### Handling empty generators
|
||||
|
||||
The generator interface assumes that a generator always has at least one
|
||||
element. This is not always true, e.g. if the generator depends on an external
|
||||
datafile, the file might be missing.
|
||||
|
||||
There are two ways to handle this, depending on whether you want this
|
||||
to be an error or not.
|
||||
|
||||
* If empty generator **is** an error, throw an exception in constructor.
|
||||
* If empty generator **is not** an error, use the [`SKIP`](skipping-passing-failing.md#skipping-test-cases-at-runtime) in constructor.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
||||
|
@@ -57,60 +57,76 @@ again.
|
||||
## Features
|
||||
This section outlines some missing features, what is their status and their possible workarounds.
|
||||
|
||||
### Thread safe assertions
|
||||
Catch2's assertion macros are not thread safe. This does not mean that
|
||||
you cannot use threads inside Catch's test, but that only single thread
|
||||
can interact with Catch's assertions and other macros.
|
||||
|
||||
This means that this is ok
|
||||
```cpp
|
||||
std::vector<std::thread> threads;
|
||||
std::atomic<int> cnt{ 0 };
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
threads.emplace_back([&]() {
|
||||
++cnt; ++cnt; ++cnt; ++cnt;
|
||||
});
|
||||
}
|
||||
for (auto& t : threads) { t.join(); }
|
||||
REQUIRE(cnt == 16);
|
||||
```
|
||||
because only one thread passes the `REQUIRE` macro and this is not
|
||||
```cpp
|
||||
std::vector<std::thread> threads;
|
||||
std::atomic<int> cnt{ 0 };
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
threads.emplace_back([&]() {
|
||||
++cnt; ++cnt; ++cnt; ++cnt;
|
||||
CHECK(cnt == 16);
|
||||
});
|
||||
}
|
||||
for (auto& t : threads) { t.join(); }
|
||||
REQUIRE(cnt == 16);
|
||||
```
|
||||
|
||||
Because C++11 provides the necessary tools to do this, we are planning
|
||||
to remove this limitation in the future.
|
||||
|
||||
### Process isolation in a test
|
||||
Catch does not support running tests in isolated (forked) processes. While this might in the future, the fact that Windows does not support forking and only allows full-on process creation and the desire to keep code as similar as possible across platforms, mean that this is likely to take significant development time, that is not currently available.
|
||||
|
||||
|
||||
### Running multiple tests in parallel
|
||||
Catch's test execution is strictly serial. If you find yourself with a test suite that takes too long to run and you want to make it parallel, there are 2 feasible solutions
|
||||
* You can split your tests into multiple binaries and then run these binaries in parallel.
|
||||
* You can have Catch list contained test cases and then run the same test binary multiple times in parallel, passing each instance list of test cases it should run.
|
||||
|
||||
Catch2 keeps test execution in one process strictly serial, and there
|
||||
are no plans to change this. If you find yourself with a test suite
|
||||
that takes too long to run and you want to make it parallel, you have
|
||||
to run multiple processes side by side.
|
||||
|
||||
There are 2 basic ways to do that,
|
||||
* you can split your tests into multiple binaries, and run those binaries
|
||||
in parallel
|
||||
* you can run the same test binary multiple times, but run a different
|
||||
subset of the tests in each process
|
||||
|
||||
There are multiple ways to achieve the latter, the easiest way is to use
|
||||
[test sharding](command-line.md#test-sharding).
|
||||
|
||||
Both of these solutions have their problems, but should let you wring parallelism out of your test suite.
|
||||
|
||||
## 3rd party bugs
|
||||
|
||||
This section outlines known bugs in 3rd party components (this means compilers, standard libraries, standard runtimes).
|
||||
|
||||
|
||||
### Visual Studio 2017 -- raw string literal in assert fails to compile
|
||||
|
||||
There is a known bug in Visual Studio 2017 (VC 15), that causes compilation
|
||||
error when preprocessor attempts to stringize a raw string literal
|
||||
(`#` preprocessor directive is applied to it). This snippet is sufficient
|
||||
to trigger the compilation error:
|
||||
|
||||
There is a known bug in Visual Studio 2017 (VC 15), that causes compilation error when preprocessor attempts to stringize a raw string literal (`#` preprocessor is applied to it). This snippet is sufficient to trigger the compilation error:
|
||||
```cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
|
||||
TEST_CASE("test") {
|
||||
CHECK(std::string(R"("\)") == "\"\\");
|
||||
}
|
||||
```
|
||||
|
||||
Catch2 provides a workaround, by letting the user disable stringification
|
||||
of the original expression by defining `CATCH_CONFIG_DISABLE_STRINGIFICATION`,
|
||||
like so:
|
||||
Catch provides a workaround, it is possible to disable stringification of original expressions by defining `CATCH_CONFIG_DISABLE_STRINGIFICATION`:
|
||||
```cpp
|
||||
#define CATCH_CONFIG_FAST_COMPILE
|
||||
#define CATCH_CONFIG_DISABLE_STRINGIFICATION
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include "catch.hpp"
|
||||
|
||||
TEST_CASE("test") {
|
||||
CHECK(std::string(R"("\)") == "\"\\");
|
||||
}
|
||||
```
|
||||
|
||||
_Do note that this changes the output:_
|
||||
_Do note that this changes the output somewhat_
|
||||
```
|
||||
catchwork\test1.cpp(6):
|
||||
PASSED:
|
||||
@@ -119,11 +135,26 @@ with expansion:
|
||||
""\" == ""\"
|
||||
```
|
||||
|
||||
### Visual Studio 2015 -- Alignment compilation error (C2718)
|
||||
|
||||
VS 2015 has a known bug, where `declval<T>` can cause compilation error
|
||||
if `T` has alignment requirements that it cannot meet.
|
||||
|
||||
|
||||
A workaround is to explicitly specialize `Catch::is_range` for given
|
||||
type (this avoids code path that uses `declval<T>` in a SFINAE context).
|
||||
|
||||
|
||||
### Visual Studio 2015 -- Wrong line number reported in debug mode
|
||||
VS 2015 has a known bug where `__LINE__` macro can be improperly expanded under certain circumstances, while compiling multi-file project in Debug mode.
|
||||
|
||||
A workaround is to compile the binary in Release mode.
|
||||
|
||||
### Clang/G++ -- skipping leaf sections after an exception
|
||||
Some versions of `libc++` and `libstdc++` (or their runtimes) have a bug with `std::uncaught_exception()` getting stuck returning `true` after rethrow, even if there are no active exceptions. One such case is this snippet, which skipped the sections "a" and "b", when compiled against `libcxxrt` from the master branch
|
||||
Some versions of `libc++` and `libstdc++` (or their runtimes) have a bug with `std::uncaught_exception()` getting stuck returning `true` after rethrow, even if there are no active exceptions. One such case is this snippet, which skipped the sections "a" and "b", when compiled against `libcxxrt` from master
|
||||
```cpp
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("a") {
|
||||
CHECK_THROWS(throw 3);
|
||||
@@ -137,21 +168,20 @@ TEST_CASE("b") {
|
||||
}
|
||||
```
|
||||
|
||||
If you are seeing a problem like this, i.e. weird test paths that trigger only under Clang with `libc++`, or only under very specific version of `libstdc++`, it is very likely you are seeing this. The only known workaround is to use a fixed version of your standard library.
|
||||
If you are seeing a problem like this, i.e. a weird test paths that trigger only under Clang with `libc++`, or only under very specific version of `libstdc++`, it is very likely you are seeing this. The only known workaround is to use a fixed version of your standard library.
|
||||
|
||||
### Clang/G++ -- `Matches` string matcher always returns false
|
||||
This is a bug in `libstdc++-4.8`, where all matching methods from `<regex>` return false. Since `Matches` uses `<regex>` internally, if the underlying implementation does not work, it doesn't work either.
|
||||
|
||||
Workaround: Use newer version of `libstdc++`.
|
||||
|
||||
|
||||
### Visual Studio 2022 -- can't compile assertion with the spaceship operator
|
||||
### libstdc++, `_GLIBCXX_DEBUG` macro and random ordering of tests
|
||||
|
||||
[The C++ standard requires that `std::foo_ordering` is only comparable with
|
||||
a literal 0](https://eel.is/c++draft/cmp#categories.pre-3). There are
|
||||
multiple strategies a stdlib implementation can take to achieve this, and
|
||||
MSVC's STL has changed the strategy they use between two releases of VS 2022.
|
||||
|
||||
With the new strategy, `REQUIRE((a <=> b) == 0)` no longer compiles under
|
||||
MSVC. Note that Catch2 can compile code using MSVC STL's new strategy,
|
||||
but only when compiled with a C++20 conforming compiler. MSVC is currently
|
||||
not conformant enough, but `clang-cl` will compile the assertion above
|
||||
using MSVC STL without problem.
|
||||
|
||||
[This change got in with MSVC v19.37](https://godbolt.org/z/KG9obzdvE).
|
||||
Running a Catch2 binary compiled against libstdc++ with `_GLIBCXX_DEBUG`
|
||||
macro defined with `--order rand` will cause a debug check to trigger and
|
||||
abort the run due to self-assignment.
|
||||
[This is a known bug inside libstdc++](https://stackoverflow.com/questions/22915325/avoiding-self-assignment-in-stdshuffle/23691322)
|
||||
|
||||
Workaround: Don't use `--order rand` when compiling against debug-enabled
|
||||
libstdc++.
|
||||
|
@@ -3,13 +3,15 @@
|
||||
|
||||
## Already available
|
||||
|
||||
- Catch main: [Catch-provided main](../examples/000-CatchMain.cpp)
|
||||
- Test Case: [Single-file](../examples/010-TestCase.cpp)
|
||||
- Test Case: [Multiple-file 1](../examples/020-TestCase-1.cpp), [2](../examples/020-TestCase-2.cpp)
|
||||
- Assertion: [REQUIRE, CHECK](../examples/030-Asn-Require-Check.cpp)
|
||||
- Fixture: [Sections](../examples/100-Fix-Section.cpp)
|
||||
- Fixture: [Class-based fixtures](../examples/110-Fix-ClassFixture.cpp)
|
||||
- Fixture: [Persistent fixtures](../examples/111-Fix-PersistentFixture.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)
|
||||
- Configuration: [Provide your own output streams](../examples/231-Cfg-OutputStreams.cpp)
|
||||
- Generators: [Create your own generator](../examples/300-Gen-OwnGenerator.cpp)
|
||||
|
@@ -1,34 +1,36 @@
|
||||
<a id="top"></a>
|
||||
# Logging macros
|
||||
|
||||
Catch2 provides various macros for logging extra information when
|
||||
running a test. These macros default to being scoped, and associate with
|
||||
all assertions in the scope, regardless of whether they pass or fail.
|
||||
Additional messages can be logged during a test case. Note that the messages logged with `INFO` are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
|
||||
|
||||
**example**
|
||||
```cpp
|
||||
TEST_CASE("Simple info") {
|
||||
TEST_CASE("Foo") {
|
||||
INFO("Test case start");
|
||||
SECTION("A") {
|
||||
INFO("Section A");
|
||||
CHECK(false); // 1
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
INFO("The number is " << i);
|
||||
CHECK(i == 0);
|
||||
}
|
||||
SECTION("B") {
|
||||
INFO("Section B");
|
||||
CHECK(false); // 2
|
||||
}
|
||||
|
||||
TEST_CASE("Bar") {
|
||||
INFO("Test case start");
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
INFO("The number is " << i);
|
||||
CHECK(i == i);
|
||||
}
|
||||
CHECK(false); // 3
|
||||
CHECK(false);
|
||||
}
|
||||
```
|
||||
The first assertion will report messages "Test case start", and "Section A"
|
||||
as extra information. The second one will report messages "Test case
|
||||
started" and "Section B", while the third one will only report "Test case
|
||||
started" as the extra info.
|
||||
|
||||
When the `CHECK` fails in the "Foo" test case, then two messages will be printed.
|
||||
```
|
||||
Test case start
|
||||
The number is 1
|
||||
```
|
||||
When the last `CHECK` fails in the "Bar" test case, then only one message will be printed: `Test case start`.
|
||||
|
||||
## Logging without local scope
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch 2.7.0.
|
||||
|
||||
`UNSCOPED_INFO` is similar to `INFO` with two key differences:
|
||||
|
||||
@@ -104,7 +106,7 @@ This semicolon will be removed with next major version. It is highly advised to
|
||||
|
||||
**UNSCOPED_INFO(** _message expression_ **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch 2.7.0.
|
||||
|
||||
Similar to `INFO`, but messages are not limited to their own scope: They are removed from the buffer after each assertion, section or test case, whichever comes first.
|
||||
|
||||
@@ -112,10 +114,6 @@ Similar to `INFO`, but messages are not limited to their own scope: They are rem
|
||||
|
||||
The message is always reported but does not fail the test.
|
||||
|
||||
**SUCCEED(** _message expression_ **)**
|
||||
|
||||
The message is reported and the test case succeeds.
|
||||
|
||||
**FAIL(** _message expression_ **)**
|
||||
|
||||
The message is reported and the test case fails.
|
||||
|
511
docs/matchers.md
@@ -1,141 +1,77 @@
|
||||
<a id="top"></a>
|
||||
# Matchers
|
||||
|
||||
**Contents**<br>
|
||||
[Using Matchers](#using-matchers)<br>
|
||||
[Built-in matchers](#built-in-matchers)<br>
|
||||
[Writing custom matchers (old style)](#writing-custom-matchers-old-style)<br>
|
||||
[Writing custom matchers (new style)](#writing-custom-matchers-new-style)<br>
|
||||
Matchers are an alternative way to do assertions which are easily extensible and composable.
|
||||
This makes them well suited to use with more complex types (such as collections) or your own custom types.
|
||||
Matchers were first popularised by the [Hamcrest](https://en.wikipedia.org/wiki/Hamcrest) family of frameworks.
|
||||
|
||||
Matchers, as popularized by the [Hamcrest](https://en.wikipedia.org/wiki/Hamcrest)
|
||||
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.
|
||||
## In use
|
||||
|
||||
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
|
||||
`CHECK_THAT` macros. The `REQUIRE_THAT` macro takes two arguments,
|
||||
the first one is the input (object/value) to test, the second argument
|
||||
is the matcher itself.
|
||||
|
||||
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") );
|
||||
```c++
|
||||
using Catch::Matchers::EndsWith; // or Catch::EndsWith
|
||||
std::string str = getStringFromSomewhere();
|
||||
REQUIRE_THAT( str, EndsWith( "as a service" ) );
|
||||
```
|
||||
|
||||
Individual matchers can also be combined using the C++ logical
|
||||
operators, that is `&&`, `||`, and `!`, like so:
|
||||
The matcher objects can take multiple arguments, allowing more fine tuning.
|
||||
The built-in string matchers, for example, take a second argument specifying whether the comparison is
|
||||
case sensitive or not:
|
||||
|
||||
```cpp
|
||||
using Catch::Matchers::EndsWith;
|
||||
using Catch::Matchers::ContainsSubstring;
|
||||
```c++
|
||||
REQUIRE_THAT( str, EndsWith( "as a service", Catch::CaseSensitive::No ) );
|
||||
```
|
||||
|
||||
REQUIRE_THAT( getSomeString(),
|
||||
EndsWith("as a service") && ContainsSubstring("web scale"));
|
||||
And matchers can be combined:
|
||||
|
||||
```c++
|
||||
REQUIRE_THAT( str,
|
||||
EndsWith( "as a service" ) ||
|
||||
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
|
||||
```
|
||||
|
||||
The example above asserts that the string returned from `getSomeString`
|
||||
_both_ ends with the suffix "as a service" _and_ contains the string
|
||||
"web scale" somewhere.
|
||||
_The combining operators do not take ownership of the matcher objects.
|
||||
This means that if you store the combined object, you have to ensure that
|
||||
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>`.
|
||||
|
||||
### Combining operators and lifetimes
|
||||
|
||||
**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 individual matchers being combined outlive the combined matcher.
|
||||
Note that the negation matcher from `!` also counts as combining matcher
|
||||
for this.
|
||||
|
||||
Explained on an example, this is fine
|
||||
```cpp
|
||||
CHECK_THAT(value, WithinAbs(0, 2e-2) && !WithinULP(0., 1));
|
||||
TEST_CASE("Bugs, bugs, bugs", "[Bug]"){
|
||||
std::string str = "Bugs as a service";
|
||||
|
||||
auto match_expression = Catch::EndsWith( "as a service" ) ||
|
||||
(Catch::StartsWith( "Big data" ) && !Catch::Contains( "web scale" ) );
|
||||
REQUIRE_THAT(str, match_expression);
|
||||
}
|
||||
```
|
||||
|
||||
and so is this
|
||||
```cpp
|
||||
auto is_close_to_zero = WithinAbs(0, 2e-2);
|
||||
auto is_zero = WithinULP(0., 1);
|
||||
|
||||
CHECK_THAT(value, is_close_to_zero && !is_zero);
|
||||
```
|
||||
## 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.
|
||||
|
||||
but this is not
|
||||
```cpp
|
||||
auto is_close_to_zero = WithinAbs(0, 2e-2);
|
||||
auto is_zero = WithinULP(0., 1);
|
||||
auto is_close_to_but_not_zero = is_close_to_zero && !is_zero;
|
||||
|
||||
CHECK_THAT(a_value, is_close_to_but_not_zero); // UAF
|
||||
```
|
||||
|
||||
because `!is_zero` creates a temporary instance of Negation matcher,
|
||||
which the `is_close_to_but_not_zero` refers to. After the line ends,
|
||||
the temporary is destroyed and the combined `is_close_to_but_not_zero`
|
||||
matcher now refers to non-existent object, so using it causes use-after-free.
|
||||
There are two parts to each of the built-in matchers, the matcher
|
||||
type itself and a helper function that provides template argument
|
||||
deduction when creating templated matchers. As an example, the matcher
|
||||
for checking that two instances of `std::vector` are identical is
|
||||
`EqualsMatcher<T>`, but the user is expected to use the `Equals`
|
||||
helper function instead.
|
||||
|
||||
|
||||
## Built-in 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.
|
||||
|
||||
Every matcher provided by Catch2 is split into 2 parts, a factory
|
||||
function that lives in the `Catch::Matchers` namespace, and the actual
|
||||
matcher type that is in some deeper namespace and should not be used by
|
||||
the user. In the examples above, we used `Catch::Matchers::Contains`.
|
||||
This is the factory function for the
|
||||
`Catch::Matchers::StdString::ContainsMatcher` type that does the actual
|
||||
matching.
|
||||
|
||||
Out of the box, Catch2 provides the following matchers:
|
||||
|
||||
|
||||
### `std::string` matchers
|
||||
|
||||
Catch2 provides 5 different matchers that work with `std::string`,
|
||||
* `StartsWith(std::string str, CaseSensitive)`,
|
||||
* `EndsWith(std::string str, CaseSensitive)`,
|
||||
* `ContainsSubstring(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 against the string as a whole, meaning that
|
||||
the regex `"abc"` will not match input string `"abcd"`. To match
|
||||
`"abcd"`, you need to use e.g. `"abc.*"` as your regex.
|
||||
|
||||
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`
|
||||
Each of the provided `std::string` matchers also takes an optional second argument, that decides case sensitivity (by-default, they are case sensitive).
|
||||
|
||||
|
||||
### Vector matchers
|
||||
|
||||
_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`.
|
||||
|
||||
Catch2 currently provides 5 built-in matchers that work on `std::vector`.
|
||||
These are
|
||||
|
||||
* `Contains` which checks whether a specified vector is present in the result
|
||||
@@ -143,57 +79,42 @@ These are
|
||||
* `Equals` which checks whether the result is exactly equal (order matters) to a specific vector
|
||||
* `UnorderedEquals` which checks whether the result is equal to a specific vector under a permutation
|
||||
* `Approx` which checks whether the result is "approx-equal" (order matters, but comparison is done via `Approx`) to a specific vector
|
||||
> Approx matcher was [introduced](https://github.com/catchorg/Catch2/issues/1499) in Catch2 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`
|
||||
> Approx matcher was [introduced](https://github.com/catchorg/Catch2/issues/1499) in Catch 2.7.2.
|
||||
|
||||
|
||||
### Floating point matchers
|
||||
Catch2 provides 3 matchers for working with floating point numbers. These
|
||||
are `WithinAbsMatcher`, `WithinUlpsMatcher` and `WithinRelMatcher`.
|
||||
|
||||
Catch2 provides 4 matchers that target floating point numbers. These
|
||||
are:
|
||||
The `WithinAbsMatcher` matcher accepts floating point numbers that are
|
||||
within a certain distance of target. It should be constructed with the
|
||||
`WithinAbs(double target, double margin)` helper.
|
||||
|
||||
* `WithinAbs(double target, double margin)`,
|
||||
* `WithinULP(FloatingPoint target, uint64_t maxUlpDiff)`, and
|
||||
* `WithinRel(FloatingPoint target, FloatingPoint eps)`.
|
||||
* `IsNaN()`
|
||||
The `WithinUlpsMatcher` matcher accepts floating point numbers that are
|
||||
within a certain number of [ULPs](https://en.wikipedia.org/wiki/Unit_in_the_last_place)
|
||||
of the target. Because ULP comparisons need to be done differently for
|
||||
`float`s and for `double`s, there are two overloads of the helpers for
|
||||
this matcher, `WithinULP(float target, int64_t ULPs)`, and
|
||||
`WithinULP(double target, int64_t ULPs)`.
|
||||
|
||||
> `WithinRel` matcher was introduced in Catch2 2.10.0
|
||||
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.
|
||||
|
||||
> `IsNaN` matcher was introduced in Catch2 3.3.2.
|
||||
> `WithinRel` matcher was introduced in Catch 2.10.0
|
||||
|
||||
The first three serve to compare two floating pointe numbers. For more
|
||||
details about how they work, read [the docs on comparing floating point
|
||||
numbers](comparing-floating-point-numbers.md#floating-point-matchers).
|
||||
|
||||
`IsNaN` then does exactly what it says on the tin. It matches the input
|
||||
if it is a NaN (Not a Number). The advantage of using it over just plain
|
||||
`REQUIRE(std::isnan(x))`, is that if the check fails, with `REQUIRE` you
|
||||
won't see the value of `x`, but with `REQUIRE_THAT(x, IsNaN())`, you will.
|
||||
|
||||
|
||||
### 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:
|
||||
### 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.
|
||||
|
||||
Because of type inference limitations, the argument type of the predicate
|
||||
has to be provided explicitly. Example:
|
||||
```cpp
|
||||
REQUIRE_THAT("Hello olleH",
|
||||
Predicate<std::string>(
|
||||
@@ -202,274 +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
|
||||
|
||||
Because exceptions are a bit special, Catch2 has a separate macro for them.
|
||||
|
||||
|
||||
The basic form is
|
||||
|
||||
```
|
||||
REQUIRE_THROWS_MATCHES(expr, ExceptionType, Matcher)
|
||||
```
|
||||
|
||||
and it checks that the `expr` throws an exception, that exception is derived
|
||||
from the `ExceptionType` type, and then `Matcher::match` is called on
|
||||
the caught exception.
|
||||
|
||||
> `REQUIRE_THROWS_MATCHES` macro lives in `catch2/matchers/catch_matchers.hpp`
|
||||
|
||||
For one-off checks you can use the `Predicate` matcher above, e.g.
|
||||
|
||||
```cpp
|
||||
REQUIRE_THROWS_MATCHES(parse(...),
|
||||
parse_error,
|
||||
Predicate<parse_error>([] (parse_error const& err) -> bool { return err.line() == 1; })
|
||||
);
|
||||
```
|
||||
|
||||
but if you intend to thoroughly test your error reporting, I recommend
|
||||
defining a specialized matcher.
|
||||
|
||||
|
||||
Catch2 also provides 2 built-in matchers for checking the error message
|
||||
inside an exception (it must be derived from `std::exception`):
|
||||
* `Message(std::string message)`.
|
||||
* `MessageMatches(Matcher matcher)`.
|
||||
|
||||
> `MessageMatches` was [introduced](https://github.com/catchorg/Catch2/pull/2570) in Catch2 3.3.0
|
||||
|
||||
`Message` checks that the exception's
|
||||
message, as returned from `what` is exactly equal to `message`.
|
||||
|
||||
`MessageMatches` applies the provided matcher on the exception's
|
||||
message, as returned from `what`. This is useful in conjunctions with the `std::string` matchers (e.g. `StartsWith`)
|
||||
> `ExceptionMessageMatcher` was introduced in Catch 2.10.0
|
||||
|
||||
Example use:
|
||||
```cpp
|
||||
REQUIRE_THROWS_MATCHES(throwsDerivedException(), DerivedException, Message("DerivedException::what"));
|
||||
REQUIRE_THROWS_MATCHES(throwsDerivedException(), DerivedException, MessageMatches(StartsWith("DerivedException")));
|
||||
```
|
||||
|
||||
> the exception message matchers live in `catch2/matchers/catch_matchers_exception.hpp`
|
||||
## Custom matchers
|
||||
It's easy to provide your own matchers to extend Catch or just to work with your own types.
|
||||
|
||||
You need to provide two things:
|
||||
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.
|
||||
|
||||
### Generic range Matchers
|
||||
|
||||
> Generic range matchers were introduced in Catch2 3.0.1
|
||||
|
||||
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)`
|
||||
* `AllMatch(Matcher element_matcher)`
|
||||
* `AnyMatch(Matcher element_matcher)`
|
||||
* `NoneMatch(Matcher element_matcher)`
|
||||
* `AllTrue()`, `AnyTrue()`, `NoneTrue()`
|
||||
* `RangeEquals(TargetRangeLike&&, Comparator = std::equal_to<>{})`
|
||||
* `UnorderedRangeEquals(TargetRangeLike&&, Comparator = std::equal_to<>{})`
|
||||
|
||||
> `IsEmpty`, `SizeIs`, `Contains` were introduced in Catch2 3.0.1
|
||||
|
||||
> `All/Any/NoneMatch` were introduced in Catch2 3.0.1
|
||||
|
||||
> `All/Any/NoneTrue` were introduced in Catch2 3.1.0
|
||||
|
||||
> `RangeEquals` and `UnorderedRangeEquals` matchers were [introduced](https://github.com/catchorg/Catch2/pull/2377) in Catch2 3.3.0
|
||||
|
||||
`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.
|
||||
|
||||
`AllMatch`, `NoneMatch`, and `AnyMatch` match ranges for which either
|
||||
all, none, or any of the contained elements matches the given matcher,
|
||||
respectively.
|
||||
|
||||
`AllTrue`, `NoneTrue`, and `AnyTrue` match ranges for which either
|
||||
all, none, or any of the contained elements are `true`, respectively.
|
||||
It works for ranges of `bool`s and ranges of elements (explicitly)
|
||||
convertible to `bool`.
|
||||
|
||||
`RangeEquals` compares the range that the matcher is constructed with
|
||||
(the "target range") against the range to be tested, element-wise. The
|
||||
match succeeds if all elements from the two ranges compare equal (using
|
||||
`operator==` by default). The ranges do not need to be the same type,
|
||||
and the element types do not need to be the same, as long as they are
|
||||
comparable. (e.g. you may compare `std::vector<int>` to `std::array<char>`).
|
||||
|
||||
`UnorderedRangeEquals` is similar to `RangeEquals`, but the order
|
||||
does not matter. For example "1, 2, 3" would match "3, 2, 1", but not
|
||||
"1, 1, 2, 3" As with `RangeEquals`, `UnorderedRangeEquals` compares
|
||||
the individual elements using `operator==` by default.
|
||||
|
||||
Both `RangeEquals` and `UnorderedRangeEquals` optionally accept a
|
||||
predicate which can be used to compare the containers element-wise.
|
||||
|
||||
To check a container elementwise against a given matcher, use
|
||||
`AllMatch`.
|
||||
|
||||
|
||||
## 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>`:
|
||||
Here's an example for asserting that an integer falls within a given range
|
||||
(note that it is all inline for the sake of keeping the example short):
|
||||
|
||||
```c++
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
// ...
|
||||
|
||||
|
||||
template <typename T>
|
||||
class IsBetweenMatcher : public Catch::Matchers::MatcherBase<T> {
|
||||
T m_begin, m_end;
|
||||
// The matcher class
|
||||
class IntRange : public Catch::MatcherBase<int> {
|
||||
int m_begin, m_end;
|
||||
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 {
|
||||
return in >= m_begin && in <= m_end;
|
||||
// Performs the test for this matcher
|
||||
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;
|
||||
ss << "is between " << m_begin << " and " << m_end;
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
IsBetweenMatcher<T> IsBetween(T begin, T end) {
|
||||
return { begin, end };
|
||||
// The builder function
|
||||
inline IntRange IsBetween( int begin, int end ) {
|
||||
return IntRange( begin, end );
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
TEST_CASE("Numbers are within range") {
|
||||
// infers `double` for the argument type of the matcher
|
||||
CHECK_THAT(3., IsBetween(1., 10.));
|
||||
// infers `int` for the argument type of the matcher
|
||||
CHECK_THAT(100, IsBetween(1, 10));
|
||||
// Usage
|
||||
TEST_CASE("Integers are within a range")
|
||||
{
|
||||
CHECK_THAT( 3, IsBetween( 1, 10 ) );
|
||||
CHECK_THAT( 100, IsBetween( 1, 10 ) );
|
||||
}
|
||||
```
|
||||
|
||||
Obviously, the code above can be improved somewhat, for example you
|
||||
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.
|
||||
Running this test gives the following in the console:
|
||||
|
||||
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 Catch2 3.0.1
|
||||
|
||||
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 overridden
|
||||
`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));
|
||||
}
|
||||
```
|
||||
|
||||
Do note that while you can rewrite any matcher from the old style to
|
||||
a new style matcher, combining new style matchers is more expensive
|
||||
in terms of compilation time. Also note that you can combine old style
|
||||
and new style matchers arbitrarily.
|
||||
|
||||
> `MatcherGenericBase` lives in `catch2/matchers/catch_matchers_templated.hpp`
|
||||
|
||||
/**/TestFile.cpp:123: FAILED:
|
||||
CHECK_THAT( 100, IsBetween( 1, 10 ) )
|
||||
with expansion:
|
||||
100 is between 1 and 10
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
@@ -1,98 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Migrating from v2 to v3
|
||||
|
||||
v3 is the next major version of Catch2 and brings three significant changes:
|
||||
* Catch2 is now split into multiple headers
|
||||
* Catch2 is now compiled as a static library
|
||||
* C++14 is the minimum required C++ version
|
||||
|
||||
There are many reasons why we decided to go from the old single-header
|
||||
distribution model to a more standard library distribution model. The
|
||||
big one is compile-time performance, but moving over to a split header
|
||||
distribution model also improves the future maintainability and
|
||||
extendability of the codebase. For example v3 adds a new kind of matchers
|
||||
without impacting the compilation times of users that do not use matchers
|
||||
in their tests. The new model is also more friendly towards package
|
||||
managers, such as vcpkg and Conan.
|
||||
|
||||
The result of this move is a significant improvement in compilation
|
||||
times, e.g. the inclusion overhead of Catch2 in the common case has been
|
||||
reduced by roughly 80%. The improved ease of maintenance also led to
|
||||
various runtime performance improvements and the introduction of new features.
|
||||
For details, look at [the release notes of 3.0.1](release-notes.md#301).
|
||||
|
||||
_Note that we still provide one header + one translation unit (TU)
|
||||
distribution but do not consider it the primarily supported option. You
|
||||
should also expect that the compilation times will be worse if you use
|
||||
this option._
|
||||
|
||||
|
||||
## How to migrate projects from v2 to v3
|
||||
|
||||
To migrate to v3, there are two basic approaches to do so.
|
||||
|
||||
1. Use `catch_amalgamated.hpp` and `catch_amalgamated.cpp`.
|
||||
2. Build Catch2 as a proper (static) library, and move to piecewise headers
|
||||
|
||||
Doing 1 means downloading the [amalgamated header](/extras/catch_amalgamated.hpp)
|
||||
and the [amalgamated sources](/extras/catch_amalgamated.cpp) from `extras`,
|
||||
dropping them into your test project, and rewriting your includes from
|
||||
`<catch2/catch.hpp>` to `"catch_amalgamated.hpp"` (or something similar,
|
||||
based on how you set up your paths).
|
||||
|
||||
The disadvantage of using this approach are increased compilation times,
|
||||
at least compared to the second approach, but it does let you avoid
|
||||
dealing with consuming libraries in your build system of choice.
|
||||
|
||||
|
||||
However, we recommend doing 2, and taking extra time to migrate to v3
|
||||
properly. This lets you reap the benefits of significantly improved
|
||||
compilation times in the v3 version. The basic steps to do so are:
|
||||
|
||||
1. Change your CMakeLists.txt to link against `Catch2WithMain` target if
|
||||
you use Catch2's default main. (If you do not, keep linking against
|
||||
the `Catch2` target.). If you use pkg-config, change `pkg-config catch2` to
|
||||
`pkg-config catch2-with-main`.
|
||||
2. Delete TU with `CATCH_CONFIG_RUNNER` or `CATCH_CONFIG_MAIN` defined,
|
||||
as it is no longer needed.
|
||||
3. Change `#include <catch2/catch.hpp>` to `#include <catch2/catch_all.hpp>`
|
||||
4. Check that everything compiles. You might have to modify namespaces,
|
||||
or perform some other changes (see the
|
||||
[Things that can break during porting](#things-that-can-break-during-porting)
|
||||
section for the most common things).
|
||||
5. Start migrating your test TUs from including `<catch2/catch_all.hpp>`
|
||||
to piecemeal includes. You will likely want to start by including
|
||||
`<catch2/catch_test_macros.hpp>`, and then go from there. (see
|
||||
[other notes](#other-notes) for further ideas)
|
||||
|
||||
## Other notes
|
||||
|
||||
* The main test include is now `<catch2/catch_test_macros.hpp>`
|
||||
|
||||
* Big "subparts" like Matchers, or Generators, have their own folder, and
|
||||
also their own "big header", so if you just want to include all matchers,
|
||||
you can include `<catch2/matchers/catch_matchers_all.hpp>`,
|
||||
or `<catch2/generators/catch_generators_all.hpp>`
|
||||
|
||||
|
||||
## Things that can break during porting
|
||||
|
||||
* The namespaces of Matchers were flattened and cleaned up.
|
||||
|
||||
Matchers are no longer declared deep within an internal namespace and
|
||||
then brought up into `Catch` namespace. All Matchers now live in the
|
||||
`Catch::Matchers` namespace.
|
||||
|
||||
* The `Contains` string matcher was renamed to `ContainsSubstring`.
|
||||
|
||||
* The reporter interfaces changed in a breaking manner.
|
||||
|
||||
If you are using a custom reporter or listener, you will likely need to
|
||||
modify them to conform to the new interfaces. Unlike before in v2,
|
||||
the [interfaces](reporters.md#top) and the [events](reporter-events.md#top)
|
||||
are now documented.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -1,28 +1,22 @@
|
||||
<a id="top"></a>
|
||||
# Open Source projects using Catch2
|
||||
# Open Source projects using Catch
|
||||
|
||||
Catch2 is great for open source. It is licensed under the [Boost Software
|
||||
License (BSL)](../LICENSE.txt), has no further dependencies and supports
|
||||
two file distribution.
|
||||
Catch is great for open source. With its [liberal license](../LICENSE.txt) and single-header, dependency-free, distribution
|
||||
it's easy to just drop the header into your project and start writing tests - what's not to like?
|
||||
|
||||
As a result, Catch2 is used for testing in many different Open Source
|
||||
projects. This page lists at least some of them, even though it will
|
||||
obviously never be complete (and does not have the ambition to be
|
||||
complete). Note that the list below is intended to be in alphabetical
|
||||
order, to avoid implications of relative importance of the projects.
|
||||
|
||||
_Please only add projects here if you are their maintainer, or have the
|
||||
maintainer's explicit consent._
|
||||
As a result Catch is now being used in many Open Source projects, including some quite well known ones.
|
||||
This page is an attempt to track those projects. Obviously it can never be complete.
|
||||
This effort largely relies on the maintainers of the projects themselves updating this page and submitting a PR
|
||||
(or, if you prefer contact one of the maintainers of Catch directly, use the
|
||||
[forums](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)), or raise an [issue](https://github.com/philsquared/Catch/issues) to let us know).
|
||||
Of course users of those projects might want to update this page too. That's fine - as long you're confident the project maintainers won't mind.
|
||||
If you're an Open Source project maintainer and see your project listed here but would rather it wasn't -
|
||||
just let us know via any of the previously mentioned means - although I'm sure there won't be many who feel that way.
|
||||
|
||||
Listing a project here does not imply endorsement and the plan is to keep these ordered alphabetically to avoid an implication of relative importance.
|
||||
|
||||
## Libraries & Frameworks
|
||||
|
||||
### [accessorpp](https://github.com/wqking/accessorpp)
|
||||
C++ library for implementing property and data binding.
|
||||
|
||||
### [alpaka](https://github.com/alpaka-group/alpaka)
|
||||
A header-only C++14 abstraction library for accelerator development.
|
||||
|
||||
### [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp)
|
||||
C++11 implementation of Approval Tests, for quick, convenient testing of legacy code.
|
||||
|
||||
@@ -53,26 +47,17 @@ Header-only C++11 library to encode/decode base64, base64url, base32, base32hex
|
||||
### [DtCraft](https://github.com/twhuang-uiuc/DtCraft)
|
||||
A High-performance Cluster Computing Engine.
|
||||
|
||||
### [eventpp](https://github.com/wqking/eventpp)
|
||||
C++ event library for callbacks, event dispatcher, and event queue. With eventpp you can easily implement signal and slot mechanism, publisher and subscriber pattern, or observer pattern.
|
||||
|
||||
### [forest](https://github.com/xorz57/forest)
|
||||
Template Library of Tree Data Structures.
|
||||
|
||||
### [Fuxedo](https://github.com/fuxedo/fuxedo)
|
||||
Open source Oracle Tuxedo-like XATMI middleware for C and C++.
|
||||
|
||||
### [HIP CPU Runtime](https://github.com/ROCm-Developer-Tools/HIP-CPU)
|
||||
A header-only library that allows CPUs to execute unmodified HIP code. It is generic and does not assume a particular CPU vendor or architecture.
|
||||
|
||||
### [Inja](https://github.com/pantor/inja)
|
||||
A header-only template engine for modern C++.
|
||||
|
||||
### [LLAMA](https://github.com/alpaka-group/llama)
|
||||
A C++17 template header-only library for the abstraction of memory access patterns.
|
||||
|
||||
### [libcluon](https://github.com/chrberger/libcluon)
|
||||
A single-header-only library written in C++14 to glue distributed software components (UDP, TCP, shared memory) supporting natively Protobuf, LCM/ZCM, MsgPack, and JSON for dynamic message transformations in-between.
|
||||
A single-header-only library written in C++14 to glue distributed software components (UDP, TCP, shared memory) supporting natively Protobuf, LCM/ZCM, MsgPack, and JSON for dynamic message transformations in-between.
|
||||
|
||||
### [MNMLSTC Core](https://github.com/mnmlstc/core)
|
||||
A small and easy to use C++11 library that adds a functionality set that will be available in C++14 and later, as well as some useful additions.
|
||||
@@ -83,9 +68,6 @@ A small C++ library wrapper for the native C ODBC API.
|
||||
### [Nonius](https://github.com/libnonius/nonius)
|
||||
A header-only framework for benchmarking small snippets of C++ code.
|
||||
|
||||
### [OpenALpp](https://github.com/Laguna1989/OpenALpp)
|
||||
A modern OOP C++14 audio library built on OpenAL for Windows, Linux and web (emscripten).
|
||||
|
||||
### [polymorphic_value](https://github.com/jbcoe/polymorphic_value)
|
||||
A polymorphic value-type for C++.
|
||||
|
||||
@@ -95,9 +77,6 @@ A C++ client library for Consul. Consul is a distributed tool for discovering an
|
||||
### [Reactive-Extensions/ RxCpp](https://github.com/Reactive-Extensions/RxCpp)
|
||||
A library of algorithms for values-distributed-in-time.
|
||||
|
||||
### [SFML](https://github.com/SFML/SFML)
|
||||
Simple and Fast Multimedia Library.
|
||||
|
||||
### [SOCI](https://github.com/SOCI/soci)
|
||||
The C++ Database Access Library.
|
||||
|
||||
@@ -113,26 +92,11 @@ A header-only TOML parser and serializer for modern C++.
|
||||
### [Trompeloeil](https://github.com/rollbear/trompeloeil)
|
||||
A thread-safe header-only mocking framework for C++14.
|
||||
|
||||
### [wxWidgets](https://www.wxwidgets.org/)
|
||||
Cross-Platform C++ GUI Library.
|
||||
|
||||
### [xmlwrapp](https://github.com/vslavik/xmlwrapp)
|
||||
C++ XML parsing library using libxml2.
|
||||
|
||||
## Applications & Tools
|
||||
|
||||
### [App Mesh](https://github.com/laoshanxi/app-mesh)
|
||||
A high available cloud native micro-service application management platform implemented by modern C++.
|
||||
|
||||
### [ArangoDB](https://github.com/arangodb/arangodb)
|
||||
ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values.
|
||||
|
||||
### [Cytopia](https://github.com/CytopiaTeam/Cytopia)
|
||||
Cytopia is a free, open source retro pixel-art city building game with a big focus on mods. It utilizes a custom isometric rendering engine based on SDL2.
|
||||
|
||||
### [d-SEAMS](https://github.com/d-SEAMS/seams-core)
|
||||
Open source molecular dynamics simulation structure analysis suite of tools in modern C++.
|
||||
|
||||
### [Giada - Your Hardcore Loop Machine](https://github.com/monocasual/giada)
|
||||
Minimal, open-source and cross-platform audio tool for live music production.
|
||||
|
||||
@@ -146,7 +110,7 @@ Newsbeuter is an open-source RSS/Atom feed reader for text terminals.
|
||||
A 2D, Zombie, RPG game which is being made on our own engine.
|
||||
|
||||
### [raspigcd](https://github.com/pantadeusz/raspigcd)
|
||||
Low level CLI app and library for execution of GCODE on Raspberry Pi without any additional microcontrollers (just RPi + Stepsticks).
|
||||
Low level CLI app and library for execution of GCODE on Raspberry Pi without any additional microcontrolers (just RPi + Stepsticks).
|
||||
|
||||
### [SpECTRE](https://github.com/sxs-collaboration/spectre)
|
||||
SpECTRE is a code for multi-scale, multi-physics problems in astrophysics and gravitational physics.
|
||||
|
@@ -15,8 +15,6 @@ stringification machinery to the _expr_ and records the result. As with
|
||||
evaluates to `true`. `CHECKED_ELSE( expr )` work similarly, but the block
|
||||
is entered only if the _expr_ evaluated to `false`.
|
||||
|
||||
> `CHECKED_X` macros were changed to not count as failure in Catch2 3.0.1.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
int a = ...;
|
||||
@@ -59,9 +57,9 @@ TEST_CASE( "SUCCEED showcase" ) {
|
||||
}
|
||||
```
|
||||
|
||||
* `STATIC_REQUIRE` and `STATIC_CHECK`
|
||||
* `STATIC_REQUIRE`
|
||||
|
||||
> `STATIC_REQUIRE` was [introduced](https://github.com/catchorg/Catch2/issues/1362) in Catch2 2.4.2.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1362) in Catch 2.4.2.
|
||||
|
||||
`STATIC_REQUIRE( expr )` is a macro that can be used the same way as a
|
||||
`static_assert`, but also registers the success with Catch2, so it is
|
||||
@@ -77,22 +75,32 @@ TEST_CASE("STATIC_REQUIRE showcase", "[traits]") {
|
||||
}
|
||||
```
|
||||
|
||||
> `STATIC_CHECK` was [introduced](https://github.com/catchorg/Catch2/pull/2318) in Catch2 3.0.1.
|
||||
|
||||
`STATIC_CHECK( expr )` is equivalent to `STATIC_REQUIRE( expr )`, with the
|
||||
difference that when `CATCH_CONFIG_RUNTIME_STATIC_REQUIRE` is defined, it
|
||||
becomes equivalent to `CHECK` instead of `REQUIRE`.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
TEST_CASE("STATIC_CHECK showcase", "[traits]") {
|
||||
STATIC_CHECK( std::is_void<void>::value );
|
||||
STATIC_CHECK_FALSE( std::is_void<int>::value );
|
||||
}
|
||||
```
|
||||
|
||||
## Test case related macros
|
||||
|
||||
* `METHOD_AS_TEST_CASE`
|
||||
|
||||
`METHOD_AS_TEST_CASE( member-function-pointer, description )` lets you
|
||||
register a member function of a class as a Catch2 test case. The class
|
||||
will be separately instantiated for each method registered in this way.
|
||||
|
||||
```cpp
|
||||
class TestClass {
|
||||
std::string s;
|
||||
|
||||
public:
|
||||
TestClass()
|
||||
:s( "hello" )
|
||||
{}
|
||||
|
||||
void testCase() {
|
||||
REQUIRE( s == "hello" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
METHOD_AS_TEST_CASE( TestClass::testCase, "Use class's method as a test case", "[class]" )
|
||||
```
|
||||
|
||||
* `REGISTER_TEST_CASE`
|
||||
|
||||
`REGISTER_TEST_CASE( function, description )` let's you register
|
||||
@@ -109,9 +117,24 @@ is initiated. This means that it either needs to be done in a global
|
||||
constructor, or before Catch2's session is created in user's own main._
|
||||
|
||||
|
||||
* `ANON_TEST_CASE`
|
||||
|
||||
`ANON_TEST_CASE` is a `TEST_CASE` replacement that will autogenerate
|
||||
unique name. The advantage of this is that you do not have to think
|
||||
of a name for the test case,`the disadvantage is that the name doesn't
|
||||
necessarily remain stable across different links, and thus it might be
|
||||
hard to run directly.
|
||||
|
||||
Example:
|
||||
```cpp
|
||||
ANON_TEST_CASE() {
|
||||
SUCCEED("Hello from anonymous test case");
|
||||
}
|
||||
```
|
||||
|
||||
* `DYNAMIC_SECTION`
|
||||
|
||||
> Introduced in Catch2 2.3.0.
|
||||
> Introduced in Catch 2.3.0.
|
||||
|
||||
`DYNAMIC_SECTION` is a `SECTION` where the user can use `operator<<` to
|
||||
create the final name for that section. This can be useful with e.g.
|
||||
|
110
docs/own-main.md
@@ -2,103 +2,102 @@
|
||||
# Supplying main() yourself
|
||||
|
||||
**Contents**<br>
|
||||
[Let Catch2 take full control of args and config](#let-catch2-take-full-control-of-args-and-config)<br>
|
||||
[Amending the Catch2 config](#amending-the-catch2-config)<br>
|
||||
[Let Catch take full control of args and config](#let-catch-take-full-control-of-args-and-config)<br>
|
||||
[Amending the config](#amending-the-config)<br>
|
||||
[Adding your own command line options](#adding-your-own-command-line-options)<br>
|
||||
[Version detection](#version-detection)<br>
|
||||
|
||||
The easiest way to use Catch2 is to use its own `main` function, and let
|
||||
it handle the command line arguments. This is done by linking against
|
||||
Catch2Main library, e.g. through the [CMake target](cmake-integration.md#cmake-targets),
|
||||
or pkg-config files.
|
||||
The easiest way to use Catch is to let it supply ```main()``` for you and handle configuring itself from the command line.
|
||||
|
||||
If you want to provide your own `main`, then you should link against
|
||||
the static library (target) only, without the main part. You will then
|
||||
have to write your own `main` and call into Catch2 test runner manually.
|
||||
This is achieved by writing ```#define CATCH_CONFIG_MAIN``` before the ```#include "catch.hpp"``` in *exactly one* source file.
|
||||
|
||||
Below are some basic recipes on what you can do supplying your own main.
|
||||
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:
|
||||
|
||||
**Important note: you can only provide `main` in the same file you defined `CATCH_CONFIG_RUNNER`.**
|
||||
|
||||
## Let Catch2 take full control of args and config
|
||||
## Let Catch take full control of args and config
|
||||
|
||||
This is useful if you just need to have code that executes before/after
|
||||
Catch2 runs tests.
|
||||
If you just need to have code that executes before and/ or after Catch this is the simplest option.
|
||||
|
||||
```cpp
|
||||
#include <catch2/catch_session.hpp>
|
||||
```c++
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
|
||||
int main( int argc, char* argv[] ) {
|
||||
// your setup ...
|
||||
// global setup...
|
||||
|
||||
int result = Catch::Session().run( argc, argv );
|
||||
|
||||
// your clean-up...
|
||||
// global clean-up...
|
||||
|
||||
return result;
|
||||
}
|
||||
```
|
||||
|
||||
_Note that if you only want to run some set up before tests are run, it
|
||||
might be simpler to use [event listeners](event-listeners.md#top) instead._
|
||||
## Amending the config
|
||||
|
||||
|
||||
## Amending the Catch2 config
|
||||
|
||||
If you want Catch2 to process command line arguments, but also want to
|
||||
programmatically change the resulting configuration of Catch2 run,
|
||||
you can do it in two ways:
|
||||
If you still want Catch to process the command line, but you want to programmatically tweak the config, you can do so in one of two ways:
|
||||
|
||||
```c++
|
||||
int main( int argc, char* argv[] ) {
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
|
||||
// writing to session.configData() here sets defaults
|
||||
// this is the preferred way to set them
|
||||
|
||||
|
||||
int returnCode = session.applyCommandLine( argc, argv );
|
||||
if( returnCode != 0 ) // Indicates a command line error
|
||||
return returnCode;
|
||||
|
||||
// writing to session.configData() or session.Config() here
|
||||
return returnCode;
|
||||
|
||||
// writing to session.configData() or session.Config() here
|
||||
// overrides command line args
|
||||
// only do this if you know you need to
|
||||
|
||||
returnCode = session.run();
|
||||
|
||||
// returnCode encodes the type of error that occured. See the
|
||||
// integer constants in catch_session.hpp for more information
|
||||
// on what each return code means.
|
||||
|
||||
int numFailed = session.run();
|
||||
|
||||
// numFailed is clamped to 255 as some unices only use the lower 8 bits.
|
||||
// This clamping has already been applied, so just return it here
|
||||
// You can also do any post run clean-up here
|
||||
return numFailed;
|
||||
}
|
||||
```
|
||||
|
||||
If you want full control of the configuration, don't call `applyCommandLine`.
|
||||
Take a look at the definitions of Config and ConfigData to see what you can do with them.
|
||||
|
||||
To take full control of the config simply omit the call to ```applyCommandLine()```.
|
||||
|
||||
## Adding your own command line options
|
||||
|
||||
You can add new command line options to Catch2, by composing the premade
|
||||
CLI parser (called Clara), and add your own options.
|
||||
Catch embeds a powerful command line parser called [Clara](https://github.com/philsquared/Clara).
|
||||
As of Catch2 (and Clara 1.0) Clara allows you to write _composable_ option and argument parsers,
|
||||
so extending Catch's own command line options is now easy.
|
||||
|
||||
```cpp
|
||||
int main( int argc, char* argv[] ) {
|
||||
```c++
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include "catch.hpp"
|
||||
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
|
||||
|
||||
int height = 0; // Some user variable you want to be able to set
|
||||
|
||||
// Build a new parser on top of Catch2's
|
||||
using namespace Catch::Clara;
|
||||
auto cli
|
||||
= session.cli() // Get Catch2's command line parser
|
||||
|
||||
// Build a new parser on top of Catch's
|
||||
using namespace Catch::clara;
|
||||
auto cli
|
||||
= session.cli() // Get Catch's composite command line parser
|
||||
| Opt( height, "height" ) // bind variable to a new option, with a hint string
|
||||
["-g"]["--height"] // the option names it will respond to
|
||||
("how high?"); // description string for the help output
|
||||
|
||||
// Now pass the new composite back to Catch2 so it uses that
|
||||
session.cli( cli );
|
||||
|
||||
// Let Catch2 (using Clara) parse the command line
|
||||
|
||||
// Now pass the new composite back to Catch so it uses that
|
||||
session.cli( cli );
|
||||
|
||||
// Let Catch (using Clara) parse the command line
|
||||
int returnCode = session.applyCommandLine( argc, argv );
|
||||
if( returnCode != 0 ) // Indicates a command line error
|
||||
return returnCode;
|
||||
@@ -111,13 +110,12 @@ int main( int argc, char* argv[] ) {
|
||||
}
|
||||
```
|
||||
|
||||
See the [Clara documentation](https://github.com/catchorg/Clara/blob/master/README.md)
|
||||
for more details on how to use the Clara parser.
|
||||
See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details.
|
||||
|
||||
|
||||
## Version detection
|
||||
|
||||
Catch2 provides a triplet of macros providing the header's version,
|
||||
Catch provides a triplet of macros providing the header's version,
|
||||
|
||||
* `CATCH_VERSION_MAJOR`
|
||||
* `CATCH_VERSION_MINOR`
|
||||
|
@@ -2,33 +2,6 @@
|
||||
|
||||
# Release notes
|
||||
**Contents**<br>
|
||||
[3.9.1](#391)<br>
|
||||
[3.9.0](#390)<br>
|
||||
[3.8.1](#381)<br>
|
||||
[3.8.0](#380)<br>
|
||||
[3.7.1](#371)<br>
|
||||
[3.7.0](#370)<br>
|
||||
[3.6.0](#360)<br>
|
||||
[3.5.4](#354)<br>
|
||||
[3.5.3](#353)<br>
|
||||
[3.5.2](#352)<br>
|
||||
[3.5.1](#351)<br>
|
||||
[3.5.0](#350)<br>
|
||||
[3.4.0](#340)<br>
|
||||
[3.3.2](#332)<br>
|
||||
[3.3.1](#331)<br>
|
||||
[3.3.0](#330)<br>
|
||||
[3.2.1](#321)<br>
|
||||
[3.2.0](#320)<br>
|
||||
[3.1.1](#311)<br>
|
||||
[3.1.0](#310)<br>
|
||||
[3.0.1](#301)<br>
|
||||
[2.13.7](#2137)<br>
|
||||
[2.13.6](#2136)<br>
|
||||
[2.13.5](#2135)<br>
|
||||
[2.13.4](#2134)<br>
|
||||
[2.13.3](#2133)<br>
|
||||
[2.13.2](#2132)<br>
|
||||
[2.13.1](#2131)<br>
|
||||
[2.13.0](#2130)<br>
|
||||
[2.12.4](#2124)<br>
|
||||
@@ -69,726 +42,6 @@
|
||||
[Even Older versions](#even-older-versions)<br>
|
||||
|
||||
|
||||
## 3.9.1
|
||||
|
||||
### Fixes
|
||||
* Fixed bad error reporting for multiple nested assertions (#1292)
|
||||
* Fixed W4702 (unreachable code) in the polyfill for std::unreachable (#3007)
|
||||
* Fixed decomposition of assertions comparing enum-backed bitfields (#3001)
|
||||
* Fixed StringMaker specialization for `time_point<system_clock>` with non-default duration type (#2685)
|
||||
|
||||
### Improvements
|
||||
* Exceptions thrown during stringification of decomposed expression no longer fail the assertion (#2980)
|
||||
* The selection logic for `CATCH_TRAP` prefers `__builtin_debugtrap` on all platforms when Catch2 is compiled with Clang
|
||||
|
||||
|
||||
## 3.9.0
|
||||
|
||||
### Improvements
|
||||
* **Added experimental opt-in support for thread safe assertions**
|
||||
* Read the documentation for full details
|
||||
* **The default test run order has been changed to random**
|
||||
* Passing assertions are significantly faster when the reporter does not ask for `assertionEnded` events on passing assertions.
|
||||
* This is the default behaviour of e.g. Console or Compact reporter
|
||||
* Simple `REQUIRE(true)` is 60% faster in Release and 80% faster in Debug build configuration
|
||||
* Simple `REQUIRE_NOTHROW` is 230% faster in Release and 430% faster in Debug build configuration
|
||||
* Simple `REQUIRE_THROWS` is ~3% faster in Release and 20% faster in Debug build configuration (throwing introduces enough overhead that the optimizations inside Catch2 are mostly irrelevant)
|
||||
* Small (2-5%) improvement if the reporter asks for `assertionEnded` events for passing assertions.
|
||||
* The exit code constants are part of the Session API. (#2955, #2976)
|
||||
* Suppressed unsigned integer overflow checking in locations with intended overflow (#2965)
|
||||
* Reporters flush output after writing metadata, e.g. rng seed (#2964)
|
||||
* Added unreachable after `FAIL` and `SKIP` macros (#2941)
|
||||
* This allows the compiler to understand that the execution does not continue past the macro, and avoids warnings.
|
||||
* Added fast path for `assertionStarting` event when no reporter requires it
|
||||
* For backwards compatibility, this fast path is opt-in
|
||||
* A reporter can opt in by changing its `ReporterPreferences::shouldReportAllAssertionStarts`
|
||||
* Improved last seen source location tracking to be more precise
|
||||
* This is used when reporting unexpected exceptions from tests
|
||||
|
||||
### Fixes
|
||||
* Fixed formatting of tags with more than 100 tests in the default `--list-tags` output (#2963)
|
||||
* Fixed Clang-Tidy's `readability-static-accessed-through-instance` in tests
|
||||
* Fixed most of Clang-Tidy's `cppcoreguidelines-avoid-non-const-global-variables` (#2582)
|
||||
* The lifetime of scoped messages now strictly obeys their scope (#1759, #2019, #2959)
|
||||
* Previously Catch2 would try to keep them around during unexpected exception, to provide helpful context.
|
||||
* The amount of surprises the irregularities caused was not worth the occasional utility provided.
|
||||
* `TEMPLATE_TEST_CASE_SIG` can handle signatures consisting of only types (#2680, #2995)
|
||||
* Moved `catch_test_run_info.hpp` up from `internal/` subfolder into the main one (#2972)
|
||||
|
||||
### Miscellaneous
|
||||
* pkg-config files are now generated at install time (#2979)
|
||||
* This fixes missing debug suffix in library names
|
||||
* This fixes install prefix mismatch between build config and actuall installation
|
||||
|
||||
|
||||
## 3.8.1
|
||||
|
||||
### Fixes
|
||||
* Fixed bug where catch_discover_tests fails when no TEST_CASEs are present (#2962)
|
||||
* Fixed Clang 19 -Wc++20-extensions warning (#2968)
|
||||
|
||||
|
||||
## 3.8.0
|
||||
|
||||
### Improvements
|
||||
* Added `std::initializer_list` overloads for `(Unordered)RangeEquals` matcher (#2915, #2919)
|
||||
* Added explicit casts to silence GCC's `Wconversion` (#2875)
|
||||
* Made the use of `builtin_constant_p` tricks in assertion macros configurable (#2925)
|
||||
* It is used to prod GCC-like compilers into providing warnings for the asserted expressions, but the compilers miscompile it annoyingly often.
|
||||
* Cleaned out Clang-Tidy's `performance-enum-size` warnings
|
||||
* Added support for using `from_range` generator with iterators with `value_type = const T` (#2926)
|
||||
* This is not correct `value_type` typedef, but it is used in the wild and the change does not make the code meaningfully worse.
|
||||
|
||||
### Fixes
|
||||
* Fixed crash when stringifying pre-1970 (epoch) dates on Windows (#2944)
|
||||
|
||||
### Miscellaneous
|
||||
* Fixes and improvements for `catch_discover_tests` CMake helper
|
||||
* Removed redundant `CTEST_FILE` param when creating the indirection file for `PRE_TEST` discovery mode (#2936)
|
||||
* Rewrote the test discovery logic to use output from the JSON reporter
|
||||
* This means that `catch_discover_tests` now requires CMake 3.19 or newer
|
||||
* Added `ADD_TAGS_AS_LABELS` option. If specified, each CTest test will be labeled with corresponding Catch2's test tag
|
||||
* Bumped up the minimum required CMake version to build Catch2 to 3.16
|
||||
* Meson build now provides option to avoid installing Catch2
|
||||
* Bazel build is moved to Bzlmod.
|
||||
|
||||
|
||||
## 3.7.1
|
||||
|
||||
### Improvements
|
||||
* Applied the JUnit reporter's optimization from last release to the SonarQube reporter
|
||||
* Suppressed `-Wuseless-cast` in `CHECK_THROWS_MATCHES` (#2904)
|
||||
* Standardize exit codes for various failures
|
||||
* Running no tests is now guaranteed to exit with 2 (without the `--allow-running-no-tests` flag)
|
||||
* All tests skipped is now always 4 (...)
|
||||
* Assertion failures are now always 42
|
||||
* and so on
|
||||
|
||||
### Fixes
|
||||
* Fixed out-of-bounds access when the arg parser encounters single `-` as an argument (#2905)
|
||||
|
||||
### Miscellaneous
|
||||
* Added `catch_config_prefix_messages.hpp` to meson build (#2903)
|
||||
* `catch_discover_tests` now supports skipped tests (#2873)
|
||||
* You can get the old behaviour by calling `catch_discover_tests` with `SKIP_IS_FAILURE` option.
|
||||
|
||||
|
||||
## 3.7.0
|
||||
|
||||
### Improvements
|
||||
* Slightly improved compile times of benchmarks
|
||||
* Made the resolution estimation in benchmarks slightly more precise
|
||||
* Added new test case macro, `TEST_CASE_PERSISTENT_FIXTURE` (#2885, #1602)
|
||||
* Unlike `TEST_CASE_METHOD`, the same underlying instance is used for all partial runs of that test case
|
||||
* **MASSIVELY** improved performance of the JUnit reporter when handling successful assertions (#2897)
|
||||
* For 1 test case and 10M assertions, the new reporter runs 3x faster and uses up only 8 MB of memory, while the old one needs 7 GB of memory.
|
||||
* Reworked how output redirects works.
|
||||
* Combining a reporter writing to stdout with capturing reporter no longer leads to the capturing reporter seeing all of the other reporter's output.
|
||||
* The file based redirect no longer opens up a new temporary file for each partial test case run, so it will not run out of temporary files when running many tests in single process.
|
||||
|
||||
### Miscellaneous
|
||||
* Better documentation for matchers on thrown exceptions (`REQUIRE_THROWS_MATCHES`)
|
||||
* Improved `catch_discover_tests`'s handling of environment paths (#2878)
|
||||
* It won't reorder paths in `DL_PATHS` or `DYLD_FRAMEWORK_PATHS` args
|
||||
* It won't overwrite the environment paths for test discovery
|
||||
|
||||
|
||||
## 3.6.0
|
||||
|
||||
### Fixes
|
||||
* Fixed Windows ARM64 build by fixing the preprocessor condition guarding use `_umul128` intrinsic.
|
||||
* Fixed Windows ARM64EC build by removing intrinsic pragma it does not understand. (#2858)
|
||||
* Why doesn't the x64-emulation build mode understand x64 pragmas? Don't ask me, ask the MSVC guys.
|
||||
* Fixed the JUnit reporter sometimes crashing when reporting a fatal error. (#1210, #2855)
|
||||
* The binary will still exit, but through the original error, rather than secondary error inside the reporter.
|
||||
* The underlying fix applies to all reporters, not just the JUnit one, but only JUnit was currently causing troubles.
|
||||
|
||||
### Improvements
|
||||
* Disable `-Wnon-virtual-dtor` in Decomposer and Matchers (#2854)
|
||||
* `precision` in floating point stringmakers defaults to `max_digits10`.
|
||||
* This means that floating point values will be printed with enough precision to disambiguate any two floats.
|
||||
* Column wrapping ignores ansi colour codes when calculating string width (#2833, #2849)
|
||||
* This makes the output much more readable when the provided messages contain colour codes.
|
||||
|
||||
### Miscellaneous
|
||||
* Conan support improvements
|
||||
* `compatibility_cppstr` is set to False. (#2860)
|
||||
* This means that Conan won't let you mix library and project with different C++ standard settings.
|
||||
* The implementation library CMake target name through Conan is properly set to `Catch2::Catch2` (#2861)
|
||||
* `SelfTest` target can be built through Bazel (#2857)
|
||||
|
||||
|
||||
## 3.5.4
|
||||
|
||||
### Fixes
|
||||
* Fixed potential compilation error when asked to generate random integers whose type did not match `std::(u)int*_t`.
|
||||
* This manifested itself when generating random `size_t`s on MacOS
|
||||
* Added missing outlined destructor causing `Wdelete-incomplete` when compiling against libstdc++ in C++23 mode (#2852)
|
||||
* Fixed regression where decomposing assertion with const instance of `std::foo_ordering` would not compile
|
||||
|
||||
### Improvements
|
||||
* Reintroduced support for GCC 5 and 6 (#2836)
|
||||
* As with VS2017, if they start causing trouble again, they will be dropped again.
|
||||
* Added workaround for targeting newest MacOS (Sonoma) using GCC (#2837, #2839)
|
||||
* `CATCH_CONFIG_DEFAULT_REPORTER` can now be an arbitrary reporter spec
|
||||
* Previously it could only be a plain reporter name, so it was impossible to compile in custom arguments to the reporter.
|
||||
* Improved performance of generating 64bit random integers by 20+%
|
||||
|
||||
### Miscellaneous
|
||||
* Significantly improved Conan in-tree recipe (#2831)
|
||||
* `DL_PATHS` in `catch_discover_tests` now supports multiple arguments (#2852, #2736)
|
||||
* Fixed preprocessor logic for checking whether we expect reproducible floating point results in tests.
|
||||
* Improved the floating point tests structure to avoid `Wunused` when the reproducibility tests are disabled (#2845)
|
||||
|
||||
|
||||
## 3.5.3
|
||||
|
||||
### Fixes
|
||||
* Fixed OOB access when computing filename tag (from the `-#` flag) for file without extension (#2798)
|
||||
* Fixed the linking against `log` on Android to be `PRIVATE` (#2815)
|
||||
* Fixed `Wuseless-cast` in benchmarking internals (#2823)
|
||||
|
||||
### Improvements
|
||||
* Restored compatibility with VS2017 (#2792, #2822)
|
||||
* The baseline for Catch2 is still C++14 with some reasonable workarounds for specific compilers, so if VS2017 starts acting up again, the support will be dropped again.
|
||||
* Suppressed clang-tidy's `bugprone-chained-comparison` in assertions (#2801)
|
||||
* Improved the static analysis mode to evaluate arguments to `TEST_CASE` and `SECTION` (#2817)
|
||||
* Clang-tidy should no longer warn about runtime arguments to these macros being unused in static analysis mode.
|
||||
* Clang-tidy can warn on issues involved arguments to these macros.
|
||||
* Added support for literal-zero detectors based on `consteval` constructors
|
||||
* This is required for compiling `REQUIRE((a <=> b) == 0)` against MSVC's stdlib.
|
||||
* Sadly, MSVC still cannot compile this assertion as it does not implement C++20 correctly.
|
||||
* You can use `clang-cl` with MSVC's stdlib instead.
|
||||
* If for some godforsaken reasons you want to understand this better, read the two relevant commits: [`dc51386b9fd61f99ea9c660d01867e6ad489b403`](https://github.com/catchorg/Catch2/commit/dc51386b9fd61f99ea9c660d01867e6ad489b403), and [`0787132fc82a75e3fb255aa9484ca1dc1eff2a30`](https://github.com/catchorg/Catch2/commit/0787132fc82a75e3fb255aa9484ca1dc1eff2a30).
|
||||
|
||||
### Miscellaneous
|
||||
* Disabled tests for FP random generator reproducibility on non-SSE2 x86 targets (#2796)
|
||||
* Modified the in-tree Conan recipe to support Conan 2 (#2805)
|
||||
|
||||
|
||||
## 3.5.2
|
||||
|
||||
### Fixes
|
||||
* Fixed `-Wsubobject-linkage` in the Console reporter (#2794)
|
||||
* Fixed adding new CLI Options to lvalue parser using `|` (#2787)
|
||||
|
||||
|
||||
## 3.5.1
|
||||
|
||||
### Improvements
|
||||
* Significantly improved performance of the CLI parsing.
|
||||
* This includes the cost of preparing the CLI parser, so Catch2's binaries start much faster.
|
||||
|
||||
### Miscellaneous
|
||||
* Added support for Bazel modules (#2781)
|
||||
* Added CMake option to disable the build reproducibility settings (#2785)
|
||||
* Added `log` library linking to the Meson build (#2784)
|
||||
|
||||
|
||||
## 3.5.0
|
||||
|
||||
### Improvements
|
||||
* Introduced `CATCH_CONFIG_PREFIX_MESSAGES` to prefix only logging macros (#2544)
|
||||
* This means `INFO`, `UNSCOPED_INFO`, `WARN` and `CAPTURE`.
|
||||
* Section hints in static analysis mode are now `const`
|
||||
* This prevents Clang-Tidy from complaining about `misc-const-correctness`.
|
||||
* `from_range` generator supports C arrays and ranges that require ADL (#2737)
|
||||
* Stringification support for `std::optional` now also includes `std::nullopt` (#2740)
|
||||
* The Console reporter flushes output after writing benchmark runtime estimate.
|
||||
* This means that you can immediately see for how long the benchmark is expected to run.
|
||||
* Added workaround to enable compilation with ICC 19.1 (#2551, #2766)
|
||||
* Compiling Catch2 for XBox should work out of the box (#2772)
|
||||
* Catch2 should automatically disable getenv when compiled for XBox.
|
||||
* Compiling Catch2 with exceptions disabled no longer triggers `Wunused-function` (#2726)
|
||||
* **`random` Generators for integral types are now reproducible across different platforms**
|
||||
* Unlike `<random>`, Catch2's generators also support 1 byte integral types (`char`, `bool`, ...)
|
||||
* **`random` Generators for `float` and `double` are now reproducible across different platforms**
|
||||
* `long double` varies across different platforms too much to be reproducible
|
||||
* This guarantee applies only to platforms with IEEE 754 floats.
|
||||
|
||||
### Fixes
|
||||
* UDL declaration inside Catch2 are now strictly conforming to the standard
|
||||
* `operator "" _a` is UB, `operator ""_a` is fine. Seriously.
|
||||
* Fixed `CAPTURE` tests failing to compile in C++23 mode (#2744)
|
||||
* Fixed missing include in `catch_message.hpp` (#2758)
|
||||
* Fixed `CHECK_ELSE` suppressing failure from uncaught exceptions(#2723)
|
||||
|
||||
### Miscellaneous
|
||||
* The documentation for specifying which tests to run through commandline has been completely rewritten (#2738)
|
||||
* Fixed installation when building Catch2 with meson (#2722, #2742)
|
||||
* Fixed `catch_discover_tests` when using custom reporter and `PRE_TEST` discovery mode (#2747)
|
||||
* `catch_discover_tests` supports multi-config CMake generator in `PRE_TEST` discovery mode (#2739, #2746)
|
||||
|
||||
|
||||
## 3.4.0
|
||||
|
||||
### Improvements
|
||||
* `VectorEquals` supports elements that provide only `==` and not `!=` (#2648)
|
||||
* Catch2 supports compiling with IAR compiler (#2651)
|
||||
* Various small internal performance improvements
|
||||
* Various small internal compilation time improvements
|
||||
* XMLReporter now reports location info for INFO and WARN (#1251)
|
||||
* This bumps up the xml format version to 3
|
||||
* Documented that `SKIP` in generator constructor can be used to handle empty generator (#1593)
|
||||
* Added experimental static analysis support to `TEST_CASE` and `SECTION` macros (#2681)
|
||||
* The two macros are redefined in a way that helps the SA tools reason about the possible paths through a test case with sections.
|
||||
* The support is controlled by the `CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT` option and autodetects clang-tidy and Coverity.
|
||||
* `*_THROWS`, `*_THROWS_AS`, etc now suppress warning coming from `__attribute__((warn_unused_result))` on GCC (#2691)
|
||||
* Unlike plain `[[nodiscard]]`, this warning is not silenced by void cast. WTF GCC?
|
||||
|
||||
### Fixes
|
||||
* Fixed `assertionStarting` events being sent after the expr is evaluated (#2678)
|
||||
* Errors in `TEST_CASE` tags are now reported nicely (#2650)
|
||||
|
||||
### Miscellaneous
|
||||
* Bunch of improvements to `catch_discover_tests`
|
||||
* Added DISCOVERY_MODE option, so the discovery can happen either post build or pre-run.
|
||||
* Fixed handling of semicolons and backslashes in test names (#2674, #2676)
|
||||
* meson build can disable building tests (#2693)
|
||||
* meson build properly sets meson version 0.54.1 as the minimal supported version (#2688)
|
||||
|
||||
|
||||
## 3.3.2
|
||||
|
||||
### Improvements
|
||||
* Further reduced allocations
|
||||
* The compact, console, TAP and XML reporters perform less allocations in various cases
|
||||
* Removed 1 allocation per entered `SECTION`/`TEST_CASE`.
|
||||
* Removed 2 allocations per test case exit, if stdout/stderr is captured
|
||||
* Improved performance
|
||||
* Section tracking is 10%-25% faster than in v3.3.0
|
||||
* Assertion handling is 5%-10% faster than in v3.3.0
|
||||
* Test case registration is 1%-2% faster than in v3.3.0
|
||||
* Tiny speedup for registering listeners
|
||||
* Tiny speedup for `CAPTURE`, `TEST_CASE_METHOD`, `METHOD_AS_TEST_CASE`, and `TEMPLATE_LIST_TEST_*` macros.
|
||||
* `Contains`, `RangeEquals` and `UnorderedRangeEquals` matchers now support ranges with iterator + sentinel pair
|
||||
* Added `IsNaN` matcher
|
||||
* Unlike `REQUIRE(isnan(x))`, `REQUIRE_THAT(x, IsNaN())` shows you the value of `x`.
|
||||
* Suppressed `declared_but_not_referenced` warning for NVHPC (#2637)
|
||||
|
||||
### Fixes
|
||||
* Fixed performance regression in section tracking introduced in v3.3.1
|
||||
* Extreme cases would cause the tracking to run about 4x slower than in 3.3.0
|
||||
|
||||
|
||||
## 3.3.1
|
||||
|
||||
### Improvements
|
||||
* Reduced allocations and improved performance
|
||||
* The exact improvements are dependent on your usage of Catch2.
|
||||
* For example running Catch2's SelfTest binary performs 8k less allocations.
|
||||
* The main improvement comes from smarter handling of `SECTION`s, especially sibling `SECTION`s
|
||||
|
||||
|
||||
## 3.3.0
|
||||
|
||||
### Improvements
|
||||
|
||||
* Added `MessageMatches` exception matcher (#2570)
|
||||
* Added `RangeEquals` and `UnorderedRangeEquals` generic range matchers (#2377)
|
||||
* Added `SKIP` macro for skipping tests from within the test body (#2360)
|
||||
* All built-in reporters have been extended to handle it properly, whether your custom reporter needs changes depends on how it was written
|
||||
* `skipTest` reporter event **is unrelated** to this, and has been deprecated since it has practically no uses
|
||||
* Restored support for PPC Macs in the break-into-debugger functionality (#2619)
|
||||
* Made our warning suppression compatible with CUDA toolkit pre 11.5 (#2626)
|
||||
* Cleaned out some static analysis complaints
|
||||
|
||||
|
||||
### Fixes
|
||||
|
||||
* Fixed macro redefinition warning when NVCC was reporting as MSVC (#2603)
|
||||
* Fixed throws in generator constructor causing the whole binary to abort (#2615)
|
||||
* Now it just fails the test
|
||||
* Fixed missing transitive include with libstdc++13 (#2611)
|
||||
|
||||
|
||||
### Miscellaneous
|
||||
|
||||
* Improved support for dynamic library build with non-MSVC compilers on Windows (#2630)
|
||||
* When used as a subproject, Catch2 keeps its generated header in a separate directory from the main project (#2604)
|
||||
|
||||
|
||||
|
||||
## 3.2.1
|
||||
|
||||
### Improvements
|
||||
* Fix the reworked decomposer to work with older (pre 9) GCC versions (#2571)
|
||||
* **This required more significant changes to properly support C++20, there might be bugs.**
|
||||
|
||||
|
||||
## 3.2.0
|
||||
|
||||
### Improvements
|
||||
* Catch2 now compiles on PlayStation (#2562)
|
||||
* Added `CATCH_CONFIG_GETENV` compile-time toggle (#2562)
|
||||
* This toggle guards whether Catch2 calls `std::getenv` when reading env variables
|
||||
* Added support for more Bazel test environment variables
|
||||
* `TESTBRIDGE_TEST_ONLY` is now supported (#2490)
|
||||
* Sharding variables, `TEST_SHARD_INDEX`, `TEST_TOTAL_SHARDS`, `TEST_SHARD_STATUS_FILE`, are now all supported (#2491)
|
||||
* Bunch of small tweaks and improvements in reporters
|
||||
* The TAP and SonarQube reporters output the used test filters
|
||||
* The XML reporter now also reports the version of its output format
|
||||
* The compact reporter now uses the same summary output as the console reporter (#878, #2554)
|
||||
* Added support for asserting on types that can only be compared with literal 0 (#2555)
|
||||
* A canonical example is C++20's `std::*_ordering` types, which cannot be compared with an `int` variable, only `0`
|
||||
* The support extends to any type with this property, not just the ones in stdlib
|
||||
* This change imposes 2-3% slowdown on compiling files that are heavy on `REQUIRE` and friends
|
||||
* **This required significant rewrite of decomposition, there might be bugs**
|
||||
* Simplified internals of matcher related macros
|
||||
* This provides about ~2% speed up compiling files that are heavy on `REQUIRE_THAT` and friends
|
||||
|
||||
|
||||
### Fixes
|
||||
* Cleaned out some warnings and static analysis issues
|
||||
* Suppressed `-Wcomma` warning rarely occurring in templated test cases (#2543)
|
||||
* Constified implementation details in `INFO` (#2564)
|
||||
* Made `MatcherGenericBase` copy constructor const (#2566)
|
||||
* Fixed serialization of test filters so the output roundtrips
|
||||
* This means that e.g. `./tests/SelfTest "aaa bbb", [approx]` outputs `Filters: "aaa bbb",[approx]`
|
||||
|
||||
|
||||
### Miscellaneous
|
||||
* Catch2's build no longer leaks `-ffile-prefix-map` setting to dependees (#2533)
|
||||
|
||||
|
||||
|
||||
## 3.1.1
|
||||
|
||||
### Improvements
|
||||
* Added `Catch::getSeed` function that user code can call to retrieve current rng-seed
|
||||
* Better detection of compiler support for `-ffile-prefix-map` (#2517)
|
||||
* Catch2's shared libraries now have `SOVERSION` set (#2516)
|
||||
* `catch2/catch_all.hpp` convenience header no longer transitively includes `windows.h` (#2432, #2526)
|
||||
|
||||
|
||||
### Fixes
|
||||
* Fixed compilation on Universal Windows Platform
|
||||
* Fixed compilation on VxWorks (#2515)
|
||||
* Fixed compilation on Cygwin (#2540)
|
||||
* Remove unused variable in reporter registration (#2538)
|
||||
* Fixed some symbol visibility issues with dynamic library on Windows (#2527)
|
||||
* Suppressed `-Wuseless-cast` warnings in `REQUIRE_THROWS*` macros (#2520, #2521)
|
||||
* This was triggered when the potentially throwing expression evaluates to `void`
|
||||
* Fixed "warning: storage class is not first" with `nvc++` (#2533)
|
||||
* Fixed handling of `DL_PATHS` argument to `catch_discover_tests` on MacOS (#2483)
|
||||
* Suppressed `*-avoid-c-arrays` clang-tidy warning in `TEMPLATE_TEST_CASE` (#2095, #2536)
|
||||
|
||||
|
||||
### Miscellaneous
|
||||
* Fixed CMake install step for Catch2 build as dynamic library (#2485)
|
||||
* Raised minimum CMake version to 3.10 (#2523)
|
||||
* Expect the minimum CMake version to increase once more in next few releases.
|
||||
* Whole bunch of doc updates and fixes
|
||||
* #1444, #2497, #2547, #2549, and more
|
||||
* Added support for building Catch2 with Meson (#2530, #2539)
|
||||
|
||||
|
||||
|
||||
## 3.1.0
|
||||
|
||||
### Improvements
|
||||
* Improved suppression of `-Wparentheses` for older GCCs
|
||||
* Turns out that even GCC 9 does not properly handle `_Pragma`s in the C++ frontend.
|
||||
* Added type constraints onto `random` generator (#2433)
|
||||
* These constraints copy what the standard says for the underlying `std::uniform_int_distribution`
|
||||
* Suppressed -Wunused-variable from nvcc (#2306, #2427)
|
||||
* Suppressed -Wunused-variable from MinGW (#2132)
|
||||
* Added All/Any/NoneTrue range matchers (#2319)
|
||||
* These check that all/any/none of boolean values in a range are true.
|
||||
* The JUnit reporter now normalizes classnames from C++ namespaces to Java-like namespaces (#2468)
|
||||
* This provides better support for other JUnit based tools.
|
||||
* The Bazel support now understands `BAZEL_TEST` environment variable (#2459)
|
||||
* The `CATCH_CONFIG_BAZEL_SUPPORT` configuration option is also still supported.
|
||||
* Returned support for compiling Catch2 with GCC 5 (#2448)
|
||||
* This required removing inherited constructors from Catch2's internals.
|
||||
* I recommend updating to a newer GCC anyway.
|
||||
* `catch_discover_tests` now has a new options for setting library load path(s) when running the Catch2 binary (#2467)
|
||||
|
||||
|
||||
### Fixes
|
||||
* Fixed crash when listing listeners without any registered listeners (#2442)
|
||||
* Fixed nvcc compilation error in constructor benchmarking helper (#2477)
|
||||
* Catch2's CMakeList supports pre-3.12 CMake again (#2428)
|
||||
* The gain from requiring CMake 3.12 was very minor, but y'all should really update to newer CMake
|
||||
|
||||
|
||||
### Miscellaneous
|
||||
* Fixed SelfTest build on MinGW (#2447)
|
||||
* The in-repo conan recipe exports the CMake helper (#2460)
|
||||
* Added experimental CMake script to showcase using test case sharding together with CTest
|
||||
* Compared to `catch_discover_tests`, it supports very limited number of options and customization
|
||||
* Added documentation page on best practices when running Catch2 tests
|
||||
* Catch2 can be built as a dynamic library (#2397, #2398)
|
||||
* Note that Catch2 does not have visibility annotations, and you are responsible for ensuring correct visibility built into the resulting library.
|
||||
|
||||
|
||||
|
||||
## 3.0.1
|
||||
|
||||
**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.**
|
||||
|
||||
You probably want to look into the [migration docs](migrate-v2-to-v3.md#top),
|
||||
which were written to help people coming from v2.x.x versions to the
|
||||
v3 releases.
|
||||
|
||||
|
||||
### 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 conscious decision by the user, not something they can just stumble into unknowingly.
|
||||
|
||||
|
||||
### (Potentially) Breaking changes
|
||||
* **Catch2 now uses statically compiled library as its distribution model**
|
||||
* **Including `catch.hpp` no longer works**
|
||||
* **Catch2 now uses C++14 as the minimum support language version**
|
||||
* `ANON_TEST_CASE` has been removed, use `TEST_CASE` with no arguments instead (#1220)
|
||||
* `--list*` commands no longer have non-zero return code (#1410)
|
||||
* `--list-test-names-only` has been removed (#1190)
|
||||
* 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`
|
||||
* `GENERATE` decays its arguments (#2012, #2040)
|
||||
* This means that `str` in `auto str = GENERATE("aa", "bb", "cc");` is inferred to `char const*` rather than `const char[2]`.
|
||||
* `--list-*` flags write their output to file specified by the `-o` flag
|
||||
* Many changes to reporter interfaces
|
||||
* With the exception of the XmlReporter, the outputs of first party reporters should remain the same
|
||||
* New pair of events were added
|
||||
* One obsolete event was removed
|
||||
* The base class has been renamed
|
||||
* The built-in reporter class hierarchy has been redone
|
||||
* Catch2 generates a random seed if one hasn't been specified by the user
|
||||
* The short flag for `--list-tests`, `-l`, has been removed.
|
||||
* This is not a commonly used flag and does not need to use up valuable single-letter space.
|
||||
* The short flag for `--list-tags`, `-t`, has been removed.
|
||||
* This is not a commonly used flag and does not need to use up valuable single-letter space.
|
||||
* The `--colour` option has been replaced with `--colour-mode` option
|
||||
|
||||
|
||||
### 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
|
||||
* `IsEmpty`, `SizeIs` which check that the range has specific properties
|
||||
* `Contains`, which checks whether a range contains a specific element
|
||||
* `AllMatch`, `AnyMatch`, `NoneMatch` range matchers, which apply matchers over a range of elements
|
||||
* Significant compilation time improvements
|
||||
* including `catch_test_macros.hpp` is 80% cheaper than including `catch.hpp`
|
||||
* Some runtime performance optimizations
|
||||
* In all tested cases the v3 branch was faster, so the table below shows the speedup of v3 to v2 at the same task
|
||||
<a id="v3-runtime-optimization-table"></a>
|
||||
|
||||
| task | debug build | release build |
|
||||
|:------------------------------------------- | ------------:| -------------:|
|
||||
| Run 1M `REQUIRE(true)` | 1.10 ± 0.01 | 1.02 ± 0.06 |
|
||||
| Run 100 tests, 3^3 sections, 1 REQUIRE each | 1.27 ± 0.01 | 1.04 ± 0.01 |
|
||||
| Run 3k tests, no names, no tags | 1.29 ± 0.01 | 1.05 ± 0.01 |
|
||||
| Run 3k tests, names, tags | 1.49 ± 0.01 | 1.22 ± 0.01 |
|
||||
| Run 1 out of 3k tests no names, no tags | 1.68 ± 0.02 | 1.19 ± 0.22 |
|
||||
| Run 1 out of 3k tests, names, tags | 1.79 ± 0.02 | 2.06 ± 0.23 |
|
||||
|
||||
|
||||
* POSIX platforms use `gmtime_r`, rather than `gmtime` when constructing a date string (#2008, #2165)
|
||||
* `--list-*` flags write their output to file specified by the `-o` flag (#2061, #2163)
|
||||
* `Approx::operator()` is now properly `const`
|
||||
* Catch2's internal helper variables no longer use reserved identifiers (#578)
|
||||
* `--rng-seed` now accepts string `"random-device"` to generate random seed using `std::random_device`
|
||||
* Catch2 now supports test sharding (#2257)
|
||||
* You can ask for the tests to be split into N groups and only run one of them.
|
||||
* This greatly simplifies parallelization of tests in a binary through external runner.
|
||||
* The embedded CLI parser now supports repeatedly callable lambdas
|
||||
* A lambda-based option parser can opt into being repeatedly specifiable.
|
||||
* Added `STATIC_CHECK` macro, similar to `STATIC_REQUIRE` (#2318)
|
||||
* When deferred tu runtime, it behaves like `CHECK`, and not like `REQUIRE`.
|
||||
* You can have multiple tests with the same name, as long as other parts of the test identity differ (#1915, #1999, #2175)
|
||||
* Test identity includes test's name, test's tags and test's class name if applicable.
|
||||
* Added new warning, `UnmatchedTestSpec`, to error on test specs with no matching tests
|
||||
* The `-w`, `--warn` warning flags can now be provided multiple times to enable multiple warnings
|
||||
* The case-insensitive handling of tags is now more reliable and takes up less memory
|
||||
* Test case and assertion counting can no longer reasonably overflow on 32 bit systems
|
||||
* The count is now kept in `uint64_t` on all platforms, instead of using `size_t` type.
|
||||
* The `-o`, `--out` output destination specifiers recognize `-` as stdout
|
||||
* You have to provide it as `--out=-` to avoid CLI error about missing option
|
||||
* The new reporter specification also recognizes `-` as stdout
|
||||
* Multiple reporters can now run at the same time and write to different files (#1712, #2183)
|
||||
* To support this, the `-r`, `--reporter` flag now also accepts optional output destination
|
||||
* For full overview of the semantics of using multiple reporters, look into the reporter documentation
|
||||
* To enable the new syntax, reporter names can no longer contain `::`.
|
||||
* Console colour support has been rewritten and significantly improved
|
||||
* The colour implementation based on ANSI colour codes is always available
|
||||
* Colour implementations respect their associated stream
|
||||
* previously e.g. Win32 impl would change console colour even if Catch2 was writing to a file
|
||||
* The colour API is resilient against changing evaluation order of expressions
|
||||
* The associated CLI flag and compile-time configuration options have changed
|
||||
* For details see the docs for command-line and compile-time Catch2 configuration
|
||||
* Added a support for Bazel integration with `XML_OUTPUT_FILE` env var (#2399)
|
||||
* This has to be enabled during compilation.
|
||||
* Added `--skip-benchmarks` flag to run tests without any `BENCHMARK`s (#2392, #2408)
|
||||
* Added option to list all listeners in the binary via `--list-listeners`
|
||||
|
||||
|
||||
### Fixes
|
||||
* The `INFO` macro no longer contains superfluous semicolon (#1456)
|
||||
* The `--list*` family of command line flags now return 0 on success (#1410, #1146)
|
||||
* Various ways of failing a benchmark are now counted and reporter properly
|
||||
* The ULP matcher now handles comparing numbers with different signs properly (#2152)
|
||||
* Universal ADL-found operators should no longer break decomposition (#2121)
|
||||
* Reporter selection is properly case-insensitive
|
||||
* Previously it forced lower cased name, which would fail for reporters with upper case characters in name
|
||||
* The cumulative reporter base stores benchmark results alongside assertion results
|
||||
* Catch2's SE handling should no longer interferes with ASan on Windows (#2334)
|
||||
* Fixed Windows console colour handling for tests that redirect stdout (#2345)
|
||||
* Fixed issue with the `random` generators returning the same value over and over again
|
||||
|
||||
|
||||
### 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
|
||||
* Passing invalid test specifications passed to Catch2 are now reported before tests are run, and are a hard error.
|
||||
* Running 0 tests (e.g. due to empty binary, or test spec not matching anything) returns non-0 exit code
|
||||
* Flag `--allow-running-no-tests` overrides this behaviour.
|
||||
* `NoTests` warning has been removed because it is fully subsumed by this change.
|
||||
* Catch2's compile-time configuration options (`CATCH_CONFIG_FOO`) can be set through CMake options of the same name
|
||||
* They use the same semantics as C++ defines, including the `CATCH_CONFIG_NO_FOO` overrides,
|
||||
* `-DCATCH_CONFIG_DEFAULT_REPORTER=compact` changes default reporter to "compact"
|
||||
* `-DCATCH_CONFIG_NO_ANDROID_LOGWRITE=ON` forces android logwrite to off
|
||||
* `-DCATCH_CONFIG_ANDROID_LOGWRITE=OFF` does nothing (the define will not exist)
|
||||
|
||||
|
||||
|
||||
## 2.13.7
|
||||
|
||||
### Fixes
|
||||
* Added missing `<iterator>` include in benchmarking. (#2231)
|
||||
* Fixed noexcept build with benchmarking enabled (#2235)
|
||||
* Fixed build for compilers with C++17 support but without C++17 library support (#2195)
|
||||
* JUnit only uses 3 decimal places when reporting durations (#2221)
|
||||
* `!mayfail` tagged tests are now marked as `skipped` in JUnit reporter output (#2116)
|
||||
|
||||
|
||||
## 2.13.6
|
||||
|
||||
### Fixes
|
||||
* Disabling all signal handlers no longer breaks compilation (#2212, #2213)
|
||||
|
||||
### Miscellaneous
|
||||
* `catch_discover_tests` should handle escaped semicolon (`;`) better (#2214, #2215)
|
||||
|
||||
|
||||
## 2.13.5
|
||||
|
||||
### Improvements
|
||||
* Detection of MAC and IPHONE platforms has been improved (#2140, #2157)
|
||||
* Added workaround for bug in XLC 16.1.0.1 (#2155)
|
||||
* Add detection for LCC when it is masquerading as GCC (#2199)
|
||||
* Modified posix signal handling so it supports newer libcs (#2178)
|
||||
* `MINSIGSTKSZ` was no longer usable in constexpr context.
|
||||
|
||||
### Fixes
|
||||
* Fixed compilation of benchmarking when `min` and `max` macros are defined (#2159)
|
||||
* Including `windows.h` without `NOMINMAX` remains a really bad idea, don't do it
|
||||
|
||||
### Miscellaneous
|
||||
* The check whether Catch2 is being built as a subproject is now more reliable (#2202, #2204)
|
||||
* The problem was that if the variable name used internally was defined the project including Catch2 as subproject, it would not be properly overwritten for Catch2's CMake.
|
||||
|
||||
|
||||
## 2.13.4
|
||||
|
||||
### Improvements
|
||||
* Improved the hashing algorithm used for shuffling test cases (#2070)
|
||||
* `TEST_CASE`s that differ only in the last character should be properly shuffled
|
||||
* Note that this means that v2.13.4 gives you a different order of test cases than 2.13.3, even given the same seed.
|
||||
|
||||
### Miscellaneous
|
||||
* Deprecated `ParseAndAddCatchTests` CMake integration (#2092)
|
||||
* It is impossible to implement it properly for all the different test case variants Catch2 provides, and there are better options provided.
|
||||
* Use `catch_discover_tests` instead, which uses runtime information about available tests.
|
||||
* Fixed bug in `catch_discover_tests` that would cause it to fail when used in specific project structures (#2119)
|
||||
* Added Bazel build file
|
||||
* Added an experimental static library target to CMake
|
||||
|
||||
|
||||
## 2.13.3
|
||||
|
||||
### Fixes
|
||||
* Fixed possible infinite loop when combining generators with section filter (`-c` option) (#2025)
|
||||
|
||||
### Miscellaneous
|
||||
* Fixed `ParseAndAddCatchTests` not finding `TEST_CASE`s without tags (#2055, #2056)
|
||||
* `ParseAndAddCatchTests` supports `CMP0110` policy for changing behaviour of `add_test` (#2057)
|
||||
* This was the shortlived change in CMake 3.18.0 that temporarily broke `ParseAndAddCatchTests`
|
||||
|
||||
|
||||
## 2.13.2
|
||||
|
||||
### Improvements
|
||||
* Implemented workaround for AppleClang shadowing bug (#2030)
|
||||
* Implemented workaround for NVCC ICE (#2005, #2027)
|
||||
|
||||
### Fixes
|
||||
* Fixed detection of `std::uncaught_exceptions` support under non-msvc platforms (#2021)
|
||||
* Fixed the experimental stdout/stderr capture under Windows (#2013)
|
||||
|
||||
### Miscellaneous
|
||||
* `catch_discover_tests` has been improved significantly (#2023, #2039)
|
||||
* You can now specify which reporter should be used
|
||||
* You can now modify where the output will be written
|
||||
* `WORKING_DIRECTORY` setting is respected
|
||||
* `ParseAndAddCatchTests` now supports `TEMPLATE_TEST_CASE` macros (#2031)
|
||||
* Various documentation fixes and improvements (#2022, #2028, #2034)
|
||||
|
||||
|
||||
## 2.13.1
|
||||
|
||||
### Improvements
|
||||
@@ -808,7 +61,7 @@ v3 releases.
|
||||
* The `SECTION`(s) before the `GENERATE` will not be run multiple times, the following ones will.
|
||||
* Added `-D`/`--min-duration` command line flag (#1910)
|
||||
* If a test takes longer to finish than the provided value, its name and duration will be printed.
|
||||
* This flag is overridden by setting `-d`/`--duration`.
|
||||
* This flag is overriden by setting `-d`/`--duration`.
|
||||
|
||||
### Fixes
|
||||
* `TAPReporter` no longer skips successful assertions (#1983)
|
||||
@@ -849,7 +102,7 @@ v3 releases.
|
||||
### Improvements
|
||||
* `std::result_of` is not used if `std::invoke_result` is available (#1934)
|
||||
* JUnit reporter writes out `status` attribute for tests (#1899)
|
||||
* Suppressed clang-tidy's `hicpp-vararg` warning (#1921)
|
||||
* Suppresed clang-tidy's `hicpp-vararg` warning (#1921)
|
||||
* Catch2 was already suppressing the `cppcoreguidelines-pro-type-vararg` alias of the warning
|
||||
|
||||
|
||||
@@ -862,7 +115,6 @@ v3 releases.
|
||||
* Added support for `^` (bitwise xor) to `CHECK` and `REQUIRE`
|
||||
|
||||
|
||||
|
||||
## 2.12.0
|
||||
|
||||
### Improvements
|
||||
@@ -876,7 +128,7 @@ v3 releases.
|
||||
### Fixes
|
||||
* Fixed computation of benchmarking column widths in ConsoleReporter (#1885, #1886)
|
||||
* Suppressed clang-tidy's `cppcoreguidelines-pro-type-vararg` in assertions (#1901)
|
||||
* It was a false positive triggered by the new warning support workaround
|
||||
* It was a false positive trigered by the new warning support workaround
|
||||
* Fixed bug in test specification parser handling of OR'd patterns using escaping (#1905)
|
||||
|
||||
### Miscellaneous
|
||||
@@ -885,7 +137,6 @@ v3 releases.
|
||||
* Improved detection of stdlib's support for `std::uncaught_exceptions` (#1911)
|
||||
|
||||
|
||||
|
||||
## 2.11.3
|
||||
|
||||
### Fixes
|
||||
@@ -917,7 +168,6 @@ v3 releases.
|
||||
* This bug has been present for the last ~2 years and nobody reported it
|
||||
|
||||
|
||||
|
||||
## 2.11.1
|
||||
|
||||
### Improvements
|
||||
@@ -931,7 +181,6 @@ v3 releases.
|
||||
* Some more cleanups in the benchmarking support
|
||||
|
||||
|
||||
|
||||
## 2.11.0
|
||||
|
||||
### Improvements
|
||||
@@ -1065,7 +314,6 @@ v3 releases.
|
||||
### Fixes
|
||||
* Fix benchmarking compilation failure in files without `CATCH_CONFIG_EXTERNAL_INTERFACES` (or implementation)
|
||||
|
||||
|
||||
## 2.9.0
|
||||
|
||||
### Improvements
|
||||
@@ -1213,7 +461,7 @@ v3 releases.
|
||||
|
||||
### Contrib
|
||||
* `ParseAndAddCatchTests` has learned how to use `DISABLED` CTest property (#1452)
|
||||
* `ParseAndAddCatchTests` now works when there is a whitespace before the test name (#1493)
|
||||
* `ParseAndAddCatchTests` now works when there is a whitspace before the test name (#1493)
|
||||
|
||||
|
||||
### Miscellaneous
|
||||
@@ -1398,7 +646,7 @@ than `single_include/catch.hpp`.**
|
||||
* CLR objects (`T^`) can now be stringified (#1216)
|
||||
* This affects code compiled as C++/CLI
|
||||
* Added `PredicateMatcher`, a matcher that takes an arbitrary predicate function (#1236)
|
||||
* See [documentation for details](https://github.com/catchorg/Catch2/blob/devel/docs/matchers.md)
|
||||
* See [documentation for details](https://github.com/catchorg/Catch2/blob/master/docs/matchers.md)
|
||||
|
||||
### Others
|
||||
* Modified CMake-installed pkg-config to allow `#include <catch.hpp>`(#1239)
|
||||
@@ -1426,7 +674,7 @@ than `single_include/catch.hpp`.**
|
||||
* Added an option to warn (+ exit with error) when no tests were ran (#1158)
|
||||
* Use as `-w NoTests`
|
||||
* Added provisional support for Emscripten (#1114)
|
||||
* [Added a way to override the fallback stringifier](https://github.com/catchorg/Catch2/blob/devel/docs/configuration.md#fallback-stringifier) (#1024)
|
||||
* [Added a way to override the fallback stringifier](https://github.com/catchorg/Catch2/blob/master/docs/configuration.md#fallback-stringifier) (#1024)
|
||||
* This allows project's own stringification machinery to be easily reused for Catch
|
||||
* `Catch::Session::run()` now accepts `char const * const *`, allowing it to accept array of string literals (#1031, #1178)
|
||||
* The embedded version of Clara was bumped to v1.1.3
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<a id="top"></a>
|
||||
# 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
|
||||
|
||||
@@ -40,10 +40,14 @@ After version number is incremented, single-include header is regenerated and re
|
||||
After pushing changes to GitHub, GitHub release *needs* to be created.
|
||||
Tag version and release title should be same as the new version,
|
||||
description should contain the release notes for the current release.
|
||||
We also attach the two amalgamated files as "binaries".
|
||||
Single header version of `catch.hpp` *needs* to be attached as a binary,
|
||||
as that is where the official download link links to. Preferably
|
||||
it should use linux line endings. All non-bundled reporters (Automake, TAP,
|
||||
TeamCity, SonarQube) should also be attached as binaries, as they might be
|
||||
dependent on a specific version of the single-include header.
|
||||
|
||||
Since 2.5.0, the release tag and the "binaries" (amalgamated files) should
|
||||
be PGP signed.
|
||||
Since 2.5.0, the release tag and the "binaries" (headers) should be PGP
|
||||
signed.
|
||||
|
||||
#### Signing a tag
|
||||
|
||||
@@ -53,14 +57,17 @@ is the version being released, e.g. `git tag -s v2.6.0`.
|
||||
Use the version name as the short message and the release notes as
|
||||
the body (long) message.
|
||||
|
||||
#### Signing the amalgamated files
|
||||
#### Signing the headers
|
||||
|
||||
This will create ASCII-armored signatures for the two amalgamated files
|
||||
that are uploaded to the GitHub release:
|
||||
This will create ASCII-armored signatures for the headers that are
|
||||
uploaded to the GitHub release:
|
||||
|
||||
```
|
||||
gpg --armor --output extras/catch_amalgamated.hpp.asc --detach-sig extras/catch_amalgamated.hpp
|
||||
gpg --armor --output extras/catch_amalgamated.cpp.asc --detach-sig extras/catch_amalgamated.cpp
|
||||
$ 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_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_sonarqube.hpp.asc --detach-sig catch_reporter_sonarqube.hpp
|
||||
```
|
||||
|
||||
_GPG does not support signing multiple files in single invocation._
|
||||
|
@@ -1,175 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Reporter events
|
||||
|
||||
**Contents**<br>
|
||||
[Test running events](#test-running-events)<br>
|
||||
[Benchmarking events](#benchmarking-events)<br>
|
||||
[Listings events](#listings-events)<br>
|
||||
[Miscellaneous events](#miscellaneous-events)<br>
|
||||
|
||||
Reporter events are one of the customization points for user code. They
|
||||
are used by [reporters](reporters.md#top) to customize Catch2's output,
|
||||
and by [event listeners](event-listeners.md#top) to perform in-process
|
||||
actions under some conditions.
|
||||
|
||||
There are currently 21 reporter events in Catch2, split between 4 distinct
|
||||
event groups:
|
||||
* test running events (10 events)
|
||||
* benchmarking (4 events)
|
||||
* listings (3 events)
|
||||
* miscellaneous (4 events)
|
||||
|
||||
## Test running events
|
||||
|
||||
Test running events are always paired so that for each `fooStarting` event,
|
||||
there is a `fooEnded` event. This means that the 10 test running events
|
||||
consist of 5 pairs of events:
|
||||
|
||||
* `testRunStarting` and `testRunEnded`,
|
||||
* `testCaseStarting` and `testCaseEnded`,
|
||||
* `testCasePartialStarting` and `testCasePartialEnded`,
|
||||
* `sectionStarting` and `sectionEnded`,
|
||||
* `assertionStarting` and `assertionEnded`
|
||||
|
||||
### `testRun` events
|
||||
|
||||
```cpp
|
||||
void testRunStarting( TestRunInfo const& testRunInfo );
|
||||
void testRunEnded( TestRunStats const& testRunStats );
|
||||
```
|
||||
|
||||
The `testRun` events bookend the entire test run. `testRunStarting` is
|
||||
emitted before the first test case is executed, and `testRunEnded` is
|
||||
emitted after all the test cases have been executed.
|
||||
|
||||
### `testCase` events
|
||||
|
||||
```cpp
|
||||
void testCaseStarting( TestCaseInfo const& testInfo );
|
||||
void testCaseEnded( TestCaseStats const& testCaseStats );
|
||||
```
|
||||
|
||||
The `testCase` events bookend one _full_ run of a specific test case.
|
||||
Individual runs through a test case, e.g. due to `SECTION`s or `GENERATE`s,
|
||||
are handled by a different event.
|
||||
|
||||
|
||||
### `testCasePartial` events
|
||||
|
||||
> Introduced in Catch2 3.0.1
|
||||
|
||||
```cpp
|
||||
void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber );
|
||||
void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber );
|
||||
```
|
||||
|
||||
`testCasePartial` events bookend one _partial_ run of a specific test case.
|
||||
This means that for any given test case, these events can be emitted
|
||||
multiple times, e.g. due to multiple leaf sections.
|
||||
|
||||
In regards to nesting with `testCase` events, `testCasePartialStarting`
|
||||
will never be emitted before the corresponding `testCaseStarting`, and
|
||||
`testCasePartialEnded` will always be emitted before the corresponding
|
||||
`testCaseEnded`.
|
||||
|
||||
|
||||
### `section` events
|
||||
|
||||
```cpp
|
||||
void sectionStarting( SectionInfo const& sectionInfo );
|
||||
void sectionEnded( SectionStats const& sectionStats );
|
||||
```
|
||||
|
||||
`section` events are emitted only for active `SECTION`s, that is, sections
|
||||
that are entered. Sections that are skipped in this test case run-through
|
||||
do not cause events to be emitted.
|
||||
|
||||
_Note that test cases always contain one implicit section. The event for
|
||||
this section is emitted after the corresponding `testCasePartialStarting`
|
||||
event._
|
||||
|
||||
|
||||
### `assertion` events
|
||||
|
||||
```cpp
|
||||
void assertionStarting( AssertionInfo const& assertionInfo );
|
||||
void assertionEnded( AssertionStats const& assertionStats );
|
||||
```
|
||||
|
||||
The `assertionStarting` event is emitted before the expression in the
|
||||
assertion is captured or evaluated and `assertionEnded` is emitted
|
||||
afterwards. This means that given assertion like `REQUIRE(a + b == c + d)`,
|
||||
Catch2 first emits `assertionStarting` event, then `a + b` and `c + d`
|
||||
are evaluated, then their results are captured, the comparison is evaluated,
|
||||
and then `assertionEnded` event is emitted.
|
||||
|
||||
|
||||
## Benchmarking events
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
|
||||
|
||||
```cpp
|
||||
void benchmarkPreparing( StringRef name ) override;
|
||||
void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
|
||||
void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
|
||||
void benchmarkFailed( StringRef error ) override;
|
||||
```
|
||||
|
||||
Due to the benchmark lifecycle being bit more complicated, the benchmarking
|
||||
events have their own category, even though they could be seen as parallel
|
||||
to the `assertion*` events. You should expect running a benchmark to
|
||||
generate at least 2 of the events above.
|
||||
|
||||
To understand the explanation below, you should read the [benchmarking
|
||||
documentation](benchmarks.md#top) first.
|
||||
|
||||
* `benchmarkPreparing` event is sent after the environmental probe
|
||||
finishes, but before the user code is first estimated.
|
||||
* `benchmarkStarting` event is sent after the user code is estimated,
|
||||
but has not been benchmarked yet.
|
||||
* `benchmarkEnded` event is sent after the user code has been benchmarked,
|
||||
and contains the benchmarking results.
|
||||
* `benchmarkFailed` event is sent if either the estimation or the
|
||||
benchmarking itself fails.
|
||||
|
||||
|
||||
## Listings events
|
||||
|
||||
> Introduced in Catch2 3.0.1.
|
||||
|
||||
Listings events are events that correspond to the test binary being
|
||||
invoked with `--list-foo` flag.
|
||||
|
||||
There are currently 3 listing events, one for reporters, one for tests,
|
||||
and one for tags. Note that they are not exclusive to each other.
|
||||
|
||||
```cpp
|
||||
void listReporters( std::vector<ReporterDescription> const& descriptions );
|
||||
void listTests( std::vector<TestCaseHandle> const& tests );
|
||||
void listTags( std::vector<TagInfo> const& tagInfos );
|
||||
```
|
||||
|
||||
|
||||
## Miscellaneous events
|
||||
|
||||
```cpp
|
||||
void reportInvalidTestSpec( StringRef unmatchedSpec );
|
||||
void fatalErrorEncountered( StringRef error );
|
||||
void noMatchingTestCases( StringRef unmatchedSpec );
|
||||
```
|
||||
|
||||
These are one-off events that do not neatly fit into other categories.
|
||||
|
||||
`reportInvalidTestSpec` is sent for each [test specification command line
|
||||
argument](command-line.md#specifying-which-tests-to-run) that wasn't
|
||||
parsed into a valid spec.
|
||||
|
||||
`fatalErrorEncountered` is sent when Catch2's POSIX signal handling
|
||||
or Windows SE handler is called into with a fatal signal/exception.
|
||||
|
||||
`noMatchingTestCases` is sent for each user provided test specification
|
||||
that did not match any registered tests.
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -1,217 +1,46 @@
|
||||
<a id="top"></a>
|
||||
# Reporters
|
||||
|
||||
Reporters are a customization point for most of Catch2's output, e.g.
|
||||
formatting and writing out [assertions (whether passing or failing),
|
||||
sections, test cases, benchmarks, and so on](reporter-events.md#top).
|
||||
|
||||
Catch2 comes with a bunch of reporters by default (currently 9), and
|
||||
you can also write your own reporter. Because multiple reporters can
|
||||
be active at the same time, your own reporters do not even have to handle
|
||||
all reporter event, just the ones you are interested in, e.g. benchmarks.
|
||||
|
||||
Catch has a modular reporting system and comes bundled with a handful of useful reporters built in.
|
||||
You can also write your own reporters.
|
||||
|
||||
## Using different reporters
|
||||
|
||||
You can see which reporters are available by running the test binary
|
||||
with `--list-reporters`. You can then pick one of them with the [`-r`,
|
||||
`--reporter` option](command-line.md#choosing-a-reporter-to-use), followed
|
||||
by the name of the desired reporter, like so:
|
||||
The reporter to use can easily be controlled from the command line.
|
||||
To specify a reporter use [`-r` or `--reporter`](command-line.md#choosing-a-reporter-to-use), followed by the name of the reporter, e.g.:
|
||||
|
||||
```
|
||||
--reporter xml
|
||||
-r xml
|
||||
```
|
||||
|
||||
You can also select multiple reporters to be used at the same time.
|
||||
In that case you should read the [section on using multiple
|
||||
reporters](#multiple-reporters) to avoid any surprises from doing so.
|
||||
If you don't specify a reporter then the console reporter is used by default.
|
||||
There are four reporters built in to the single include:
|
||||
|
||||
* `console` writes as lines of text, formatted to a typical terminal width, with colours if a capable terminal is detected.
|
||||
* `compact` similar to `console` but optimised for minimal output - each entry on one line
|
||||
* `junit` writes xml that corresponds to Ant's [junitreport](http://help.catchsoftware.com/display/ET/JUnit+Format) target. Useful for build systems that understand Junit.
|
||||
Because of the way the junit format is structured the run must complete before anything is written.
|
||||
* `xml` writes an xml format tailored to Catch. Unlike `junit` this is a streaming format so results are delivered progressively.
|
||||
|
||||
<a id="multiple-reporters"></a>
|
||||
## Using multiple reporters
|
||||
There are a few additional reporters, for specific build systems, in the Catch repository (in `include\reporters`) which you can `#include` in your project if you would like to make use of them.
|
||||
Do this in one source file - the same one you have `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`.
|
||||
|
||||
> Support for having multiple parallel reporters was [introduced](https://github.com/catchorg/Catch2/pull/2183) in Catch2 3.0.1
|
||||
|
||||
Catch2 supports using multiple reporters at the same time while having
|
||||
them write into different destinations. The two main uses of this are
|
||||
|
||||
* having both human-friendly and machine-parseable (e.g. in JUnit format)
|
||||
output from one run of binary
|
||||
* having "partial" reporters that are highly specialized, e.g. having one
|
||||
reporter that writes out benchmark results as markdown tables and does
|
||||
nothing else, while also having standard testing output separately
|
||||
|
||||
Specifying multiple reporter looks like this:
|
||||
```
|
||||
--reporter JUnit::out=result-junit.xml --reporter console::out=-::colour-mode=ansi
|
||||
```
|
||||
|
||||
This tells Catch2 to use two reporters, `JUnit` reporter that writes
|
||||
its machine-readable XML output to file `result-junit.xml`, and the
|
||||
`console` reporter that writes its user-friendly output to stdout and
|
||||
uses ANSI colour codes for colouring the output.
|
||||
|
||||
Using multiple reporters (or one reporter and one-or-more [event
|
||||
listeners](event-listeners.md#top)) can have surprisingly complex semantics
|
||||
when using customization points provided to reporters by Catch2, namely
|
||||
capturing stdout/stderr from test cases.
|
||||
|
||||
As long as at least one reporter (or listener) asks Catch2 to capture
|
||||
stdout/stderr, captured stdout and stderr will be available to all
|
||||
reporters and listeners.
|
||||
|
||||
Because this might be surprising to the users, if at least one active
|
||||
_reporter_ is non-capturing, then Catch2 tries to roughly emulate
|
||||
non-capturing behaviour by printing out the captured stdout/stderr
|
||||
just before `testCasePartialEnded` event is sent out to the active
|
||||
reporters and listeners. This means that stdout/stderr is no longer
|
||||
printed out from tests as it is being written, but instead it is written
|
||||
out in batch after each runthrough of a test case is finished.
|
||||
* `teamcity` writes the native, streaming, format that [TeamCity](https://www.jetbrains.com/teamcity/) understands.
|
||||
Use this when building as part of a TeamCity build to see results as they happen ([code example](../examples/207-Rpt-TeamCityReporter.cpp)).
|
||||
* `tap` writes in the TAP ([Test Anything Protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) format.
|
||||
* `automake` writes in a format that correspond to [automake .trs](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html) files
|
||||
* `sonarqube` writes the [SonarQube Generic Test Data](https://docs.sonarqube.org/latest/analysis/generic-test/) XML format.
|
||||
|
||||
You see what reporters are available from the command line by running with `--list-reporters`.
|
||||
|
||||
By default all these reports are written to stdout, but can be redirected to a file with [`-o` or `--out`](command-line.md#sending-output-to-a-file)
|
||||
|
||||
## Writing your own reporter
|
||||
|
||||
You can also write your own custom reporter and tell Catch2 to use it.
|
||||
When writing your reporter, you have two options:
|
||||
|
||||
* Derive from `Catch::ReporterBase`. When doing this, you will have
|
||||
to provide handling for all [reporter events](reporter-events.md#top).
|
||||
* Derive from one of the provided [utility reporter bases in
|
||||
Catch2](#utility-reporter-bases).
|
||||
|
||||
Generally we recommend doing the latter, as it is less work.
|
||||
|
||||
Apart from overriding handling of the individual reporter events, reporters
|
||||
have access to some extra customization points, described below.
|
||||
|
||||
|
||||
### Utility reporter bases
|
||||
|
||||
Catch2 currently provides two utility reporter bases:
|
||||
|
||||
* `Catch::StreamingReporterBase`
|
||||
* `Catch::CumulativeReporterBase`
|
||||
|
||||
`StreamingReporterBase` is useful for reporters that can format and write
|
||||
out the events as they come in. It provides (usually empty) implementation
|
||||
for all reporter events, and if you let it handle the relevant events,
|
||||
it also handles storing information about active test run and test case.
|
||||
|
||||
`CumulativeReporterBase` is a base for reporters that need to see the whole
|
||||
test run, before they can start writing the output, such as the JUnit
|
||||
and SonarQube reporters. This post-facto approach requires the assertions
|
||||
to be stringified when it is finished, so that the assertion can be written
|
||||
out later. Because the stringification can be expensive, and not all
|
||||
cumulative reporters need the assertions, this base provides customization
|
||||
point to change whether the assertions are saved or not, separate for
|
||||
passing and failing assertions.
|
||||
|
||||
|
||||
_Generally we recommend that if you override a member function from either
|
||||
of the bases, you call into the base's implementation first. This is not
|
||||
necessarily in all cases, but it is safer and easier._
|
||||
|
||||
|
||||
Writing your own reporter then looks like this:
|
||||
|
||||
```cpp
|
||||
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class PartialReporter : public Catch::StreamingReporterBase {
|
||||
public:
|
||||
using StreamingReporterBase::StreamingReporterBase;
|
||||
|
||||
static std::string getDescription() {
|
||||
return "Reporter for testing TestCasePartialStarting/Ended events";
|
||||
}
|
||||
|
||||
void testCasePartialStarting(Catch::TestCaseInfo const& testInfo,
|
||||
uint64_t partNumber) override {
|
||||
std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n';
|
||||
}
|
||||
|
||||
void testCasePartialEnded(Catch::TestCaseStats const& testCaseStats,
|
||||
uint64_t partNumber) override {
|
||||
std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
CATCH_REGISTER_REPORTER("partial", PartialReporter)
|
||||
```
|
||||
|
||||
This create a simple reporter that responds to `testCasePartial*` events,
|
||||
and calls itself "partial" reporter, so it can be invoked with
|
||||
`--reporter partial` command line flag.
|
||||
|
||||
|
||||
### `ReporterPreferences`
|
||||
|
||||
Each reporter instance contains instance of `ReporterPreferences`, a type
|
||||
that holds flags for the behaviour of Catch2 when this reporter run.
|
||||
Currently there are three customization options:
|
||||
|
||||
* `shouldRedirectStdOut` - whether the reporter wants to handle
|
||||
writes to stdout/stderr from user code, or not. This is useful for
|
||||
reporters that output machine-parseable output, e.g. the JUnit
|
||||
reporter, or the XML reporter.
|
||||
* `shouldReportAllAssertions` - whether the reporter wants to handle
|
||||
`assertionEnded` events for passing assertions as well as failing
|
||||
assertions. Usually reporters do not report successful assertions
|
||||
and don't need them for their output, but sometimes the desired output
|
||||
format includes passing assertions even without the `-s` flag.
|
||||
* `shouldReportAllAssertionStarts` - whether the reporter wants to handle
|
||||
`assertionStarting` events. Most reporters do not, and opting out
|
||||
explicitly enables a fast-path in Catch2's handling of assertions.
|
||||
|
||||
> `shouldReportAllAssertionStarts` was introduced in Catch2 3.9.0
|
||||
|
||||
|
||||
### Per-reporter configuration
|
||||
|
||||
> Per-reporter configuration was introduced in Catch2 3.0.1
|
||||
|
||||
Catch2 supports some configuration to happen per reporter. The configuration
|
||||
options fall into one of two categories:
|
||||
|
||||
* Catch2-recognized options
|
||||
* Reporter-specific options
|
||||
|
||||
The former is a small set of universal options that Catch2 handles for
|
||||
the reporters, e.g. output file or console colour mode. The latter are
|
||||
options that the reporters have to handle themselves, but the keys and
|
||||
values can be arbitrary strings, as long as they don't contain `::`. This
|
||||
allows writing reporters that can be significantly customized at runtime.
|
||||
|
||||
Reporter-specific options always have to be prefixed with "X" (large
|
||||
letter X).
|
||||
|
||||
|
||||
### Other expected functionality of a reporter
|
||||
|
||||
When writing a custom reporter, there are few more things that you should
|
||||
keep in mind. These are not important for correctness, but they are
|
||||
important for the reporter to work _nicely_.
|
||||
|
||||
* Catch2 provides a simple verbosity option for users. There are three
|
||||
verbosity levels, "quiet", "normal", and "high", and if it makes sense
|
||||
for reporter's output format, it should respond to these by changing
|
||||
what, and how much, it writes out.
|
||||
|
||||
* Catch2 operates with an rng-seed. Knowing what seed a test run had
|
||||
is important if you want to replicate it, so your reporter should
|
||||
report the rng-seed, if at all possible given the target output format.
|
||||
|
||||
* Catch2 also operates with test filters, or test specs. If a filter
|
||||
is present, you should also report the filter, if at all possible given
|
||||
the target output format.
|
||||
|
||||
|
||||
You can write your own custom reporter and register it with Catch.
|
||||
At time of writing the interface is subject to some changes so is not, yet, documented here.
|
||||
If you are determined you shouldn't have too much trouble working it out from the existing implementations -
|
||||
but do keep in mind upcoming changes (these will be minor, simplifying, changes such as not needing to forward calls to the base class).
|
||||
|
||||
---
|
||||
|
||||
|
@@ -1,149 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Explicitly skipping, passing, and failing tests at runtime
|
||||
|
||||
## Skipping Test Cases at Runtime
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/2360) in Catch2 3.3.0.
|
||||
|
||||
In some situations it may not be possible to meaningfully execute a test case,
|
||||
for example when the system under test is missing certain hardware capabilities.
|
||||
If the required conditions can only be determined at runtime, it often
|
||||
doesn't make sense to consider such a test case as either passed or failed,
|
||||
because it simply cannot run at all.
|
||||
|
||||
To properly express such scenarios, Catch2 provides a way to explicitly
|
||||
_skip_ test cases, using the `SKIP` macro:
|
||||
|
||||
```
|
||||
SKIP( [streamable expression] )
|
||||
```
|
||||
|
||||
Example usage:
|
||||
|
||||
```c++
|
||||
TEST_CASE("copy files between drives") {
|
||||
if(getNumberOfHardDrives() < 2) {
|
||||
SKIP("at least two hard drives required");
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
This test case is then reported as _skipped_ instead of _passed_ or _failed_.
|
||||
|
||||
The `SKIP` macro behaves similarly to an explicit [`FAIL`](#passing-and-failing-test-cases),
|
||||
in that it is the last expression that will be executed:
|
||||
|
||||
```c++
|
||||
TEST_CASE("my test") {
|
||||
printf("foo");
|
||||
SKIP();
|
||||
printf("bar"); // not printed
|
||||
}
|
||||
```
|
||||
|
||||
However a failed assertion _before_ a `SKIP` still causes the entire
|
||||
test case to fail:
|
||||
|
||||
```c++
|
||||
TEST_CASE("failing test") {
|
||||
CHECK(1 == 2);
|
||||
SKIP();
|
||||
}
|
||||
```
|
||||
|
||||
Same applies for a `SKIP` nested inside an assertion:
|
||||
|
||||
```cpp
|
||||
static bool do_skip() {
|
||||
SKIP();
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST_CASE("Another failing test") {
|
||||
CHECK(do_skip());
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Interaction with Sections and Generators
|
||||
|
||||
Sections, nested sections as well as specific outputs from [generators](generators.md#top)
|
||||
can all be individually skipped, with the rest executing as usual:
|
||||
|
||||
```c++
|
||||
TEST_CASE("complex test case") {
|
||||
int value = GENERATE(2, 4, 6);
|
||||
SECTION("a") {
|
||||
SECTION("a1") { CHECK(value < 8); }
|
||||
SECTION("a2") {
|
||||
if (value == 4) {
|
||||
SKIP();
|
||||
}
|
||||
CHECK(value % 2 == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This test case will report 5 passing assertions; one for each of the three
|
||||
values in section `a1`, and then two in section `a2`, from values 2 and 4.
|
||||
|
||||
Note that as soon as one section is skipped, the entire test case will
|
||||
be reported as _skipped_ (unless there is a failing assertion, in which
|
||||
case the test is handled as _failed_ instead).
|
||||
|
||||
Note that if all test cases in a run are skipped, Catch2 returns a non-zero
|
||||
exit code, same as it does if no test cases have run. This behaviour can
|
||||
be overridden using the [--allow-running-no-tests](command-line.md#no-tests-override)
|
||||
flag.
|
||||
|
||||
### `SKIP` inside generators
|
||||
|
||||
You can also use the `SKIP` macro inside generator's constructor to handle
|
||||
cases where the generator is empty, but you do not want to fail the test
|
||||
case.
|
||||
|
||||
|
||||
## Passing and failing test cases
|
||||
|
||||
Test cases can also be explicitly passed or failed, without the use of
|
||||
assertions, and with a specific message. This can be useful to handle
|
||||
complex preconditions/postconditions and give useful error messages
|
||||
when they fail.
|
||||
|
||||
* `SUCCEED( [streamable expression] )`
|
||||
|
||||
`SUCCEED` is morally equivalent with `INFO( [streamable expression] ); REQUIRE( true );`.
|
||||
Note that it does not stop further test execution, so it cannot be used
|
||||
to guard failing assertions from being executed.
|
||||
|
||||
_In practice, `SUCCEED` is usually used as a test placeholder, to avoid
|
||||
[failing a test case due to missing assertions](command-line.md#warnings)._
|
||||
|
||||
```cpp
|
||||
TEST_CASE( "SUCCEED showcase" ) {
|
||||
int I = 1;
|
||||
SUCCEED( "I is " << I );
|
||||
// ... execution continues here ...
|
||||
}
|
||||
```
|
||||
|
||||
* `FAIL( [streamable expression] )`
|
||||
|
||||
`FAIL` is morally equivalent with `INFO( [streamable expression] ); REQUIRE( false );`.
|
||||
|
||||
_In practice, `FAIL` is usually used to stop executing test that is currently
|
||||
known to be broken, but has to be fixed later._
|
||||
|
||||
```cpp
|
||||
TEST_CASE( "FAIL showcase" ) {
|
||||
FAIL( "This test case causes segfault, which breaks CI." );
|
||||
// ... this will not be executed ...
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
72
docs/slow-compiles.md
Normal file
@@ -0,0 +1,72 @@
|
||||
<a id="top"></a>
|
||||
# Why do my tests take so long to compile?
|
||||
|
||||
**Contents**<br>
|
||||
[Short answer](#short-answer)<br>
|
||||
[Long answer](#long-answer)<br>
|
||||
[Practical example](#practical-example)<br>
|
||||
[Other possible solutions](#other-possible-solutions)<br>
|
||||
|
||||
Several people have reported that test code written with Catch takes much longer to compile than they would expect. Why is that?
|
||||
|
||||
Catch is implemented entirely in headers. There is a little overhead due to this - but not as much as you might think - and you can minimise it simply by organising your test code as follows:
|
||||
|
||||
## Short answer
|
||||
Exactly one source file must ```#define``` either ```CATCH_CONFIG_MAIN``` or ```CATCH_CONFIG_RUNNER``` before ```#include```-ing Catch. In this file *do not write any test cases*! In most cases that means this file will just contain two lines (the ```#define``` and the ```#include```).
|
||||
|
||||
## Long answer
|
||||
|
||||
Usually C++ code is split between a header file, containing declarations and prototypes, and an implementation file (.cpp) containing the definition, or implementation, code. Each implementation file, along with all the headers that it includes (and which those headers include, etc), is expanded into a single entity called a translation unit - which is then passed to the compiler and compiled down to an object file.
|
||||
|
||||
But functions and methods can also be written inline in header files. The downside to this is that these definitions will then be compiled in *every* translation unit that includes the header.
|
||||
|
||||
Because Catch is implemented *entirely* in headers you might think that the whole of Catch must be compiled into every translation unit that uses it! Actually it's not quite as bad as that. Catch mitigates this situation by effectively maintaining the traditional separation between the implementation code and declarations. Internally the implementation code is protected by ```#ifdef```s and is conditionally compiled into only one translation unit. This translation unit is that one that ```#define```s ```CATCH_CONFIG_MAIN``` or ```CATCH_CONFIG_RUNNER```. Let's call this the main source file.
|
||||
|
||||
As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch.
|
||||
|
||||
## Practical example
|
||||
Assume you have the `Factorial` function from the [tutorial](tutorial.md#top) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`:
|
||||
|
||||
```cpp
|
||||
// tests-main.cpp
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
```
|
||||
|
||||
```cpp
|
||||
// tests-factorial.cpp
|
||||
#include "catch.hpp"
|
||||
|
||||
#include "factorial.h"
|
||||
|
||||
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
REQUIRE( Factorial(1) == 1 );
|
||||
REQUIRE( Factorial(2) == 2 );
|
||||
REQUIRE( Factorial(3) == 6 );
|
||||
REQUIRE( Factorial(10) == 3628800 );
|
||||
}
|
||||
```
|
||||
|
||||
After compiling `tests-main.cpp` once, it is enough to link it with separately compiled `tests-factorial.cpp`. This means that adding more tests to `tests-factorial.cpp`, will not result in recompiling Catch's main and the resulting compilation times will decrease substantially.
|
||||
|
||||
```
|
||||
$ g++ tests-main.cpp -c
|
||||
$ g++ factorial.cpp -c
|
||||
$ g++ tests-main.o factorial.o tests-factorial.cpp -o tests && ./tests -r compact
|
||||
Passed 1 test case with 4 assertions.
|
||||
```
|
||||
|
||||
Now, the next time we change the file `tests-factorial.cpp` (say we add `REQUIRE( Factorial(0) == 1)`), it is enough to recompile the tests instead of recompiling main as well:
|
||||
|
||||
```
|
||||
$ g++ tests-main.o factorial.o tests-factorial.cpp -o tests && ./tests -r compact
|
||||
tests-factorial.cpp:11: failed: Factorial(0) == 1 for: 0 == 1
|
||||
Failed 1 test case, failed 1 assertion.
|
||||
```
|
||||
|
||||
## Other possible solutions
|
||||
You can also opt to sacrifice some features in order to speed-up Catch's compilation times. For details see the [documentation on Catch's compile-time configuration](configuration.md#other-toggles).
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -15,18 +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_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, 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).
|
||||
|
||||
**The combination of test names and tags must be unique within the Catch2
|
||||
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. Tags are discussed below. Test names must be unique within the Catch executable.
|
||||
|
||||
For examples see the [Tutorial](tutorial.md#top)
|
||||
|
||||
@@ -45,21 +36,13 @@ The tag expression, ```"[widget]"``` selects A, B & D. ```"[gadget]"``` selects
|
||||
|
||||
For more detail on command line selection see [the command line docs](command-line.md#specifying-which-tests-to-run)
|
||||
|
||||
Tag names are not case sensitive and can contain any ASCII characters.
|
||||
This means that tags `[tag with spaces]` and `[I said "good day"]`
|
||||
are both allowed tags and can be filtered on. However, escapes are not
|
||||
supported and `[\]]` is not a valid tag.
|
||||
|
||||
The same tag can be specified multiple times for a single test case,
|
||||
but only one of the instances of identical tags will be kept. Which one
|
||||
is kept is functionally random.
|
||||
|
||||
Tag names are not case sensitive and can contain any ASCII characters. This means that tags `[tag with spaces]` and `[I said "good day"]` are both allowed tags and can be filtered on. Escapes are not supported however and `[\]]` is not a valid tag.
|
||||
|
||||
### Special Tags
|
||||
|
||||
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`.
|
||||
|
||||
@@ -69,13 +52,11 @@ All tag names beginning with non-alphanumeric characters are reserved by Catch.
|
||||
|
||||
* `[!nonportable]` - Indicates that behaviour may vary between platforms or compilers.
|
||||
|
||||
* `[#<filename>]` - these tags are added to test cases when you run Catch2
|
||||
with [`-#` or `--filenames-as-tags`](command-line.md#filenames-as-tags).
|
||||
* `[#<filename>]` - running with `-#` or `--filenames-as-tags` causes Catch to add the filename, prefixed with `#` (and with any extension stripped), as a tag to all contained tests, e.g. tests in testfile.cpp would all be tagged `[#testfile]`.
|
||||
|
||||
* `[@<alias>]` - tag aliases all begin with `@` (see below).
|
||||
|
||||
* `[!benchmark]` - this test case is actually a benchmark. Currently this only serves to hide the test case by default, to avoid the execution time costs.
|
||||
|
||||
* `[!benchmark]` - this test case is actually a benchmark. This is an experimental feature, and currently has no documentation. If you want to try it out, look at `projects/SelfTest/Benchmark.tests.cpp` for details.
|
||||
|
||||
## Tag aliases
|
||||
|
||||
@@ -101,65 +82,15 @@ This macro maps onto ```TEST_CASE``` and works in the same way, except that the
|
||||
* **WHEN(** _something_ **)**
|
||||
* **THEN(** _something_ **)**
|
||||
|
||||
These macros map onto ```SECTION```s except that the section names are the _something_ texts prefixed by
|
||||
"given: ", "when: " or "then: " respectively. These macros also map onto the AAA or A<sup>3</sup> test pattern
|
||||
(standing either for [Assemble-Activate-Assert](http://wiki.c2.com/?AssembleActivateAssert) or
|
||||
[Arrange-Act-Assert](http://wiki.c2.com/?ArrangeActAssert)), and in this context, the macros provide both code
|
||||
documentation and reporting of these parts of a test case without the need for extra comments or code to do so.
|
||||
|
||||
Semantically, a `GIVEN` clause may have multiple _independent_ `WHEN` clauses within it. This allows a test
|
||||
to have, e.g., one set of "given" objects and multiple subtests using those objects in various ways in each
|
||||
of the `WHEN` clauses without repeating the initialisation from the `GIVEN` clause. When there are _dependent_
|
||||
clauses -- such as a second `WHEN` clause that should only happen _after_ the previous `WHEN` clause has been
|
||||
executed and validated -- there are additional macros starting with `AND_`:
|
||||
These macros map onto ```SECTION```s except that the section names are the _something_s prefixed by "given: ", "when: " or "then: " respectively.
|
||||
|
||||
* **AND_GIVEN(** _something_ **)**
|
||||
* **AND_WHEN(** _something_ **)**
|
||||
* **AND_THEN(** _something_ **)**
|
||||
|
||||
These are used to chain ```GIVEN```s, ```WHEN```s and ```THEN```s together. The `AND_*` clause is placed
|
||||
_inside_ the clause on which it depends. There can be multiple _independent_ clauses that are all _dependent_
|
||||
on a single outer clause.
|
||||
```cpp
|
||||
SCENARIO( "vector can be sized and resized" ) {
|
||||
GIVEN( "An empty vector" ) {
|
||||
auto v = std::vector<std::string>{};
|
||||
Similar to ```GIVEN```, ```WHEN``` and ```THEN``` except that the prefixes start with "and ". These are used to chain ```GIVEN```s, ```WHEN```s and ```THEN```s together.
|
||||
|
||||
// Validate assumption of the GIVEN clause
|
||||
THEN( "The size and capacity start at 0" ) {
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() == 0 );
|
||||
}
|
||||
|
||||
// Validate one use case for the GIVEN object
|
||||
WHEN( "push_back() is called" ) {
|
||||
v.push_back("hullo");
|
||||
|
||||
THEN( "The size changes" ) {
|
||||
REQUIRE( v.size() == 1 );
|
||||
REQUIRE( v.capacity() >= 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This code will result in two runs through the scenario:
|
||||
```
|
||||
Scenario : vector can be sized and resized
|
||||
Given : An empty vector
|
||||
Then : The size and capacity start at 0
|
||||
|
||||
Scenario : vector can be sized and resized
|
||||
Given : An empty vector
|
||||
When : push_back() is called
|
||||
Then : The size changes
|
||||
```
|
||||
|
||||
See also [runnable example on godbolt](https://godbolt.org/z/eY5a64r99),
|
||||
with a more complicated (and failing) example.
|
||||
|
||||
> `AND_GIVEN` was [introduced](https://github.com/catchorg/Catch2/issues/1360) in Catch2 2.4.0.
|
||||
> `AND_GIVEN` was [introduced](https://github.com/catchorg/Catch2/issues/1360) in Catch 2.4.0.
|
||||
|
||||
When any of these macros are used the console reporter recognises them and formats the test case header such that the Givens, Whens and Thens are aligned to aid readability.
|
||||
|
||||
@@ -169,15 +100,11 @@ Other than the additional prefixes and the formatting in the console reporter th
|
||||
|
||||
In addition to `TEST_CASE`s, Catch2 also supports test cases parametrised
|
||||
by types, in the form of `TEMPLATE_TEST_CASE`,
|
||||
`TEMPLATE_PRODUCT_TEST_CASE` and `TEMPLATE_LIST_TEST_CASE`. These macros
|
||||
are defined in the `catch_template_test_macros.hpp` header, so compiling
|
||||
the code examples below also requires
|
||||
`#include <catch2/catch_template_test_macros.hpp>`.
|
||||
|
||||
`TEMPLATE_PRODUCT_TEST_CASE` and `TEMPLATE_LIST_TEST_CASE`.
|
||||
|
||||
* **TEMPLATE_TEST_CASE(** _test name_ , _tags_, _type1_, _type2_, ..., _typen_ **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1437) in Catch2 2.5.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1437) in Catch 2.5.0.
|
||||
|
||||
_test name_ and _tag_ are exactly the same as they are in `TEST_CASE`,
|
||||
with the difference that the tag string must be provided (however, it
|
||||
@@ -229,9 +156,9 @@ TEMPLATE_TEST_CASE( "vectors can be sized and resized", "[vector][template]", in
|
||||
|
||||
* **TEMPLATE_PRODUCT_TEST_CASE(** _test name_ , _tags_, (_template-type1_, _template-type2_, ..., _template-typen_), (_template-arg1_, _template-arg2_, ..., _template-argm_) **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1468) in Catch2 2.6.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1468) in Catch 2.6.0.
|
||||
|
||||
_template-type1_ through _template-typen_ is list of template
|
||||
_template-type1_ through _template-typen_ is list of template template
|
||||
types which should be combined with each of _template-arg1_ through
|
||||
_template-argm_, resulting in _n * m_ test cases. Inside the test case,
|
||||
the resulting type is available under the name of `TestType`.
|
||||
@@ -268,9 +195,13 @@ TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities", "[template][product
|
||||
}
|
||||
```
|
||||
|
||||
_While there is an upper limit on the number of types you can specify
|
||||
in single `TEMPLATE_TEST_CASE` or `TEMPLATE_PRODUCT_TEST_CASE`, the limit
|
||||
is very high and should not be encountered in practice._
|
||||
|
||||
* **TEMPLATE_LIST_TEST_CASE(** _test name_, _tags_, _type list_ **)**
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1627) in Catch2 2.9.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1627) in Catch 2.9.0.
|
||||
|
||||
_type list_ is a generic list of types on which test case should be instantiated.
|
||||
List can be `std::tuple`, `boost::mpl::list`, `boost::mp11::mp_list` or anything with
|
||||
@@ -290,14 +221,12 @@ TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std
|
||||
|
||||
## Signature based parametrised test cases
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch2 2.8.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch 2.8.0.
|
||||
|
||||
In addition to [type parametrised test cases](#type-parametrised-test-cases) Catch2 also supports
|
||||
signature base parametrised test cases, in form of `TEMPLATE_TEST_CASE_SIG` and `TEMPLATE_PRODUCT_TEST_CASE_SIG`.
|
||||
These test cases have similar syntax like [type parametrised test cases](#type-parametrised-test-cases), with one
|
||||
additional positional argument which specifies the signature. These macros are defined in the
|
||||
`catch_template_test_macros.hpp` header, so compiling the code examples below also requires
|
||||
`#include <catch2/catch_template_test_macros.hpp>`.
|
||||
additional positional argument which specifies the signature.
|
||||
|
||||
### Signature
|
||||
Signature has some strict rules for these tests cases to work properly:
|
||||
@@ -314,7 +243,7 @@ Currently Catch2 support up to 11 template parameters in signature
|
||||
|
||||
* **TEMPLATE_TEST_CASE_SIG(** _test name_ , _tags_, _signature_, _type1_, _type2_, ..., _typen_ **)**
|
||||
|
||||
Inside `TEMPLATE_TEST_CASE_SIG` test case you can use the names of template parameters as defined in _signature_.
|
||||
Inside `TEMPLATE_TEST_CASE_SIG` test case you can use the names of template parameters as defined in _signature_.
|
||||
|
||||
```cpp
|
||||
TEMPLATE_TEST_CASE_SIG("TemplateTestSig: arrays can be created from NTTP arguments", "[vector][template][nttp]",
|
||||
|
@@ -1,30 +1,9 @@
|
||||
<a id="top"></a>
|
||||
# Test fixtures
|
||||
|
||||
**Contents**<br>
|
||||
[Non-Templated test fixtures](#non-templated-test-fixtures)<br>
|
||||
[Templated test fixtures](#templated-test-fixtures)<br>
|
||||
[Signature-based parameterised test fixtures](#signature-based-parameterised-test-fixtures)<br>
|
||||
[Template fixtures with types specified in template type lists](#template-fixtures-with-types-specified-in-template-type-lists)<br>
|
||||
## Defining test fixtures
|
||||
|
||||
## Non-Templated test fixtures
|
||||
|
||||
Although Catch2 allows you to group tests together as
|
||||
[sections within a test case](test-cases-and-sections.md), it can still
|
||||
be convenient, sometimes, to group them using a more traditional test.
|
||||
Catch2 fully supports this too with 3 different macros for
|
||||
non-templated test fixtures. They are:
|
||||
|
||||
| Macro | Description |
|
||||
|----------|-------------|
|
||||
|1. `TEST_CASE_METHOD(className, ...)`| Creates a uniquely named class which inherits from the class specified by `className`. The test function will be a member of this derived class. An instance of the derived class will be created for every partial run of the test case. |
|
||||
|2. `METHOD_AS_TEST_CASE(member-function, ...)`| Uses `member-function` as the test function. An instance of the class will be created for each partial run of the test case. |
|
||||
|3. `TEST_CASE_PERSISTENT_FIXTURE(className, ...)`| Creates a uniquely named class which inherits from the class specified by `className`. The test function will be a member of this derived class. An instance of the derived class will be created at the start of the test run. That instance will be destroyed once the entire test case has ended. |
|
||||
|
||||
### 1. `TEST_CASE_METHOD`
|
||||
|
||||
|
||||
You define a `TEST_CASE_METHOD` test fixture as a simple structure:
|
||||
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
|
||||
|
||||
```c++
|
||||
class UniqueTestsFixture {
|
||||
@@ -51,116 +30,8 @@ class UniqueTestsFixture {
|
||||
}
|
||||
```
|
||||
|
||||
The two test cases here will create uniquely-named derived classes of
|
||||
UniqueTestsFixture and thus can access the `getID()` protected method
|
||||
and `conn` member variables. This ensures that both the test cases
|
||||
are able to create a DBConnection using the same method
|
||||
(DRY principle) and that any ID's created are unique such that the
|
||||
order that tests are executed does not matter.
|
||||
The two test cases here will create uniquely-named derived classes of UniqueTestsFixture and thus can access the `getID()` protected method and `conn` member variables. This ensures that both the test cases are able to create a DBConnection using the same method (DRY principle) and that any ID's created are unique such that the order that tests are executed does not matter.
|
||||
|
||||
### 2. `METHOD_AS_TEST_CASE`
|
||||
|
||||
`METHOD_AS_TEST_CASE` lets you register a member function of a class
|
||||
as a Catch2 test case. The class will be separately instantiated
|
||||
for each method registered in this way.
|
||||
|
||||
```cpp
|
||||
class TestClass {
|
||||
std::string s;
|
||||
|
||||
public:
|
||||
TestClass()
|
||||
:s( "hello" )
|
||||
{}
|
||||
|
||||
void testCase() {
|
||||
REQUIRE( s == "hello" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
METHOD_AS_TEST_CASE( TestClass::testCase, "Use class's method as a test case", "[class]" )
|
||||
```
|
||||
|
||||
This type of fixture is similar to [TEST_CASE_METHOD](#1-test_case_method) except in this
|
||||
case it will directly use the provided class to create an object rather than a derived
|
||||
class.
|
||||
|
||||
### 3. `TEST_CASE_PERSISTENT_FIXTURE`
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/pull/2885) in Catch2 3.7.0
|
||||
|
||||
`TEST_CASE_PERSISTENT_FIXTURE` behaves in the same way as
|
||||
[TEST_CASE_METHOD](#1-test_case_method) except that there will only be
|
||||
one instance created throughout the entire run of a test case. To
|
||||
demonstrate this have a look at the following example:
|
||||
|
||||
```cpp
|
||||
class ClassWithExpensiveSetup {
|
||||
public:
|
||||
ClassWithExpensiveSetup() {
|
||||
// expensive construction
|
||||
std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
|
||||
}
|
||||
|
||||
~ClassWithExpensiveSetup() noexcept {
|
||||
// expensive destruction
|
||||
std::this_thread::sleep_for( std::chrono::seconds( 1 ) );
|
||||
}
|
||||
|
||||
int getInt() const { return 42; }
|
||||
};
|
||||
|
||||
struct MyFixture {
|
||||
mutable int myInt = 0;
|
||||
ClassWithExpensiveSetup expensive;
|
||||
};
|
||||
|
||||
TEST_CASE_PERSISTENT_FIXTURE( MyFixture, "Tests with MyFixture" ) {
|
||||
|
||||
const int val = myInt++;
|
||||
|
||||
SECTION( "First partial run" ) {
|
||||
const auto otherValue = expensive.getInt();
|
||||
REQUIRE( val == 0 );
|
||||
REQUIRE( otherValue == 42 );
|
||||
}
|
||||
|
||||
SECTION( "Second partial run" ) { REQUIRE( val == 1 ); }
|
||||
}
|
||||
```
|
||||
|
||||
This example demonstrates two possible use-cases of this fixture type:
|
||||
1. Improve test run times by reducing the amount of expensive and
|
||||
redundant setup and tear-down required.
|
||||
2. Reusing results from the previous partial run, in the current
|
||||
partial run.
|
||||
|
||||
This test case will be executed twice as there are two leaf sections.
|
||||
On the first run `val` will be `0` and on the second run `val` will be
|
||||
`1`. This demonstrates that we were able to use the results of the
|
||||
previous partial run in subsequent partial runs.
|
||||
|
||||
Additionally, we are simulating an expensive object using
|
||||
`std::this_thread::sleep_for`, but real world use-cases could be:
|
||||
1. Creating a D3D12/Vulkan device
|
||||
2. Connecting to a database
|
||||
3. Loading a file.
|
||||
|
||||
The fixture object (`MyFixture`) will be constructed just before the
|
||||
test case begins, and it will be destroyed just after the test case
|
||||
ends. Therefore, this expensive object will only be created and
|
||||
destroyed once during the execution of this test case. If we had used
|
||||
`TEST_CASE_METHOD`, `MyFixture` would have been created and destroyed
|
||||
twice during the execution of this test case.
|
||||
|
||||
NOTE: The member function which runs the test case is `const`. Therefore
|
||||
if you want to mutate any member of the fixture it must be marked as
|
||||
`mutable` as shown in this example. This is to make it clear that
|
||||
the initial state of the fixture is intended to mutate during the
|
||||
execution of the test case.
|
||||
|
||||
## Templated test fixtures
|
||||
|
||||
Catch2 also provides `TEMPLATE_TEST_CASE_METHOD` and
|
||||
`TEMPLATE_PRODUCT_TEST_CASE_METHOD` that can be used together
|
||||
@@ -188,10 +59,7 @@ struct Template_Fixture {
|
||||
T m_a;
|
||||
};
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD(Template_Fixture,
|
||||
"A TEMPLATE_TEST_CASE_METHOD based test run that succeeds",
|
||||
"[class][template]",
|
||||
int, float, double) {
|
||||
TEMPLATE_TEST_CASE_METHOD(Template_Fixture,"A TEMPLATE_TEST_CASE_METHOD based test run that succeeds", "[class][template]", int, float, double) {
|
||||
REQUIRE( Template_Fixture<TestType>::m_a == 1 );
|
||||
}
|
||||
|
||||
@@ -209,11 +77,7 @@ struct Foo_class {
|
||||
}
|
||||
};
|
||||
|
||||
TEMPLATE_PRODUCT_TEST_CASE_METHOD(Template_Template_Fixture,
|
||||
"A TEMPLATE_PRODUCT_TEST_CASE_METHOD based test succeeds",
|
||||
"[class][template]",
|
||||
(Foo_class, std::vector),
|
||||
int) {
|
||||
TEMPLATE_PRODUCT_TEST_CASE_METHOD(Template_Template_Fixture, "A TEMPLATE_PRODUCT_TEST_CASE_METHOD based test succeeds", "[class][template]", (Foo_class, std::vector), int) {
|
||||
REQUIRE( Template_Template_Fixture<TestType>::m_a.size() == 0 );
|
||||
}
|
||||
```
|
||||
@@ -222,9 +86,9 @@ _While there is an upper limit on the number of types you can specify
|
||||
in single `TEMPLATE_TEST_CASE_METHOD` or `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
|
||||
the limit is very high and should not be encountered in practice._
|
||||
|
||||
## Signature-based parameterised test fixtures
|
||||
## Signature-based parametrised test fixtures
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch2 2.8.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1609) in Catch 2.8.0.
|
||||
|
||||
Catch2 also provides `TEMPLATE_TEST_CASE_METHOD_SIG` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG` to support
|
||||
fixtures using non-type template parameters. These test cases work similar to `TEMPLATE_TEST_CASE_METHOD` and `TEMPLATE_PRODUCT_TEST_CASE_METHOD`,
|
||||
@@ -237,12 +101,7 @@ struct Nttp_Fixture{
|
||||
int value = V;
|
||||
};
|
||||
|
||||
TEMPLATE_TEST_CASE_METHOD_SIG(
|
||||
Nttp_Fixture,
|
||||
"A TEMPLATE_TEST_CASE_METHOD_SIG based test run that succeeds",
|
||||
"[class][template][nttp]",
|
||||
((int V), V),
|
||||
1, 3, 6) {
|
||||
TEMPLATE_TEST_CASE_METHOD_SIG(Nttp_Fixture, "A TEMPLATE_TEST_CASE_METHOD_SIG based test run that succeeds", "[class][template][nttp]",((int V), V), 1, 3, 6) {
|
||||
REQUIRE(Nttp_Fixture<V>::value > 0);
|
||||
}
|
||||
|
||||
@@ -258,13 +117,8 @@ struct Template_Foo_2 {
|
||||
size_t size() { return V; }
|
||||
};
|
||||
|
||||
TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG(
|
||||
Template_Fixture_2,
|
||||
"A TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG based test run that succeeds",
|
||||
"[class][template][product][nttp]",
|
||||
((typename T, size_t S), T, S),
|
||||
(std::array, Template_Foo_2),
|
||||
((int,2), (float,6))) {
|
||||
TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG(Template_Fixture_2, "A TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG based test run that succeeds", "[class][template][product][nttp]", ((typename T, size_t S), T, S),(std::array, Template_Foo_2), ((int,2), (float,6)))
|
||||
{
|
||||
REQUIRE(Template_Fixture_2<TestType>{}.m_a.size() >= 2);
|
||||
}
|
||||
```
|
||||
@@ -278,10 +132,8 @@ only difference is the source of types. This allows you to reuse the template ty
|
||||
Example:
|
||||
```cpp
|
||||
using MyTypes = std::tuple<int, char, double>;
|
||||
TEMPLATE_LIST_TEST_CASE_METHOD(Template_Fixture,
|
||||
"Template test case method with test types specified inside std::tuple",
|
||||
"[class][template][list]",
|
||||
MyTypes) {
|
||||
TEMPLATE_LIST_TEST_CASE_METHOD(Template_Fixture, "Template test case method with test types specified inside std::tuple", "[class][template][list]", MyTypes)
|
||||
{
|
||||
REQUIRE( Template_Fixture<TestType>::m_a == 1 );
|
||||
}
|
||||
```
|
||||
|
@@ -1,130 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Thread safety in Catch2
|
||||
|
||||
**Contents**<br>
|
||||
[Using assertion macros from multiple threads](#using-assertion-macros-from-multiple-threads)<br>
|
||||
[examples](#examples)<br>
|
||||
[`STATIC_REQUIRE` and `STATIC_CHECK`](#static_require-and-static_check)<br>
|
||||
[Fatal errors and multiple threads](#fatal-errors-and-multiple-threads)<br>
|
||||
[Performance overhead](#performance-overhead)<br>
|
||||
|
||||
> Thread safe assertions were introduced in Catch2 3.9.0
|
||||
|
||||
Thread safety in Catch2 is currently limited to all the assertion macros.
|
||||
Interacting with benchmark macros, message macros (e.g. `INFO` or `CAPTURE`),
|
||||
sections macros, generator macros, or test case macros is not thread-safe.
|
||||
The message macros are likely to be made thread-safe in the future, but
|
||||
the way sections define test runs is incompatible with user being able
|
||||
to spawn threads arbitrarily, thus that limitation is here to stay.
|
||||
|
||||
**Important: thread safety in Catch2 is [opt-in](configuration.md#experimental-thread-safety)**
|
||||
|
||||
|
||||
## Using assertion macros from multiple threads
|
||||
|
||||
The full set of Catch2's runtime assertion macros is thread-safe. However,
|
||||
it is important to keep in mind that their semantics might not support
|
||||
being used from user-spawned threads.
|
||||
|
||||
Specifically, the `REQUIRE` family of assertion macros have semantics
|
||||
of stopping the test execution on failure. This is done by throwing
|
||||
an exception, but since the user-spawned thread will not have the test-level
|
||||
try-catch block ready to catch the test failure exception, failing a
|
||||
`REQUIRE` assertion inside this thread will terminate the process.
|
||||
|
||||
The `CHECK` family of assertions does not have this issue, because it
|
||||
does not try to stop the test execution.
|
||||
|
||||
Note that `CHECKED_IF` and `CHECKED_ELSE` are also thread safe (internally
|
||||
they are assertion macro + an if).
|
||||
|
||||
**`SKIP()`, `FAIL()`, `SUCCEED()` are not assertion macros, and are not
|
||||
thread-safe.**
|
||||
|
||||
|
||||
## examples
|
||||
|
||||
### `REQUIRE` from main thread, `CHECK` from spawned threads
|
||||
|
||||
```cpp
|
||||
TEST_CASE( "Failed REQUIRE in main thread is fine" ) {
|
||||
std::vector<std::jthread> threads;
|
||||
for ( size_t t = 0; t < 16; ++t) {
|
||||
threads.emplace_back( []() {
|
||||
for (size_t i = 0; i < 10'000; ++i) {
|
||||
CHECK( true );
|
||||
CHECK( false );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
REQUIRE( false );
|
||||
}
|
||||
```
|
||||
This will work as expected, that is, the process will finish running
|
||||
normally, the test case will fail and there will be the correct count of
|
||||
passing and failing assertions (160000 and 160001 respectively). However,
|
||||
it is important to understand that when the main thread fails its assertion,
|
||||
the spawned threads will keep running.
|
||||
|
||||
|
||||
### `REQUIRE` from spawned threads
|
||||
|
||||
```cpp
|
||||
TEST_CASE( "Successful REQUIRE in spawned thread is fine" ) {
|
||||
std::vector<std::jthread> threads;
|
||||
for ( size_t t = 0; t < 16; ++t) {
|
||||
threads.emplace_back( []() {
|
||||
for (size_t i = 0; i < 10'000; ++i) {
|
||||
REQUIRE( true );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
```
|
||||
This will also work as expected, because the `REQUIRE` is successful.
|
||||
|
||||
```cpp
|
||||
TEST_CASE( "Failed REQUIRE in spawned thread is fine" ) {
|
||||
std::vector<std::jthread> threads;
|
||||
for ( size_t t = 0; t < 16; ++t) {
|
||||
threads.emplace_back( []() {
|
||||
for (size_t i = 0; i < 10'000; ++i) {
|
||||
REQUIRE( false );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
```
|
||||
This will fail catastrophically and terminate the process.
|
||||
|
||||
|
||||
## `STATIC_REQUIRE` and `STATIC_CHECK`
|
||||
|
||||
None of `STATIC_REQUIRE`, `STATIC_REQUIRE_FALSE`, `STATIC_CHECK`, and
|
||||
`STATIC_CHECK_FALSE` are currently thread safe. This might be surprising
|
||||
given that they are a compile-time checks, but they also rely on the
|
||||
message macros to register the result with reporter at runtime.
|
||||
|
||||
|
||||
## Fatal errors and multiple threads
|
||||
|
||||
By default, Catch2 tries to catch fatal errors (POSIX signals/Windows
|
||||
Structured Exceptions) and report something useful to the user. This
|
||||
always happened on a best-effort basis, but in presence of multiple
|
||||
threads and locks the chance of it working decreases. If this starts
|
||||
being an issue for you, [you can disable it](configuration.md#other-toggles).
|
||||
|
||||
|
||||
## Performance overhead
|
||||
|
||||
In the worst case, which is optimized build and assertions using the
|
||||
fast path for successful assertions, the performance overhead of using
|
||||
the thread-safe assertion implementation can reach 40%. In other cases,
|
||||
the overhead will be smaller, between 4% and 20%.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -64,18 +64,18 @@ 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:
|
||||
|
||||
```cpp
|
||||
CATCH_TRANSLATE_EXCEPTION( MyType const& ex ) {
|
||||
CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
|
||||
return ex.message();
|
||||
}
|
||||
```
|
||||
|
||||
## Enums
|
||||
|
||||
> Introduced in Catch2 2.8.0.
|
||||
> Introduced in Catch 2.8.0.
|
||||
|
||||
Enums that already have a `<<` overload for `std::ostream` will convert to strings as expected.
|
||||
If you only need to convert enums to strings for test reporting purposes you can provide a `StringMaker` specialisations as any other type.
|
||||
However, as a convenience, Catch provides the `CATCH_REGISTER_ENUM` helper macro that will generate the `StringMaker` specialisation for you with minimal code.
|
||||
However, as a convenience, Catch provides the `REGISTER_ENUM` helper macro that will generate the `StringMaker` specialiation for you with minimal code.
|
||||
Simply provide it the (qualified) enum name, followed by all the enum values, and you're done!
|
||||
|
||||
E.g.
|
||||
@@ -110,7 +110,7 @@ TEST_CASE() {
|
||||
|
||||
## Floating point precision
|
||||
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1614) in Catch2 2.8.0.
|
||||
> [Introduced](https://github.com/catchorg/Catch2/issues/1614) in Catch 2.8.0.
|
||||
|
||||
Catch provides a built-in `StringMaker` specialization for both `float`
|
||||
and `double`. By default, it uses what we think is a reasonable precision,
|
||||
|
237
docs/tutorial.md
@@ -3,21 +3,32 @@
|
||||
|
||||
**Contents**<br>
|
||||
[Getting Catch2](#getting-catch2)<br>
|
||||
[Where to put it?](#where-to-put-it)<br>
|
||||
[Writing tests](#writing-tests)<br>
|
||||
[Test cases and sections](#test-cases-and-sections)<br>
|
||||
[BDD style testing](#bdd-style-testing)<br>
|
||||
[Data and Type driven tests](#data-and-type-driven-tests)<br>
|
||||
[BDD-Style](#bdd-style)<br>
|
||||
[Scaling up](#scaling-up)<br>
|
||||
[Type parametrised test cases](#type-parametrised-test-cases)<br>
|
||||
[Next steps](#next-steps)<br>
|
||||
|
||||
|
||||
## Getting Catch2
|
||||
|
||||
Ideally you should be using Catch2 through its [CMake integration](cmake-integration.md#top).
|
||||
Catch2 also provides pkg-config files and two file (header + cpp)
|
||||
distribution, but this documentation will assume you are using CMake. If
|
||||
you are using the two file distribution instead, remember to replace
|
||||
the included header with `catch_amalgamated.hpp` ([step by step instructions](migrate-v2-to-v3.md#how-to-migrate-projects-from-v2-to-v3)).
|
||||
The simplest way to get Catch2 is to download the latest [single header version](https://raw.githubusercontent.com/catchorg/Catch2/master/single_include/catch2/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file.
|
||||
|
||||
Alternative ways of getting Catch2 include using your system package
|
||||
manager, or installing it using [its CMake package](cmake-integration.md#installing-catch2-from-git-repository).
|
||||
|
||||
The full source for Catch2, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there.
|
||||
|
||||
|
||||
## Where to put it?
|
||||
|
||||
Catch2 is header only. All you need to do is drop the file somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself! This is a particularly good option for other Open-Source projects that want to use Catch for their test suite. See [this blog entry for more on that](https://levelofindirection.com/blog/unit-testing-in-cpp-and-objective-c-just-got-ridiculously-easier-still.html).
|
||||
|
||||
The rest of this tutorial will assume that the Catch2 single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
|
||||
|
||||
_If you have installed Catch2 from system package manager, or CMake
|
||||
package, you need to include the header as `#include <catch2/catch.hpp>`_
|
||||
|
||||
## Writing tests
|
||||
|
||||
@@ -29,8 +40,11 @@ unsigned int Factorial( unsigned int number ) {
|
||||
}
|
||||
```
|
||||
|
||||
To keep things simple we'll put everything in a single file (<a href="#scaling-up">see later for more on how to structure your test files</a>).
|
||||
|
||||
```c++
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
|
||||
#include "catch.hpp"
|
||||
|
||||
unsigned int Factorial( unsigned int number ) {
|
||||
return number <= 1 ? number : Factorial(number-1)*number;
|
||||
@@ -46,10 +60,13 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
|
||||
This will compile to a complete executable which responds to [command line arguments](command-line.md#top). If you just run it with no arguments it will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: "did it work").
|
||||
|
||||
Anyway, as the tests above as written will pass, but there is a bug.
|
||||
The problem is that `Factorial(0)` should return 1 (due to [its
|
||||
definition](https://en.wikipedia.org/wiki/Factorial#Factorial_of_zero)).
|
||||
Let's add that as an assertion to the test case:
|
||||
If you run this as written it will pass. Everything is good. Right?
|
||||
Well, there is still a bug here. In fact the first version of this tutorial I posted here genuinely had the bug in! So it's not completely contrived (thanks to Daryle Walker (```@CTMacUser```) for pointing this out).
|
||||
|
||||
What is the bug? Well what is the factorial of zero?
|
||||
[The factorial of zero is one](http://mathforum.org/library/drmath/view/57128.html) - which is just one of those things you have to know (and remember!).
|
||||
|
||||
Let's add that to the test case:
|
||||
|
||||
```c++
|
||||
TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
@@ -61,8 +78,7 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
||||
}
|
||||
```
|
||||
|
||||
After another compile & run cycle, we will see a test failure. The output
|
||||
will look something like:
|
||||
Now we get a failure - something like:
|
||||
|
||||
```
|
||||
Example.cpp:9: FAILED:
|
||||
@@ -71,55 +87,41 @@ with expansion:
|
||||
0 == 1
|
||||
```
|
||||
|
||||
Note that the output contains both the original expression,
|
||||
`REQUIRE( Factorial(0) == 1 )` and the actual value returned by the call
|
||||
to the `Factorial` function: `0`.
|
||||
Note that we get the actual return value of Factorial(0) printed for us (0) - even though we used a natural expression with the == operator. That lets us immediately see what the problem is.
|
||||
|
||||
Let's change the factorial function to:
|
||||
|
||||
We can fix this bug by slightly modifying the `Factorial` function to:
|
||||
```c++
|
||||
unsigned int Factorial( unsigned int number ) {
|
||||
return number > 1 ? Factorial(number-1)*number : 1;
|
||||
}
|
||||
```
|
||||
|
||||
Now all the tests pass.
|
||||
|
||||
Of course there are still more issues to deal with. For example we'll hit problems when the return value starts to exceed the range of an unsigned int. With factorials that can happen quite quickly. You might want to add tests for such cases and decide how to handle them. We'll stop short of doing that here.
|
||||
|
||||
### What did we do here?
|
||||
|
||||
Although this was a simple test it's been enough to demonstrate a few
|
||||
things about how Catch2 is used. Let's take a moment to consider those
|
||||
before we move on.
|
||||
|
||||
* We introduce test cases with the `TEST_CASE` macro. This macro takes
|
||||
one or two string arguments - a free form test name and, optionally,
|
||||
one or more tags (for more see [Test cases and Sections](#test-cases-and-sections)).
|
||||
* The test automatically self-registers with the test runner, and user
|
||||
does not have do anything more to ensure that it is picked up by the test
|
||||
framework. _Note that you can run specific test, or set of tests,
|
||||
through the [command line](command-line.md#top)._
|
||||
* The individual test assertions are written using the `REQUIRE` macro.
|
||||
It accepts a boolean expression, and uses expression templates to
|
||||
internally decompose it, so that it can be individually stringified
|
||||
on test failure.
|
||||
|
||||
On the last point, note that there are more testing macros available,
|
||||
because not all useful checks can be expressed as a simple boolean
|
||||
expression. As an example, checking that an expression throws an exception
|
||||
is done with the `REQUIRE_THROWS` macro. More on that later.
|
||||
Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take a moment to consider those before we move on.
|
||||
|
||||
1. All we did was ```#define``` one identifier and ```#include``` one header and we got everything - even an implementation of ```main()``` that will [respond to command line arguments](command-line.md#top). You can only use that ```#define``` in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll just ```#include "catch.hpp"``` and go. Usually it's a good idea to have a dedicated implementation file that just has ```#define CATCH_CONFIG_MAIN``` and ```#include "catch.hpp"```. You can also provide your own implementation of main and drive Catch yourself (see [Supplying-your-own-main()](own-main.md#top)).
|
||||
2. We introduce test cases with the ```TEST_CASE``` macro. This macro takes one or two arguments - a free form test name and, optionally, one or more tags (for more see <a href="#test-cases-and-sections">Test cases and Sections</a>). The test name must be unique. You can run sets of tests by specifying a wildcarded test name or a tag expression. See the [command line docs](command-line.md#top) for more information on running tests.
|
||||
3. The name and tags arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
|
||||
4. We write our individual test assertions using the ```REQUIRE``` macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
|
||||
|
||||
<a id="test-cases-and-sections"></a>
|
||||
## Test cases and sections
|
||||
|
||||
Like most test frameworks, Catch2 supports a class-based fixture mechanism,
|
||||
where individual tests are methods on class and setup/teardown can be
|
||||
done in constructor/destructor of the type.
|
||||
Most test frameworks have a class-based fixture mechanism. That is, test cases map to methods on a class and common setup and teardown can be performed in ```setup()``` and ```teardown()``` methods (or constructor/ destructor in languages, like C++, that support deterministic destruction).
|
||||
|
||||
However, their use in Catch2 is rare, because idiomatic Catch2 tests
|
||||
instead use _sections_ to share setup and teardown code between test code.
|
||||
This is best explained through an example ([code](../examples/100-Fix-Section.cpp)):
|
||||
While Catch fully supports this way of working there are a few problems with the approach. In particular the way your code must be split up, and the blunt granularity of it, may cause problems. You can only have one setup/ teardown pair across a set of methods, but sometimes you want slightly different setup in each method, or you may even want several levels of setup (a concept which we will clarify later on in this tutorial). It was <a href="http://jamesnewkirk.typepad.com/posts/2007/09/why-you-should-.html">problems like these</a> that led James Newkirk, who led the team that built NUnit, to start again from scratch and <a href="http://jamesnewkirk.typepad.com/posts/2007/09/announcing-xuni.html">build xUnit</a>).
|
||||
|
||||
Catch takes a different approach (to both NUnit and xUnit) that is a more natural fit for C++ and the C family of languages. This is best explained through an example ([code](../examples/100-Fix-Section.cpp)):
|
||||
|
||||
```c++
|
||||
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
// This setup will be done 4 times in total, once for each section
|
||||
|
||||
std::vector<int> v( 5 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
@@ -152,76 +154,125 @@ TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
}
|
||||
```
|
||||
|
||||
For each `SECTION` the `TEST_CASE` is **executed from the start**. This means
|
||||
that each section is entered with a freshly constructed vector `v`, that
|
||||
we know has size 5 and capacity at least 5, because the two assertions
|
||||
are also checked before the section is entered. This behaviour may not be
|
||||
ideal for tests where setup is expensive. Each run through a test case will
|
||||
execute one, and only one, leaf section.
|
||||
For each ```SECTION``` the ```TEST_CASE``` is executed from the start - so as we enter each section we know that size is 5 and capacity is at least 5. We enforced those requirements with the ```REQUIRE```s at the top level so we can be confident in them.
|
||||
This works because the ```SECTION``` macro contains an if statement that calls back into Catch to see if the section should be executed. One leaf section is executed on each run through a ```TEST_CASE```. The other sections are skipped. Next time through the next section is executed, and so on until no new sections are encountered.
|
||||
|
||||
Section can also be nested, in which case the parent section can be
|
||||
entered multiple times, once for each leaf section. Nested sections are
|
||||
most useful when you have multiple tests that share part of the set up.
|
||||
To continue on the vector example above, you could add a check that
|
||||
`std::vector::reserve` does not remove unused excess capacity, like this:
|
||||
So far so good - this is already an improvement on the setup/teardown approach because now we see our setup code inline and use the stack.
|
||||
|
||||
```cpp
|
||||
The power of sections really shows, however, when we need to execute a sequence of checked operations. Continuing the vector example, we might want to verify that attempting to reserve a capacity smaller than the current capacity of the vector changes nothing. We can do that, naturally, like so:
|
||||
|
||||
```c++
|
||||
SECTION( "reserving bigger changes capacity but not size" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
SECTION( "reserving down unused capacity does not change capacity" ) {
|
||||
|
||||
SECTION( "reserving smaller again does not change capacity" ) {
|
||||
v.reserve( 7 );
|
||||
REQUIRE( v.size() == 5 );
|
||||
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Another way to look at sections is that they are a way to define a tree
|
||||
of paths through the test. Each section represents a node, and the final
|
||||
tree is walked in depth-first manner, with each path only visiting only
|
||||
one leaf node.
|
||||
Sections can be nested to an arbitrary depth (limited only by your stack size). Each leaf section (i.e. a section that contains no nested sections) will be executed exactly once, on a separate path of execution from any other leaf section (so no leaf section can interfere with another). A failure in a parent section will prevent nested sections from running - but then that's the idea.
|
||||
|
||||
There is no practical limit on nesting sections, as long as your compiler
|
||||
can handle them, but keep in mind that overly nested sections can become
|
||||
unreadable. From experience, having section nest more than 3 levels is
|
||||
usually very hard to follow and not worth the removed duplication.
|
||||
## BDD-Style
|
||||
|
||||
If you name your test cases and sections appropriately you can achieve a BDD-style specification structure. This became such a useful way of working that first class support has been added to Catch. Scenarios can be specified using ```SCENARIO```, ```GIVEN```, ```WHEN``` and ```THEN``` macros, which map on to ```TEST_CASE```s and ```SECTION```s, respectively. For more details see [Test cases and sections](test-cases-and-sections.md#top).
|
||||
|
||||
The vector example can be adjusted to use these macros like so ([example code](../examples/120-Bdd-ScenarioGivenWhenThen.cpp)):
|
||||
|
||||
```c++
|
||||
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
||||
|
||||
GIVEN( "A vector with some items" ) {
|
||||
std::vector<int> v( 5 );
|
||||
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
|
||||
WHEN( "the size is increased" ) {
|
||||
v.resize( 10 );
|
||||
|
||||
THEN( "the size and capacity change" ) {
|
||||
REQUIRE( v.size() == 10 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "the size is reduced" ) {
|
||||
v.resize( 0 );
|
||||
|
||||
THEN( "the size changes but not capacity" ) {
|
||||
REQUIRE( v.size() == 0 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
WHEN( "more capacity is reserved" ) {
|
||||
v.reserve( 10 );
|
||||
|
||||
THEN( "the capacity changes but not the size" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 10 );
|
||||
}
|
||||
}
|
||||
WHEN( "less capacity is reserved" ) {
|
||||
v.reserve( 0 );
|
||||
|
||||
THEN( "neither size nor capacity are changed" ) {
|
||||
REQUIRE( v.size() == 5 );
|
||||
REQUIRE( v.capacity() >= 5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Conveniently, these tests will be reported as follows when run:
|
||||
|
||||
```
|
||||
Scenario: vectors can be sized and resized
|
||||
Given: A vector with some items
|
||||
When: more capacity is reserved
|
||||
Then: the capacity changes but not the size
|
||||
```
|
||||
|
||||
<a id="scaling-up"></a>
|
||||
## Scaling up
|
||||
|
||||
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
|
||||
|
||||
The requirement is that the following block of code ([or equivalent](own-main.md#top)):
|
||||
|
||||
```c++
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
||||
```
|
||||
|
||||
appears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include "catch.hpp"``` - do not repeat the ```#define```!
|
||||
|
||||
In fact it is usually a good idea to put the block with the ```#define``` [in its own source file](slow-compiles.md#top) (code example [main](../examples/020-TestCase-1.cpp), [tests](../examples/020-TestCase-2.cpp)).
|
||||
|
||||
Do not write your tests in header files!
|
||||
|
||||
|
||||
## BDD style testing
|
||||
## Type parametrised test cases
|
||||
|
||||
Catch2 also provides some basic support for BDD-style testing. There are
|
||||
macro aliases for `TEST_CASE` and `SECTIONS` that you can use so that
|
||||
the resulting tests read as BDD spec. `SCENARIO` acts as a `TEST_CASE`
|
||||
with "Scenario: " name prefix. Then there are `GIVEN`, `WHEN`, `THEN`
|
||||
(and their variants with `AND_` prefix), which act as a `SECTION`,
|
||||
similarly prefixed with the macro name.
|
||||
Test cases in Catch2 can be also parametrised by type, via the
|
||||
`TEMPLATE_TEST_CASE` and `TEMPLATE_PRODUCT_TEST_CASE` macros,
|
||||
which behave in the same way the `TEST_CASE` macro, but are run for
|
||||
every type or type combination.
|
||||
|
||||
For more details on the macros look at the [test cases and
|
||||
sections](test-cases-and-sections.md#top) part of the reference docs,
|
||||
or at the [vector example done with BDD macros](../examples/120-Bdd-ScenarioGivenWhenThen.cpp).
|
||||
|
||||
|
||||
## Data and Type driven tests
|
||||
|
||||
Test cases in Catch2 can also be driven by types, input data, or both
|
||||
at the same time.
|
||||
|
||||
For more details look into the Catch2 reference, either at the
|
||||
[type parametrized test cases](test-cases-and-sections.md#type-parametrised-test-cases),
|
||||
or [data generators](generators.md#top).
|
||||
For more details, see our documentation on [test cases and
|
||||
sections](test-cases-and-sections.md#type-parametrised-test-cases).
|
||||
|
||||
|
||||
## Next steps
|
||||
|
||||
This page is a brief introduction to get you up and running with Catch2,
|
||||
and to show the basic features of Catch2. The features mentioned here
|
||||
can get you quite far, but there are many more. However, you can read
|
||||
about these as you go, in the ever-growing [reference section](Readme.md#top)
|
||||
of the documentation.
|
||||
This has been a brief introduction to get you up and running with Catch, and to point out some of the key differences between Catch and other frameworks you may already be familiar with. This will get you going quite far already and you are now in a position to dive in and write some tests.
|
||||
|
||||
Of course there is more to learn - most of which you should be able to page-fault in as you go. Please see the ever-growing [Reference section](Readme.md#top) for what's available.
|
||||
|
||||
---
|
||||
|
||||
|
@@ -1,100 +0,0 @@
|
||||
<a id="top"></a>
|
||||
# Best practices and other tips on using Catch2
|
||||
|
||||
## Running tests
|
||||
|
||||
Your tests should be run in a manner roughly equivalent with:
|
||||
|
||||
```
|
||||
./tests --order rand --warn NoAssertions
|
||||
```
|
||||
|
||||
Notice that all the tests are run in a large batch, their relative order
|
||||
is randomized, and that you ask Catch2 to fail test whose leaf-path
|
||||
does not contain an assertion.
|
||||
|
||||
The reason I recommend running all your tests in the same process is that
|
||||
this exposes your tests to interference from their runs. This can be both
|
||||
positive interference, where the changes in global state from previous
|
||||
test allow later tests to pass, but also negative interference, where
|
||||
changes in global state from previous test causes later tests to fail.
|
||||
|
||||
In my experience, interference, especially destructive interference,
|
||||
usually comes from errors in the code under test, rather than the tests
|
||||
themselves. This means that by allowing interference to happen, our tests
|
||||
can find these issues. Obviously, to shake out interference coming from
|
||||
different orderings of tests, the test order also need to be shuffled
|
||||
between runs.
|
||||
|
||||
However, running all tests in a single batch eventually becomes impractical
|
||||
as they will take too long to run, and you will want to run your tests
|
||||
in parallel.
|
||||
|
||||
|
||||
<a id="parallel-tests"></a>
|
||||
## Running tests in parallel
|
||||
|
||||
There are multiple ways of running tests in parallel, with various level
|
||||
of structure. If you are using CMake and CTest, then we provide a helper
|
||||
function [`catch_discover_tests`](cmake-integration.md#automatic-test-registration)
|
||||
that registers each Catch2 `TEST_CASE` as a single CTest test, which
|
||||
is then run in a separate process. This is an easy way to set up parallel
|
||||
tests if you are already using CMake & CTest to run your tests, but you
|
||||
will lose the advantage of running tests in batches.
|
||||
|
||||
|
||||
Catch2 also supports [splitting tests in a binary into multiple
|
||||
shards](command-line.md#test-sharding). This can be used by any test
|
||||
runner to run batches of tests in parallel. Do note that when selecting
|
||||
on the number of shards, you should have more shards than there are cores,
|
||||
to avoid issues with long-running tests getting accidentally grouped in
|
||||
the same shard, and causing long-tailed execution time.
|
||||
|
||||
**Note that naively composing sharding and random ordering of tests will break.**
|
||||
|
||||
Invoking Catch2 test executable like this
|
||||
|
||||
```text
|
||||
./tests --order rand --shard-index 0 --shard-count 3
|
||||
./tests --order rand --shard-index 1 --shard-count 3
|
||||
./tests --order rand --shard-index 2 --shard-count 3
|
||||
```
|
||||
|
||||
does not guarantee covering all tests inside the executable, because
|
||||
each invocation will have its own random seed, thus it will have its own
|
||||
random order of tests and thus the partitioning of tests into shards will
|
||||
be different as well.
|
||||
|
||||
To do this properly, you need the individual shards to share the random
|
||||
seed, e.g.
|
||||
```text
|
||||
./tests --order rand --shard-index 0 --shard-count 3 --rng-seed 0xBEEF
|
||||
./tests --order rand --shard-index 1 --shard-count 3 --rng-seed 0xBEEF
|
||||
./tests --order rand --shard-index 2 --shard-count 3 --rng-seed 0xBEEF
|
||||
```
|
||||
|
||||
Catch2 actually provides a helper to automatically register multiple shards
|
||||
as CTest tests, with shared random seed that changes each CTest invocation.
|
||||
For details look at the documentation of
|
||||
[`CatchShardTests.cmake` CMake script](cmake-integration.md#catchshardtestscmake).
|
||||
|
||||
|
||||
## Organizing tests into binaries
|
||||
|
||||
Both overly large and overly small test binaries can cause issues. Overly
|
||||
large test binaries have to be recompiled and relinked often, and the
|
||||
link times are usually also long. Overly small test binaries in turn pay
|
||||
significant overhead from linking against Catch2 more often per compiled
|
||||
test case, and also make it hard/impossible to run tests in batches.
|
||||
|
||||
Because there is no hard and fast rule for the right size of a test binary,
|
||||
I recommend having 1:1 correspondence between libraries in project and test
|
||||
binaries. (At least if it is possible, in some cases it is not.) Having
|
||||
a test binary for each library in project keeps related tests together,
|
||||
and makes tests easy to navigate by reflecting the project's organizational
|
||||
structure.
|
||||
|
||||
|
||||
---
|
||||
|
||||
[Home](Readme.md#top)
|
@@ -6,53 +6,40 @@ including (but not limited to),
|
||||
[Google Test](http://code.google.com/p/googletest/),
|
||||
[Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html),
|
||||
[CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page),
|
||||
[Cute](http://www.cute-test.com), and
|
||||
[Cute](http://www.cute-test.com),
|
||||
[many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B).
|
||||
|
||||
So what does Catch2 bring to the party that differentiates it from these? Apart from the catchy name, of course.
|
||||
|
||||
So what does Catch bring to the party that differentiates it from these? Apart from a Catchy name, of course.
|
||||
|
||||
## Key Features
|
||||
|
||||
* Quick and easy to get started. Just download two files, add them into your project and you're away.
|
||||
* No external dependencies. As long as you can compile C++14 and have the C++ standard library available.
|
||||
* Quick and Really easy to get started. Just download catch.hpp, `#include` it and you're away.
|
||||
* No external dependencies. As long as you can compile C++11 and have a C++ standard library available.
|
||||
* Write test cases as, self-registering, functions (or methods, if you prefer).
|
||||
* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures).
|
||||
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
|
||||
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
|
||||
* Tests are named using free-form strings - no more couching names in legal identifiers.
|
||||
|
||||
|
||||
## Other core features
|
||||
|
||||
* Tests can be tagged for easily running ad-hoc groups of tests.
|
||||
* Failures can (optionally) break into the debugger on common platforms.
|
||||
* Failures can (optionally) break into the debugger on Windows and Mac.
|
||||
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
|
||||
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
|
||||
* A default main() function is provided, but you can supply your own for complete control (e.g. integration into your own test runner GUI).
|
||||
* A command line parser is provided and can still be used if you choose to provide your own main() function.
|
||||
* A command line parser is provided and can still be used if you choose to provided your own main() function.
|
||||
* Catch can test itself.
|
||||
* Alternative assertion macro(s) report failures but don't abort the test case
|
||||
* Good set of facilities for floating point comparisons (`Catch::Approx` and full set of matchers)
|
||||
* Floating point tolerance comparisons are built in using an expressive Approx() syntax.
|
||||
* Internal and friendly macros are isolated so name clashes can be managed
|
||||
* Data generators (data driven test support)
|
||||
* Hamcrest-style Matchers for testing complex properties
|
||||
* Microbenchmarking support
|
||||
* Matchers
|
||||
|
||||
## Who else is using Catch?
|
||||
|
||||
## Who else is using Catch2?
|
||||
See the list of [open source projects using Catch](opensource-users.md#top).
|
||||
|
||||
A whole lot of people. According to [the 2022 JetBrains C++ ecosystem survey](https://www.jetbrains.com/lp/devecosystem-2022/cpp/#Which-unit-testing-frameworks-do-you-regularly-use),
|
||||
about 12% of C++ programmers use Catch2 for unit testing, making it the
|
||||
second most popular unit testing framework.
|
||||
|
||||
You can also take a look at the (incomplete) list of [open source projects](opensource-users.md#top)
|
||||
or the (very incomplete) list of [commercial users of Catch2](commercial-users.md#top)
|
||||
for some idea on who else also uses Catch2.
|
||||
|
||||
---
|
||||
|
||||
See the [tutorial](tutorial.md#top) to get more of a taste of using
|
||||
Catch2 in practice.
|
||||
See the [tutorial](tutorial.md#top) to get more of a taste of using Catch in practice
|
||||
|
||||
---
|
||||
|
||||
|
15
examples/000-CatchMain.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
// 000-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>
|
||||
|
||||
// That's it
|
||||
|
||||
// Compile implementation of Catch for use with files that do contain tests:
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 000-CatchMain.cpp
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -c 000-CatchMain.cpp
|
@@ -1,16 +1,11 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 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 ? 1 : Factorial( number - 1 ) * number; // pass
|
||||
}
|
||||
@@ -27,7 +22,7 @@ TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) {
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 010-TestCase 010-TestCase.cpp && 010-TestCase --success
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 010-TestCase 010-TestCase.cpp && 010-TestCase --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 010-TestCase.cpp && 010-TestCase --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
|
@@ -1,14 +1,12 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 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]" ) {
|
||||
}
|
||||
@@ -18,8 +16,8 @@ TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:
|
||||
// Here just to show there are two source files via option --list-tests.
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 020-TestCase-1.cpp
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 020-TestCase TestCase-1.o 020-TestCase-2.cpp && 020-TestCase --success
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 020-TestCase-1.cpp
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 020-TestCase TestCase-1.o 020-TestCase-2.cpp && 020-TestCase --success
|
||||
//
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -c 020-TestCase-1.cpp
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -Fe020-TestCase.exe 020-TestCase-1.obj 020-TestCase-2.cpp && 020-TestCase --success
|
||||
|
@@ -1,18 +1,10 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 020-TestCase-2.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 ? 1 : Factorial( number - 1 ) * number; // pass
|
||||
}
|
||||
|
@@ -1,11 +1,3 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 030-Asn-Require-Check.cpp
|
||||
|
||||
// Catch has two natural expression assertion macro's:
|
||||
@@ -16,11 +8,11 @@
|
||||
// - REQUIRE_FALSE() stops at first failure.
|
||||
// - CHECK_FALSE() continues after failure.
|
||||
|
||||
// main() provided by linkage to Catch2WithMain
|
||||
// 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";
|
||||
}
|
||||
|
||||
@@ -61,8 +53,8 @@ TEST_CASE( "Assert that something is false (continue after failure)", "[check-fa
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 030-Asn-Require-Check 030-Asn-Require-Check.cpp && 030-Asn-Require-Check --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 030-Asn-Require-Check.cpp && 030-Asn-Require-Check --success
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 030-Asn-Require-Check 030-Asn-Require-Check.cpp 000-CatchMain.o && 030-Asn-Require-Check --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 030-Asn-Require-Check.cpp 000-CatchMain.obj && 030-Asn-Require-Check --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
|
@@ -1,21 +1,12 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 100-Fix-Section.cpp
|
||||
|
||||
// Catch has two ways to express fixtures:
|
||||
// - Sections (this file)
|
||||
// - Traditional class-based fixtures
|
||||
|
||||
// main() provided by linkage to Catch2WithMain
|
||||
// main() provided in 000-CatchMain.cpp
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <vector>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
|
||||
@@ -53,8 +44,8 @@ TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 100-Fix-Section 100-Fix-Section.cpp && 100-Fix-Section --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 100-Fix-Section.cpp && 100-Fix-Section --success
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 100-Fix-Section 100-Fix-Section.cpp 000-CatchMain.o && 100-Fix-Section --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 100-Fix-Section.cpp 000-CatchMain.obj && 100-Fix-Section --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
|
@@ -1,20 +1,12 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 110-Fix-ClassFixture.cpp
|
||||
|
||||
// Catch has two ways to express fixtures:
|
||||
// - Sections
|
||||
// - Traditional class-based fixtures (this file)
|
||||
|
||||
// main() provided by linkage to Catch2WithMain
|
||||
// main() provided in 000-CatchMain.cpp
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
class DBConnection
|
||||
{
|
||||
@@ -60,11 +52,8 @@ TEST_CASE_METHOD( UniqueTestsFixture, "Create Employee/Normal", "[create]" ) {
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 110-Fix-ClassFixture 110-Fix-ClassFixture.cpp && 110-Fix-ClassFixture --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 110-Fix-ClassFixture.cpp && 110-Fix-ClassFixture --success
|
||||
//
|
||||
// Compile with pkg-config:
|
||||
// - g++ -std=c++14 -Wall $(pkg-config catch2-with-main --cflags) -o 110-Fix-ClassFixture 110-Fix-ClassFixture.cpp $(pkg-config catch2-with-main --libs)
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 110-Fix-ClassFixture 110-Fix-ClassFixture.cpp 000-CatchMain.o && 110-Fix-ClassFixture --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 110-Fix-ClassFixture.cpp 000-CatchMain.obj && 110-Fix-ClassFixture --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
|
@@ -1,74 +0,0 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// Fixture.cpp
|
||||
|
||||
// Catch2 has three ways to express fixtures:
|
||||
// - Sections
|
||||
// - Traditional class-based fixtures that are created and destroyed on every
|
||||
// partial run
|
||||
// - Traditional class-based fixtures that are created at the start of a test
|
||||
// case and destroyed at the end of a test case (this file)
|
||||
|
||||
// main() provided by linkage to Catch2WithMain
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <thread>
|
||||
|
||||
class ClassWithExpensiveSetup {
|
||||
public:
|
||||
ClassWithExpensiveSetup() {
|
||||
// Imagine some really expensive set up here.
|
||||
// e.g.
|
||||
// setting up a D3D12/Vulkan Device,
|
||||
// connecting to a database,
|
||||
// loading a file
|
||||
// etc etc etc
|
||||
std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
|
||||
}
|
||||
|
||||
~ClassWithExpensiveSetup() noexcept {
|
||||
// We can do any clean up of the expensive class in the destructor
|
||||
// e.g.
|
||||
// destroy D3D12/Vulkan Device,
|
||||
// disconnecting from a database,
|
||||
// release file handle
|
||||
// etc etc etc
|
||||
std::this_thread::sleep_for( std::chrono::seconds( 1 ) );
|
||||
}
|
||||
|
||||
int getInt() const { return 42; }
|
||||
};
|
||||
|
||||
struct MyFixture {
|
||||
|
||||
// The test case member function is const.
|
||||
// Therefore we need to mark any member of the fixture
|
||||
// that needs to mutate as mutable.
|
||||
mutable int myInt = 0;
|
||||
ClassWithExpensiveSetup expensive;
|
||||
};
|
||||
|
||||
// Only one object of type MyFixture will be instantiated for the run
|
||||
// of this test case even though there are two leaf sections.
|
||||
// This is useful if your test case requires an object that is
|
||||
// expensive to create and could be reused for each partial run of the
|
||||
// test case.
|
||||
TEST_CASE_PERSISTENT_FIXTURE( MyFixture, "Tests with MyFixture" ) {
|
||||
|
||||
const int val = myInt++;
|
||||
|
||||
SECTION( "First partial run" ) {
|
||||
const auto otherValue = expensive.getInt();
|
||||
REQUIRE( val == 0 );
|
||||
REQUIRE( otherValue == 42 );
|
||||
}
|
||||
|
||||
SECTION( "Second partial run" ) { REQUIRE( val == 1 ); }
|
||||
}
|
@@ -1,16 +1,8 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 120-Bdd-ScenarioGivenWhenThen.cpp
|
||||
|
||||
// main() provided by linkage with Catch2WithMain
|
||||
// main() provided in 000-CatchMain.cpp
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
||||
|
||||
@@ -56,8 +48,8 @@ SCENARIO( "vectors can be sized and resized", "[vector]" ) {
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 120-Bdd-ScenarioGivenWhenThen 120-Bdd-ScenarioGivenWhenThen.cpp && 120-Bdd-ScenarioGivenWhenThen --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 120-Bdd-ScenarioGivenWhenThen.cpp && 120-Bdd-ScenarioGivenWhenThen --success
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 120-Bdd-ScenarioGivenWhenThen 120-Bdd-ScenarioGivenWhenThen.cpp 000-CatchMain.o && 120-Bdd-ScenarioGivenWhenThen --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 120-Bdd-ScenarioGivenWhenThen.cpp 000-CatchMain.obj && 120-Bdd-ScenarioGivenWhenThen --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
|
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
@@ -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']
|
||||
// ...
|
@@ -1,11 +1,3 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 210-Evt-EventListeners.cpp
|
||||
|
||||
// Contents:
|
||||
@@ -13,26 +5,22 @@
|
||||
// 2. My listener and registration
|
||||
// 3. Test cases
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
||||
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
||||
#include <catch2/catch_test_case_info.hpp>
|
||||
// main() provided in 000-CatchMain.cpp
|
||||
|
||||
// Let Catch provide the required interfaces:
|
||||
#define CATCH_CONFIG_EXTERNAL_INTERFACES
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <iostream>
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 1. Printing of listener data:
|
||||
//
|
||||
|
||||
|
||||
namespace {
|
||||
std::string ws(int const level) {
|
||||
return std::string( 2 * level, ' ' );
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Catch::Tag t) {
|
||||
return out << "original: " << t.original;
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
||||
os << "{ ";
|
||||
@@ -40,6 +28,7 @@ std::ostream& operator<<( std::ostream& os, std::vector<T> const& v ) {
|
||||
os << x << ", ";
|
||||
return os << "}";
|
||||
}
|
||||
|
||||
// struct SourceLineInfo {
|
||||
// char const* file;
|
||||
// std::size_t line;
|
||||
@@ -130,36 +119,32 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
||||
os << ws(level+1) << "- aborting: " << info.aborting << "\n";
|
||||
}
|
||||
|
||||
// struct Tag {
|
||||
// StringRef original, lowerCased;
|
||||
// };
|
||||
// struct TestCaseInfo {
|
||||
// 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 {
|
||||
// None = 0,
|
||||
// IsHidden = 1 << 1,
|
||||
// ShouldFail = 1 << 2,
|
||||
// MayFail = 1 << 3,
|
||||
// Throws = 1 << 4,
|
||||
// NonPortable = 1 << 5,
|
||||
// Benchmark = 1 << 6
|
||||
// };
|
||||
// std::string tagsAsString() const;
|
||||
//
|
||||
//
|
||||
// struct TestCaseInfo : NonCopyable {
|
||||
//
|
||||
// bool isHidden() const;
|
||||
// bool throws() const;
|
||||
// bool okToFail() const;
|
||||
// bool expectedToFail() const;
|
||||
//
|
||||
//
|
||||
// std::string name;
|
||||
// std::string className;
|
||||
// std::vector<Tag> tags;
|
||||
// SourceLineInfo lineInfo;
|
||||
// TestCaseProperties properties = TestCaseProperties::None;
|
||||
// };
|
||||
// std::string name;
|
||||
// std::string className;
|
||||
// std::string description;
|
||||
// std::vector<std::string> tags;
|
||||
// std::vector<std::string> lcaseTags;
|
||||
// SourceLineInfo lineInfo;
|
||||
// SpecialProperties properties;
|
||||
// };
|
||||
|
||||
void print( std::ostream& os, int const level, std::string const& title, Catch::TestCaseInfo const& info ) {
|
||||
os << ws(level ) << title << ":\n"
|
||||
@@ -170,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) << "- name: '" << info.name << "'\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 );
|
||||
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 {
|
||||
@@ -185,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 ) {
|
||||
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 );
|
||||
os << ws(level+1) << "- stdOut: " << info.stdOut << "\n"
|
||||
<< ws(level+1) << "- stdErr: " << info.stdErr << "\n"
|
||||
@@ -286,8 +273,8 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
||||
print( os, level+1 , "- getSourceInfo(): ", info.getSourceInfo() );
|
||||
os << ws(level+1) << "- getTestMacroName(): '" << info.getTestMacroName() << "'\n";
|
||||
|
||||
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_info (AssertionInfo)", info.m_info );
|
||||
// print( os, level+1 , "- *** m_resultData (AssertionResultData)", info.m_resultData );
|
||||
}
|
||||
|
||||
// struct AssertionStats {
|
||||
@@ -307,16 +294,15 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
|
||||
// 2. My listener and registration:
|
||||
//
|
||||
|
||||
char const * const dashed_line =
|
||||
char const * dashed_line =
|
||||
"--------------------------------------------------------------------------";
|
||||
|
||||
struct MyListener : Catch::TestEventListenerBase {
|
||||
|
||||
struct MyListener : Catch::EventListenerBase {
|
||||
|
||||
using EventListenerBase::EventListenerBase; // inherit constructor
|
||||
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
|
||||
|
||||
// Get rid of Wweak-tables
|
||||
~MyListener() override;
|
||||
~MyListener();
|
||||
|
||||
// The whole test run starting
|
||||
void testRunStarting( Catch::TestRunInfo const& testRunInfo ) override {
|
||||
@@ -374,18 +360,18 @@ struct MyListener : Catch::EventListenerBase {
|
||||
print( std::cout, 1, "- assertionInfo", assertionInfo );
|
||||
}
|
||||
|
||||
void assertionEnded( Catch::AssertionStats const& assertionStats ) override {
|
||||
bool assertionEnded( Catch::AssertionStats const& assertionStats ) override {
|
||||
std::cout << "\nEvent: assertionEnded:\n";
|
||||
print( std::cout, 1, "- assertionStats", assertionStats );
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
CATCH_REGISTER_LISTENER( MyListener )
|
||||
|
||||
// Get rid of Wweak-tables
|
||||
MyListener::~MyListener() = default;
|
||||
MyListener::~MyListener() {}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// 3. Test cases:
|
||||
@@ -427,8 +413,8 @@ TEST_CASE_METHOD( Fixture, "3: Testcase with class-based fixture", "[tag-C][tag-
|
||||
}
|
||||
|
||||
// Compile & run:
|
||||
// - g++ -std=c++14 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 210-Evt-EventListeners 210-Evt-EventListeners.cpp && 210-Evt-EventListeners --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 210-Evt-EventListeners.cpp && 210-Evt-EventListeners --success
|
||||
// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 210-Evt-EventListeners 210-Evt-EventListeners.cpp 000-CatchMain.o && 210-Evt-EventListeners --success
|
||||
// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 210-Evt-EventListeners.cpp 000-CatchMain.obj && 210-Evt-EventListeners --success
|
||||
|
||||
// Expected compact output (all assertions):
|
||||
//
|
||||
|
@@ -1,11 +1,3 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 231-Cfg-OutputStreams.cpp
|
||||
// Show how to replace the streams with a simple custom made streambuf.
|
||||
|
||||
@@ -13,16 +5,17 @@
|
||||
// semantic, because it buffers the output. For most uses however,
|
||||
// there is no important difference between having `std::cerr` buffered
|
||||
// or unbuffered.
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <cstdio>
|
||||
#define CATCH_CONFIG_NOSTDOUT
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
||||
class out_buff : public std::stringbuf {
|
||||
std::FILE* m_stream;
|
||||
public:
|
||||
out_buff(std::FILE* stream):m_stream(stream) {}
|
||||
~out_buff() override;
|
||||
~out_buff();
|
||||
int sync() override {
|
||||
int ret = 0;
|
||||
for (unsigned char c : str()) {
|
||||
|
@@ -1,41 +0,0 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 232-Cfg-CustomMain.cpp
|
||||
// Show how to use custom main and add a custom option to the CLI parser
|
||||
|
||||
#include <catch2/catch_session.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Catch::Session session; // There must be exactly one instance
|
||||
|
||||
int height = 0; // Some user variable you want to be able to set
|
||||
|
||||
// Build a new parser on top of Catch2's
|
||||
using namespace Catch::Clara;
|
||||
auto cli
|
||||
= session.cli() // Get Catch2's command line parser
|
||||
| Opt( height, "height" ) // bind variable to a new option, with a hint string
|
||||
["--height"] // the option names it will respond to
|
||||
("how high?"); // description string for the help output
|
||||
|
||||
// Now pass the new composite back to Catch2 so it uses that
|
||||
session.cli( cli );
|
||||
|
||||
// Let Catch2 (using Clara) parse the command line
|
||||
int returnCode = session.applyCommandLine( argc, argv );
|
||||
if( returnCode != 0 ) // Indicates a command line error
|
||||
return returnCode;
|
||||
|
||||
// if set on the command line then 'height' is now set at this point
|
||||
std::cout << "height: " << height << '\n';
|
||||
|
||||
return session.run();
|
||||
}
|
@@ -1,27 +1,15 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 300-Gen-OwnGenerator.cpp
|
||||
// Shows how to define a custom generator.
|
||||
|
||||
// Specifically we will implement a random number generator for integers
|
||||
// It will have infinite capacity and settable lower/upper bound
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <random>
|
||||
|
||||
namespace {
|
||||
|
||||
// This class shows how to implement a simple generator for Catch tests
|
||||
class RandomIntGenerator final : public Catch::Generators::IGenerator<int> {
|
||||
class RandomIntGenerator : public Catch::Generators::IGenerator<int> {
|
||||
std::minstd_rand m_rand;
|
||||
std::uniform_int_distribution<> m_dist;
|
||||
int current_number;
|
||||
@@ -50,15 +38,9 @@ int const& RandomIntGenerator::get() const {
|
||||
// Notice that it returns an instance of GeneratorWrapper<int>, which
|
||||
// is a value-wrapper around std::unique_ptr<IGenerator<int>>.
|
||||
Catch::Generators::GeneratorWrapper<int> random(int low, int high) {
|
||||
return Catch::Generators::GeneratorWrapper<int>(
|
||||
new RandomIntGenerator(low, high)
|
||||
// Another possibility:
|
||||
// Catch::Detail::make_unique<RandomIntGenerator>(low, high)
|
||||
);
|
||||
return Catch::Generators::GeneratorWrapper<int>(std::unique_ptr<Catch::Generators::IGenerator<int>>(new RandomIntGenerator(low, high)));
|
||||
}
|
||||
|
||||
} // end anonymous namespaces
|
||||
|
||||
// The two sections in this test case are equivalent, but the first one
|
||||
// is much more readable/nicer to use
|
||||
TEST_CASE("Generating random ints", "[example][generator]") {
|
||||
@@ -68,7 +50,7 @@ TEST_CASE("Generating random ints", "[example][generator]") {
|
||||
REQUIRE(i <= 100);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@@ -1,11 +1,3 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 301-Gen-MapTypeConversion.cpp
|
||||
// Shows how to use map to modify generator's return type.
|
||||
|
||||
@@ -13,30 +5,27 @@
|
||||
// that converts the strings using stoi, so the returned type is actually
|
||||
// an int.
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators_adapters.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
// 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 fixed stringstream.
|
||||
class LineGenerator final : public Catch::Generators::IGenerator<std::string> {
|
||||
class LineGenerator : public Catch::Generators::IGenerator<std::string> {
|
||||
std::string m_line;
|
||||
std::stringstream m_stream;
|
||||
public:
|
||||
explicit LineGenerator( std::string const& lines ) {
|
||||
m_stream.str( lines );
|
||||
LineGenerator() {
|
||||
m_stream.str("1\n2\n3\n4\n");
|
||||
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;
|
||||
|
||||
|
||||
bool next() override {
|
||||
return !!std::getline(m_stream, m_line);
|
||||
}
|
||||
@@ -49,20 +38,20 @@ std::string const& LineGenerator::get() const {
|
||||
// This helper function provides a nicer UX when instantiating the generator
|
||||
// Notice that it returns an instance of GeneratorWrapper<std::string>, which
|
||||
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
|
||||
Catch::Generators::GeneratorWrapper<std::string>
|
||||
lines( std::string const& lines ) {
|
||||
Catch::Generators::GeneratorWrapper<std::string> lines(std::string /* ignored for example */) {
|
||||
return Catch::Generators::GeneratorWrapper<std::string>(
|
||||
new LineGenerator( lines ) );
|
||||
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]") {
|
||||
auto num = GENERATE(
|
||||
map<int>( []( std::string const& line ) { return std::stoi( line ); },
|
||||
lines( "1\n2\n3\n4\n" ) ) );
|
||||
|
||||
auto num = GENERATE(map<int>([](std::string const& line) { return std::stoi(line); },
|
||||
lines("fake-file")));
|
||||
|
||||
REQUIRE(num > 0);
|
||||
}
|
||||
|
||||
|
@@ -1,17 +1,8 @@
|
||||
|
||||
// Copyright Catch2 Authors
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
// 302-Gen-Table.cpp
|
||||
// Shows how to use table to run a test many times with different inputs. Lifted from examples on
|
||||
// issue #850.
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <string>
|
||||
|
||||
struct TestSubject {
|
||||
@@ -52,11 +43,11 @@ TEST_CASE("Table allows pre-computed test inputs and outputs", "[example][genera
|
||||
|
||||
/* Possible simplifications where less legacy toolchain support is needed:
|
||||
*
|
||||
* - With libstdc++6 or newer, the make_tuple() calls can be omitted
|
||||
* - With libstdc++6 or newer, the make_tuple() calls can be ommitted
|
||||
* (technically C++17 but does not require -std in GCC/Clang). See
|
||||
* https://stackoverflow.com/questions/12436586/tuple-vector-and-initializer-list
|
||||
*
|
||||
* - In C++17 mode std::tie() and the preceding variable declarations can be
|
||||
* - In C++17 mode std::tie() and the preceeding variable delcarations can be
|
||||
* replaced by structured bindings: auto [test_input, expected] = GENERATE(
|
||||
* table<std::string, size_t>({ ...
|
||||
*/
|
||||
|