Compare commits

...

27 Commits

Author SHA1 Message Date
Chris Thrasher
8efee9b763 Use std::string_view 2025-09-22 11:50:44 -06:00
Chris Thrasher
a5735af2f7 Use std::optional 2025-09-22 11:35:23 -06:00
Chris Thrasher
db46dc4cb2 Upgrade to C++17 2025-09-22 11:35:22 -06:00
Chris Thrasher
c6cefc6596 Disable reproducible build flags for dev builds 2025-09-21 21:43:51 -06:00
Silent
dc3a4ea41a Fix non-desktop Windows platforms not defining CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 correctly
Fixes building on non-desktop GDK platforms.
2025-09-17 20:25:26 +02:00
Martin Hořeňovský
cd93d202e0 Small refactoring in CAPTURE parsing 2025-08-26 12:40:13 +02:00
Martin Hořeňovský
227af796b4 Move MessageInfos into the run context
Together with the previous change, this means that `ScopedMessage`
only needs to keep around a single unsigned int.
2025-08-26 12:37:52 +02:00
Martin Hořeňovský
33adb4c779 Use only the ID of a message when removing it from context 2025-08-26 12:07:41 +02:00
Martin Hořeňovský
25319fd304 v3.10.0 2025-08-25 21:30:21 +02:00
Szapi
85c4bad86b Forbid deducing reference types for m_predicate in FilterGenerator (#3005)
Forbid deducing reference types for m_predicate in FilterGenerator to prevent dangling references.
This is needed for out-of-line predicates to work correctly instead of undefined behavior or crashes.

---------

Co-authored-by: Tek Mate <mate.tek@evosoft.com>
2025-08-23 21:55:38 +02:00
Martin Hořeňovský
582200a1f8 Make message macros (FAIL, WARN, INFO, etc) thread safe
This builds on the existing work to make assertion thread safe,
by adding an extra synchronization point in the holder of
`ReusableStringStream`'s stream instances, as those are used to
build the messages, and finishing the move of message scope holders
to be thread-local.
2025-08-23 11:08:18 +02:00
Martin Hořeňovský
f4e05a67bb Improve performance of writing XML
As with the JSON writer, the old code was made to be simple and
for each char just decided whether it needs escaping, or should be
written as-is. The new code instead looks for characters that need
escaping and batches writes of characters that do not.

This provides 4-8x speedup (length dependent) for writing strings
that do not need escaping, and keeps roughly the same performance
for those that do need escaping.
2025-08-22 17:03:35 +02:00
Martin Hořeňovský
fb2e4fbe41 Improve performance of writing JSON values
The old code was exceedingly simple, as it went char-by-char and
decided whether to write it to the output stream as-is, or escaped.
This caused a _lot_ of stream writes of individual characters.

The new code instead looks for characters that need escaping, and
bulk-writes the non-escaped characters in between them. This leads
to about the same performance for strings that comprise of only
escaped characters, and 3-10x improvement for strings without any
escaping needed.

In practice, we should expect the former rather than the latter,
but this is still nice improvement.
2025-08-22 17:00:40 +02:00
Martin Hořeňovský
78a9518a28 Don't add / to start of pkg-config file path when DESTDIR is unset
This broke installation on Windows, because the suddenly started
with a '/' instead of a drive letter.

Closes #3019
2025-08-21 20:58:55 +02:00
Shloka Jain
3e82ef9317 Fix color mode detection on FreeBSD by adding platform macro 2025-08-12 14:38:50 +02:00
Martin Hořeňovský
7cad6d7539 Handle DESTDIR env var when generating pkgconfig files
Having the ability to configure the installation path at config
time, and the ability to change the prefix at install time is not
enough, apparently people also use env var to redirect them instead.

Closes #3006
2025-08-09 23:05:18 +02:00
Martin Hořeňovský
644821ce28 v3.9.1 2025-08-09 00:30:23 +02:00
Martin Hořeňovský
03c62cdf2e Add tests for comparing & stringifying volatile pointers 2025-08-08 00:02:33 +02:00
Martin Hořeňovský
9a3d68315b Refactor CATCH_TRAP selection logic to prefer compiler-specific impls
Primarily this means that with Clang we use `__builtin_debugtrap`
if available.
2025-08-08 00:01:38 +02:00
Andrew Auclair
bcd4116df7 Update generators.md
Break specific purpose generators into random and range generator sections.
2025-08-06 19:31:42 +02:00
Martin Hořeňovský
9b3f508a1b Cleanup WIP changes from last commit 2025-08-02 10:21:41 +02:00
Martin Hořeňovský
c5e0ef4e67 Catch exceptions from StringMakers inside Detail::stringify
This stops tests failing falsely if the assertion passed, but the
stringification itself failed as the assertion was sent to the reporter.

I don't think that stringification should be fallible, but the
overhead in compilation ended up being small enough (<0.5% on `SelfTest`)
that it might be worth implementing, in case there is more users
with weird `StringMaker`s than just MongoDB.

Closes #2980
2025-08-02 10:11:52 +02:00
Martin Hořeňovský
17fe5eaa5c Fix StringMaker for time_point<system_clock> with non-default duration
Fixes #2685
2025-08-02 08:31:34 +02:00
Tim Lyon
fbfd13501c Fix warning in catch_unique_ptr::bool() 2025-08-02 00:15:06 +02:00
Martin Hořeňovský
ccabd4de89 Add enum types to what is captured by value by default
As it turns out, enums can be used to declare bitfields, and we
cannot form a reference to a bitfield in the cpature. Thus, we add
`std::is_enum` as a criteria to the default for `capture_by_value`,
so that enum-based bitfields are also captured by value and thus
decomposable.

Closes #3001
2025-07-30 20:20:38 +02:00
Martin Hořeňovský
a1c7ee115f Don't follow __assume(false) with std::terminate in NDEBUG builds
Having `std::terminate` as the backstop after `__assume(false)`
would trigger W4702 (unreachable code) with MSVC. As we want to
keep `__assume(false)` for the optimization hint in NDEBUG builds,
we have to avoid mixing in `std::terminate` for those builds.

Fixes #3007
2025-07-28 11:03:46 +02:00
Martin Hořeňovský
d547cae549 Fix bad error reporting for nested exceptions in default configuration
Bad handling of `TestFailureException` when translating unexpected
exceptions inside assertion macros led to the unexpected exceptions
handling erroring out through throwing the same exception again.

This was then backstopped by the machinery for handling uncaught
exceptions from assertions, which is normally used by the
`CATCH_CONFIG_FAST_COMPILE` machinery, where we assume that it can
only be invoked because the assertion macros are not configured to
catch assertions.

Closes #1292
2025-07-27 21:41:02 +02:00
215 changed files with 3378 additions and 4905 deletions

View File

@@ -1,6 +1,6 @@
---
Language: Cpp
Standard: c++14
Standard: c++17
# Note that we cannot use IncludeIsMainRegex functionality, because it
# does not support includes in angle brackets (<>)

View File

@@ -28,13 +28,12 @@ Checks: >-
-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,
-performance-enum-size,
portability-*,

View File

@@ -4,7 +4,7 @@ on: [push, pull_request]
jobs:
build:
name: meson ${{matrix.cxx}}, C++${{matrix.std}}, ${{matrix.build_type}}
name: meson ${{matrix.cxx}}, ${{matrix.build_type}}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
@@ -13,7 +13,6 @@ jobs:
- g++-11
- clang++-11
build_type: [debug, release]
std: [14, 17]
include:
- cxx: clang++-11
other_pkgs: clang-11
@@ -29,7 +28,7 @@ jobs:
- name: Configure
env:
CXX: ${{matrix.cxx}}
CXXFLAGS: -std=c++${{matrix.std}} ${{matrix.cxxflags}}
CXXFLAGS: -std=c++17 ${{matrix.cxxflags}}
# Note: $GITHUB_WORKSPACE is distinct from ${{runner.workspace}}.
# This is important
run: |

View File

@@ -7,7 +7,7 @@ on: [push, pull_request]
jobs:
build:
name: ${{matrix.build_description}}, ${{matrix.cxx}}, C++${{matrix.std}} ${{matrix.build_type}}
name: ${{matrix.build_description}}, ${{matrix.cxx}}, ${{matrix.build_type}}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
@@ -20,7 +20,6 @@ jobs:
- cxx: clang++-14
build_description: Surrogates build
build_type: Debug
std: 14
other_pkgs: clang-14
cmake_configurations: -DCATCH_BUILD_SURROGATES=ON
@@ -28,13 +27,11 @@ jobs:
- 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
@@ -42,29 +39,18 @@ jobs:
- 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
@@ -83,7 +69,6 @@ jobs:
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
@@ -116,7 +101,6 @@ jobs:
-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

View File

@@ -14,7 +14,6 @@ jobs:
- g++-10
- g++-11
- g++-12
- clang++-6.0
- clang++-7
- clang++-8
- clang++-9
@@ -24,7 +23,7 @@ jobs:
- clang++-13
- clang++-14
build_type: [Debug, Release]
std: [14]
std: [17]
include:
- cxx: g++-9
other_pkgs: g++-9
@@ -34,8 +33,6 @@ jobs:
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
@@ -52,15 +49,6 @@ jobs:
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

View File

@@ -12,7 +12,6 @@ jobs:
matrix:
image: [macos-13, macos-14, macos-15]
build_type: [Debug, Release]
std: [14, 17]
steps:
- uses: actions/checkout@v4
@@ -21,7 +20,6 @@ jobs:
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

View File

@@ -4,7 +4,7 @@ on: [push, pull_request]
jobs:
build:
name: ${{matrix.os}}, ${{matrix.std}}, ${{matrix.build_type}}, ${{matrix.platform}}
name: ${{matrix.os}}, ${{matrix.build_type}}, ${{matrix.platform}}
runs-on: ${{matrix.os}}
strategy:
fail-fast: false
@@ -12,7 +12,6 @@ jobs:
os: [windows-2022, windows-2025]
platform: [Win32, x64]
build_type: [Debug, Release]
std: [14, 17]
steps:
- uses: actions/checkout@v4
@@ -20,7 +19,6 @@ jobs:
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%

View File

@@ -27,11 +27,6 @@ expand_template(
"#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": "",
@@ -51,11 +46,6 @@ expand_template(
"#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": "",

View File

@@ -31,11 +31,6 @@ set(_OverridableOptions
"COLOUR_WIN32"
"COUNTER"
"CPP11_TO_STRING"
"CPP17_BYTE"
"CPP17_OPTIONAL"
"CPP17_STRING_VIEW"
"CPP17_UNCAUGHT_EXCEPTIONS"
"CPP17_VARIANT"
"GLOBAL_NEXTAFTER"
"POSIX_SIGNALS"
"USE_ASYNC"

View File

@@ -3,7 +3,7 @@ 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)
Description: A modern, C++-native test framework for C++17 and above (links in default main)
URL: https://github.com/catchorg/Catch2
Version: ${pkg_version}
Requires: catch2 = ${pkg_version}

View File

@@ -4,7 +4,7 @@ includedir=${prefix}/@include_dir@
libdir=${prefix}/@lib_dir@
Name: Catch2
Description: A modern, C++-native, test framework for C++14 and above
Description: A modern, C++-native, test framework for C++17 and above
URL: https://github.com/catchorg/Catch2
Version: @Catch2_VERSION@
Cflags: -I${includedir}

View File

@@ -34,7 +34,7 @@ if(CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()
project(Catch2
VERSION 3.9.0 # CML version placeholder, don't delete
VERSION 3.10.0 # CML version placeholder, don't delete
LANGUAGES CXX
HOMEPAGE_URL "https://github.com/catchorg/Catch2"
DESCRIPTION "A modern, C++-native, unit test framework."
@@ -195,17 +195,23 @@ if(NOT_SUBPROJECT)
"set(include_dir \"${CMAKE_INSTALL_INCLUDEDIR}\")"
"set(lib_dir \"${CMAKE_INSTALL_LIBDIR}\")"
[[
message(STATUS "DESTDIR: $ENV{DESTDIR}")
set(DESTDIR_PREFIX "")
if (DEFINED ENV{DESTDIR})
set(DESTDIR_PREFIX "$ENV{DESTDIR}")
endif ()
message(STATUS "PREFIX: ${DESTDIR_PREFIX}")
set(lib_name "$<TARGET_FILE_BASE_NAME:Catch2>")
configure_file(
"${impl_pc_file}"
"${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2.pc"
"${DESTDIR_PREFIX}${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2.pc"
@ONLY
)
set(lib_name "$<TARGET_FILE_BASE_NAME:Catch2WithMain>")
configure_file(
"${main_pc_file}"
"${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2-with-main.pc"
"${DESTDIR_PREFIX}${CMAKE_INSTALL_PREFIX}/${install_pkgconfdir}/catch2-with-main.pc"
@ONLY
)
]]

View File

@@ -11,7 +11,8 @@
"CMAKE_CXX_EXTENSIONS": "OFF",
"CMAKE_CXX_STANDARD_REQUIRED": "ON",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"CATCH_DEVELOPMENT_BUILD": "ON"
"CATCH_DEVELOPMENT_BUILD": "ON",
"CATCH_ENABLE_REPRODUCIBLE_BUILD": "OFF"
}
},
{

View File

@@ -10,7 +10,6 @@
[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>
[Enabling stringification](#enabling-stringification)<br>
[Disabling exceptions](#disabling-exceptions)<br>
@@ -128,23 +127,6 @@ Catch's selection, by defining either `CATCH_CONFIG_CPP11_TO_STRING` or
`CATCH_CONFIG_NO_CPP11_TO_STRING`.
## 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_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 contains basic compiler/standard detection and attempts to use
some C++17 features whenever appropriate. This automatic detection
can be manually overridden in both directions, that is, a feature
can be enabled by defining the macro in the table above, and disabled
by using `_NO_` in the macro, e.g. `CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS`.
## Other toggles
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
@@ -221,8 +203,8 @@ 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_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_VARIANT_STRINGMAKER // Provide StringMaker specialization for std::variant, std::monostate
CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER // Provide StringMaker specialization for std::optional
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.

View File

@@ -211,16 +211,10 @@ and so on.
### C++ standard version
Catch2 currently targets C++14 as the minimum supported C++ version.
Catch2 currently targets C++17 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

View File

@@ -114,11 +114,12 @@ 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
* 4 specific purpose generators (defined in `catch2/generators/catch_generators_random.hpp`)
* 2 random generators (defined in `catch2/generators/catch_generators_random.hpp`)
* `RandomIntegerGenerator<Integral>` -- generates random Integrals from range
* `RandomFloatGenerator<Float>` -- generates random Floats from range
* `RangeGenerator<T>(first, last)` -- generates all values inside a `[first, last)` arithmetic range (defined in `catch2/generators/catch_generators_range.hpp`)
* `IteratorGenerator<T>` -- copies and returns values from an iterator range (defined in `catch2/generators/catch_generators_range.hpp`)
* 2 range generators (defined in `catch2/generators/catch_generators_range.hpp`)
* `RangeGenerator<T>(first, last)` -- generates all values inside a `[first, last)` arithmetic range
* `IteratorGenerator<T>` -- copies and returns values from an iterator range
> `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch2 2.7.0.

View File

@@ -72,8 +72,8 @@ including the Catch2 header.
Example:
```cpp
TEST_CASE("STATIC_REQUIRE showcase", "[traits]") {
STATIC_REQUIRE( std::is_void<void>::value );
STATIC_REQUIRE_FALSE( std::is_void<int>::value );
STATIC_REQUIRE( std::is_void_v<void> );
STATIC_REQUIRE_FALSE( std::is_void_v<int> );
}
```
@@ -86,8 +86,8 @@ 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 );
STATIC_CHECK( std::is_void_v<void> );
STATIC_CHECK_FALSE( std::is_void_v<int> );
}
```

View File

@@ -2,6 +2,8 @@
# Release notes
**Contents**<br>
[3.10.0](#3100)<br>
[3.9.1](#391)<br>
[3.9.0](#390)<br>
[3.8.1](#381)<br>
[3.8.0](#380)<br>
@@ -68,6 +70,32 @@
[Even Older versions](#even-older-versions)<br>
## 3.10.0
### Fixes
* pkg-config files will take `DESTDIR` env var into account when selecting install destination (#3006, #3019)
* Changed `filter` to store the provided predicate by value (#3002, #3005)
* This is done to avoid dangling-by-default behaviour when `filter` is used inside `GENERATE_COPY`/`GENERATE_REF`.
### Improvements
* Escaping XML and JSON output is faster when the strings do not need escaping.
* The improvement starts at about 3x throughput, up to 10x for long strings.
* Message macros (`INFO`, `CAPTURE`, `WARN`, `SUCCEED`, etc) are now thread safe.
## 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

View File

@@ -109,10 +109,10 @@ and then `assertionEnded` event is emitted.
> [Introduced](https://github.com/catchorg/Catch2/issues/1616) in Catch2 2.9.0.
```cpp
void benchmarkPreparing( StringRef name ) override;
void benchmarkPreparing( std::string_view name ) override;
void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
void benchmarkFailed( StringRef error ) override;
void benchmarkFailed( std::string_view error ) override;
```
Due to the benchmark lifecycle being bit more complicated, the benchmarking
@@ -153,9 +153,9 @@ void listTags( std::vector<TagInfo> const& tagInfos );
## Miscellaneous events
```cpp
void reportInvalidTestSpec( StringRef unmatchedSpec );
void fatalErrorEncountered( StringRef error );
void noMatchingTestCases( StringRef unmatchedSpec );
void reportInvalidTestSpec( std::string_view unmatchedSpec );
void fatalErrorEncountered( std::string_view error );
void noMatchingTestCases( std::string_view unmatchedSpec );
```
These are one-off events that do not neatly fit into other categories.

View File

@@ -52,6 +52,20 @@ TEST_CASE("failing test") {
}
```
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)

View File

@@ -264,7 +264,7 @@ You can also have different arities in the _template-arg_ packs:
```cpp
TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities", "[template][product]", std::tuple, (int, (int, double), (int, double, float))) {
TestType x;
REQUIRE(std::tuple_size<TestType>::value >= 1);
REQUIRE(std::tuple_size_v<TestType> >= 1);
}
```

View File

@@ -2,7 +2,9 @@
# Thread safety in Catch2
**Contents**<br>
[Using assertion macros from multiple threads](#using-assertion-macros-from-multiple-threads)<br>
[Using assertion macros from spawned threads](#using-assertion-macros-from-spawned-threads)<br>
[Assertion-like message macros and spawned threads](#assertion-like-message-macros-and-spawned-threads)<br>
[Message macros and spawned threads](#message-macros-and-spawned-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>
@@ -10,17 +12,18 @@
> 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.
Thread safety in Catch2 is currently limited to all the assertion macros,
and to message or message-adjacent macros (e.g. `INFO` or `WARN`).
Interacting with benchmark macros, sections macros, generator macros, or
test case macros is not thread-safe. The way sections define paths through
the test is incompatible with user spawning threads arbitrarily, so this
limitation is here to stay.
**Important: thread safety in Catch2 is [opt-in](configuration.md#experimental-thread-safety)**
## Using assertion macros from multiple threads
## Using assertion macros from spawned 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
@@ -30,7 +33,7 @@ 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.
`REQUIRE` assertion inside user-spawned 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.
@@ -38,16 +41,36 @@ 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.**
## Assertion-like message macros and spawned threads
> Assertion-like messages were made thread safe in Catch2 3.10.0
Similarly to assertion macros, not all assertion-like message macros can
be used from spawned thread.
`SKIP` and `FAIL` macros stop the test execution. Just like with `REQUIRE`,
this means that they cannot be used inside user-spawned threads. `SUCCEED`,
`FAIL_CHECK` and `WARN` do not attempt to stop the test execution and
thus can be used from any thread.
## Message macros and spawned threads
> Message macros were made thread safe in Catch2 3.10.0
Macros that add extra messages to following assertion, such as `INFO`
or `CAPTURE`, are all thread safe and can be used in any thread. Note
that these messages are per-thread, and thus `INFO` inside a user-spawned
thread will not be seen by the main thread, and vice versa.
## examples
### `REQUIRE` from main thread, `CHECK` from spawned threads
### `REQUIRE` from the main thread, `CHECK` from spawned threads
```cpp
TEST_CASE( "Failed REQUIRE in main thread is fine" ) {
TEST_CASE( "Failed REQUIRE in the main thread is fine" ) {
std::vector<std::jthread> threads;
for ( size_t t = 0; t < 16; ++t) {
threads.emplace_back( []() {
@@ -85,7 +108,7 @@ TEST_CASE( "Successful REQUIRE in spawned thread is fine" ) {
This will also work as expected, because the `REQUIRE` is successful.
```cpp
TEST_CASE( "Failed REQUIRE in spawned thread is fine" ) {
TEST_CASE( "Failed REQUIRE in spawned thread kills the process" ) {
std::vector<std::jthread> threads;
for ( size_t t = 0; t < 16; ++t) {
threads.emplace_back( []() {
@@ -99,12 +122,88 @@ TEST_CASE( "Failed REQUIRE in spawned thread is fine" ) {
This will fail catastrophically and terminate the process.
### INFO across threads
```cpp
TEST_CASE( "messages don't cross threads" ) {
std::jthread t1( [&]() {
for ( size_t i = 0; i < 100; ++i ) {
INFO( "spawned thread #1" );
CHECK( 1 == 1 );
}
} );
std::thread t2( [&]() {
for (size_t i = 0; i < 100; ++i) {
UNSCOPED_INFO( "spawned thread #2" );
}
} );
for (size_t i = 0; i < 100; ++i) {
CHECK( 1 == 2 );
}
}
```
None of the failed checks will show the "spawned thread #1" message, as
that message is for the `t1` thread. If the reporter shows passing
assertions (e.g. due to the tests being run with `-s`), you will see the
"spawned thread #1" message alongside the passing `CHECK( 1 == 1 )` assertion.
The message "spawned thread #2" will never be shown, because there are no
assertions in `t2`.
### FAIL/SKIP from the main thread
```cpp
TEST_CASE( "FAIL in the 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; ++i) {
CHECK( true );
CHECK( false );
}
} );
}
FAIL();
}
```
This will work as expected, that is, the process will finish running
normally, the test case will fail and there will be 321 total assertions,
160 passing and 161 failing (`FAIL` counts as failed assertion).
However, when the main thread hits `FAIL`, it will wait for the other
threads to finish due to `std::jthread`'s destructor joining the spawned
thread. Due to this, using `SKIP` is not recommended once more threads
are spawned; while the main thread will bail from the test execution,
the spawned threads will keep running and may fail the test case.
### FAIL/SKIP from spawned threads
```cpp
TEST_CASE( "FAIL/SKIP in spawned thread kills the process" ) {
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) {
FAIL();
}
} );
}
}
```
As with failing `REQUIRE`, both `FAIL` and `SKIP` in spawned threads
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.
All of `STATIC_REQUIRE`, `STATIC_REQUIRE_FALSE`, `STATIC_CHECK`, and
`STATIC_CHECK_FALSE` are thread safe in the delayed evaluation configuration.
## Fatal errors and multiple threads

View File

@@ -15,7 +15,7 @@ So what does Catch2 bring to the party that differentiates it from these? Apart
## 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.
* No external dependencies. As long as you can compile C++17 and have the C++ standard library available.
* Write test cases as, self-registering, functions (or methods, if you prefer).
* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures).
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.

View File

@@ -27,7 +27,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++17 -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):

View File

@@ -18,8 +18,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++17 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 020-TestCase-1.cpp
// - g++ -std=c++17 -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

View File

@@ -61,7 +61,7 @@ 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
// - g++ -std=c++17 -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
// Expected compact output (all assertions):

View File

@@ -53,7 +53,7 @@ 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
// - g++ -std=c++17 -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
// Expected compact output (all assertions):

View File

@@ -60,11 +60,11 @@ 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
// - g++ -std=c++17 -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++17 -Wall $(pkg-config catch2-with-main --cflags) -o 110-Fix-ClassFixture 110-Fix-ClassFixture.cpp $(pkg-config catch2-with-main --libs)
// Expected compact output (all assertions):
//

View File

@@ -56,7 +56,7 @@ 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
// - g++ -std=c++17 -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
// Expected compact output (all assertions):

View File

@@ -131,7 +131,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
}
// struct Tag {
// StringRef original, lowerCased;
// std::string_view original, lowerCased;
// };
//
//
@@ -221,9 +221,9 @@ void print( std::ostream& os, int const level, std::string const& title, Catch::
// struct AssertionInfo
// {
// StringRef macroName;
// std::string_view macroName;
// SourceLineInfo lineInfo;
// StringRef capturedExpression;
// std::string_view capturedExpression;
// ResultDisposition::Flags resultDisposition;
// };
@@ -427,7 +427,7 @@ 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
// - g++ -std=c++17 -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
// Expected compact output (all assertions):

View File

@@ -22,24 +22,21 @@ struct TestSubject {
TEST_CASE("Table allows pre-computed test inputs and outputs", "[example][generator]") {
using std::make_tuple;
// do setup here as normal
TestSubject subj;
SECTION("This section is run for each row in the table") {
std::string test_input;
size_t expected_output;
std::tie( test_input, expected_output ) =
const auto [test_input, expected_output] =
GENERATE( table<std::string, size_t>(
{ /* In this case one of the parameters to our test case is the
* expected output, but this is not required. There could be
* multiple expected values in the table, which can have any
* (fixed) number of columns.
*/
make_tuple( "one", 3 ),
make_tuple( "two", 3 ),
make_tuple( "three", 5 ),
make_tuple( "four", 4 ) } ) );
{ "one", 3 },
{ "two", 3 },
{ "three", 5 },
{ "four", 4 } } ) );
// run the test
auto result = subj.GetLength(test_input);
@@ -50,14 +47,4 @@ TEST_CASE("Table allows pre-computed test inputs and outputs", "[example][genera
} // end section
}
/* Possible simplifications where less legacy toolchain support is needed:
*
* - With libstdc++6 or newer, the make_tuple() calls can be omitted
* (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
* replaced by structured bindings: auto [test_input, expected] = GENERATE(
* table<std::string, size_t>({ ...
*/
// Compiling and running this file will result in 4 successful assertions

View File

@@ -6,8 +6,8 @@
// SPDX-License-Identifier: BSL-1.0
// Catch v3.9.0
// Generated: 2025-07-24 22:00:25.173359
// Catch v3.10.0
// Generated: 2025-08-24 16:18:04.775778
// ----------------------------------------------------------
// This file is an amalgamation of multiple different files.
// You probably shouldn't edit it directly.
@@ -1057,8 +1057,9 @@ namespace Catch {
}
Capturer::~Capturer() {
assert( m_captured == m_messages.size() );
for ( size_t i = 0; i < m_captured; ++i )
for ( size_t i = 0; i < m_captured; ++i ) {
m_resultCapture.popScopedMessage( m_messages[i] );
}
}
void Capturer::captureValue( size_t index, std::string const& value ) {
@@ -2026,6 +2027,13 @@ namespace Detail {
rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
return rss.str();
}
std::string makeExceptionHappenedString() {
return "{ stringification failed with an exception: \"" +
translateActiveException() + "\" }";
}
} // end Detail namespace
@@ -2271,7 +2279,7 @@ namespace Catch {
}
Version const& libraryVersion() {
static Version version( 3, 9, 0, "", 0 );
static Version version( 3, 10, 0, "", 0 );
return version;
}
@@ -3507,7 +3515,7 @@ namespace {
#endif // Windows/ ANSI/ None
#if defined( CATCH_PLATFORM_LINUX ) || defined( CATCH_PLATFORM_MAC ) || defined( __GLIBC__ )
#if defined( CATCH_PLATFORM_LINUX ) || defined( CATCH_PLATFORM_MAC ) || defined( __GLIBC__ ) || defined(__FreeBSD__)
# define CATCH_INTERNAL_HAS_ISATTY
# include <unistd.h>
#endif
@@ -3981,10 +3989,10 @@ namespace Catch {
// To avoid having to handle TFE explicitly everywhere, we just
// rethrow it so that it goes back up the caller.
catch( TestFailureException& ) {
std::rethrow_exception(std::current_exception());
return "{ nested assertion failed }";
}
catch( TestSkipException& ) {
std::rethrow_exception(std::current_exception());
return "{ nested SKIP() called }";
}
catch( std::exception const& ex ) {
return ex.what();
@@ -4451,6 +4459,33 @@ namespace Detail {
namespace Catch {
namespace {
static bool needsEscape( char c ) {
return c == '"' || c == '\\' || c == '\b' || c == '\f' ||
c == '\n' || c == '\r' || c == '\t';
}
static Catch::StringRef makeEscapeStringRef( char c ) {
if ( c == '"' ) {
return "\\\""_sr;
} else if ( c == '\\' ) {
return "\\\\"_sr;
} else if ( c == '\b' ) {
return "\\b"_sr;
} else if ( c == '\f' ) {
return "\\f"_sr;
} else if ( c == '\n' ) {
return "\\n"_sr;
} else if ( c == '\r' ) {
return "\\r"_sr;
} else if ( c == '\t' ) {
return "\\t"_sr;
}
Catch::Detail::Unreachable();
}
} // namespace
void JsonUtils::indent( std::ostream& os, std::uint64_t level ) {
for ( std::uint64_t i = 0; i < level; ++i ) {
os << " ";
@@ -4560,30 +4595,19 @@ namespace Catch {
void JsonValueWriter::writeImpl( Catch::StringRef value, bool quote ) {
if ( quote ) { m_os << '"'; }
for (char c : value) {
// Escape list taken from https://www.json.org/json-en.html,
// string definition.
// Note that while forward slash _can_ be escaped, it does
// not have to be, if JSON is not further embedded somewhere
// where forward slash is meaningful.
if ( c == '"' ) {
m_os << "\\\"";
} else if ( c == '\\' ) {
m_os << "\\\\";
} else if ( c == '\b' ) {
m_os << "\\b";
} else if ( c == '\f' ) {
m_os << "\\f";
} else if ( c == '\n' ) {
m_os << "\\n";
} else if ( c == '\r' ) {
m_os << "\\r";
} else if ( c == '\t' ) {
m_os << "\\t";
} else {
m_os << c;
size_t current_start = 0;
for ( size_t i = 0; i < value.size(); ++i ) {
if ( needsEscape( value[i] ) ) {
if ( current_start < i ) {
m_os << value.substr( current_start, i - current_start );
}
m_os << makeEscapeStringRef( value[i] );
current_start = i + 1;
}
}
if ( current_start < value.size() ) {
m_os << value.substr( current_start, value.size() - current_start );
}
if ( quote ) { m_os << '"'; }
}
@@ -4780,17 +4804,18 @@ int main (int argc, char * argv[]) {
namespace Catch {
MessageInfo::MessageInfo( StringRef _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type )
MessageInfo::MessageInfo( StringRef _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type )
: macroName( _macroName ),
lineInfo( _lineInfo ),
type( _type ),
sequence( ++globalCount )
{}
// This may need protecting if threading support is added
unsigned int MessageInfo::globalCount = 0;
// Messages are owned by their individual threads, so the counter should be thread-local as well.
// Alternative consideration: atomic, so threads don't share IDs and things are easier to debug.
thread_local unsigned int MessageInfo::globalCount = 0;
} // end namespace Catch
@@ -5549,8 +5574,10 @@ namespace Catch {
std::vector<Detail::unique_ptr<std::ostringstream>> m_streams;
std::vector<std::size_t> m_unused;
std::ostringstream m_referenceStream; // Used for copy state/ flags from
Detail::Mutex m_mutex;
auto add() -> std::size_t {
Detail::LockGuard _( m_mutex );
if( m_unused.empty() ) {
m_streams.push_back( Detail::make_unique<std::ostringstream>() );
return m_streams.size()-1;
@@ -5562,9 +5589,13 @@ namespace Catch {
}
}
void release( std::size_t index ) {
m_streams[index]->copyfmt( m_referenceStream ); // Restore initial flags and other state
m_unused.push_back(index);
void release( std::size_t index, std::ostream* originalPtr ) {
assert( originalPtr );
originalPtr->copyfmt( m_referenceStream ); // Restore initial flags and other state
Detail::LockGuard _( m_mutex );
assert( originalPtr == m_streams[index].get() && "Mismatch between release index and stream ptr" );
m_unused.push_back( index );
}
};
@@ -5576,7 +5607,7 @@ namespace Catch {
ReusableStringStream::~ReusableStringStream() {
static_cast<std::ostringstream*>( m_oss )->str("");
m_oss->clear();
Singleton<StringStreams>::getMutable().release( m_index );
Singleton<StringStreams>::getMutable().release( m_index, m_oss );
}
std::string ReusableStringStream::str() const {
@@ -5743,9 +5774,6 @@ namespace Catch {
// This also implies that messages are owned by their respective
// threads, and should not be shared across different threads.
//
// For simplicity, we disallow messages in multi-threaded contexts,
// but in the future we can enable them under this logic.
//
// This implies that various pieces of metadata referring to last
// assertion result/source location/message handling, etc
// should also be thread local. For now we just use naked globals
@@ -5754,15 +5782,27 @@ namespace Catch {
// This is used for the "if" part of CHECKED_IF/CHECKED_ELSE
static thread_local bool g_lastAssertionPassed = false;
// Should we clear message scopes before sending off the messages to
// reporter? Set in `assertionPassedFastPath` to avoid doing the full
// clear there for performance reasons.
static thread_local bool g_clearMessageScopes = false;
// This is the source location for last encountered macro. It is
// used to provide the users with more precise location of error
// when an unexpected exception/fatal error happens.
static thread_local SourceLineInfo g_lastKnownLineInfo("DummyLocation", static_cast<size_t>(-1));
}
// Should we clear message scopes before sending off the messages to
// reporter? Set in `assertionPassedFastPath` to avoid doing the full
// clear there for performance reasons.
static thread_local bool g_clearMessageScopes = false;
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
// Actual messages to be provided to the reporter
static thread_local std::vector<MessageInfo> g_messages;
// Owners for the UNSCOPED_X information macro
static thread_local std::vector<ScopedMessage> g_messageScopes;
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
} // namespace Detail
RunContext::RunContext(IConfig const* _config, IEventListenerPtr&& reporter)
: m_runInfo(_config->name()),
@@ -5898,20 +5938,21 @@ namespace Catch {
Detail::g_lastAssertionPassed = true;
}
if ( Detail::g_clearMessageScopes ) {
Detail::g_messageScopes.clear();
Detail::g_clearMessageScopes = false;
}
// From here, we are touching shared state and need mutex.
Detail::LockGuard lock( m_assertionMutex );
{
if ( Detail::g_clearMessageScopes ) {
m_messageScopes.clear();
Detail::g_clearMessageScopes = false;
}
auto _ = scopedDeactivate( *m_outputRedirect );
updateTotalsFromAtomics();
m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) );
m_reporter->assertionEnded( AssertionStats( result, Detail::g_messages, m_totals ) );
}
if ( result.getResultType() != ResultWas::Warning ) {
m_messageScopes.clear();
Detail::g_messageScopes.clear();
}
// Reset working state. assertion info will be reset after
@@ -6044,8 +6085,8 @@ namespace Catch {
m_reporter->benchmarkFailed( error );
}
void RunContext::pushScopedMessage(MessageInfo const & message) {
m_messages.push_back(message);
void RunContext::pushScopedMessage( MessageInfo const& message ) {
Detail::g_messages.push_back( message );
}
void RunContext::popScopedMessage( MessageInfo const& message ) {
@@ -6054,16 +6095,16 @@ namespace Catch {
// messages than low single digits, so the optimization is tiny,
// and we would have to hand-write the loop to avoid terrible
// codegen of reverse iterators in debug mode.
m_messages.erase(
std::find_if( m_messages.begin(),
m_messages.end(),
Detail::g_messages.erase(
std::find_if( Detail::g_messages.begin(),
Detail::g_messages.end(),
[id = message.sequence]( MessageInfo const& msg ) {
return msg.sequence == id;
} ) );
}
void RunContext::emplaceUnscopedMessage( MessageBuilder&& builder ) {
m_messageScopes.emplace_back( CATCH_MOVE(builder) );
Detail::g_messageScopes.emplace_back( CATCH_MOVE(builder) );
}
std::string RunContext::getCurrentTestName() const {
@@ -6222,10 +6263,10 @@ namespace Catch {
m_testCaseTracker->close();
handleUnfinishedSections();
m_messageScopes.clear();
Detail::g_messageScopes.clear();
// TBD: At this point, m_messages should be empty. Do we want to
// assert that this is true, or keep the defensive clear call?
m_messages.clear();
Detail::g_messages.clear();
SectionStats testCaseSectionStats(CATCH_MOVE(testCaseSection), assertions, duration, missingAssertions);
m_reporter->sectionEnded(testCaseSectionStats);
@@ -7964,7 +8005,7 @@ namespace {
void hexEscapeChar(std::ostream& os, unsigned char c) {
std::ios_base::fmtflags f(os.flags());
os << "\\x"
os << "\\x"_sr
<< std::uppercase << std::hex << std::setfill('0') << std::setw(2)
<< static_cast<int>(c);
os.flags(f);
@@ -7983,95 +8024,111 @@ namespace {
void XmlEncode::encodeTo( std::ostream& os ) const {
// Apostrophe escaping not necessary if we always use " to write attributes
// (see: http://www.w3.org/TR/xml/#syntax)
size_t last_start = 0;
auto write_to = [&]( size_t idx ) {
if ( last_start < idx ) {
os << m_str.substr( last_start, idx - last_start );
}
last_start = idx + 1;
};
for( std::size_t idx = 0; idx < m_str.size(); ++ idx ) {
unsigned char c = static_cast<unsigned char>(m_str[idx]);
switch (c) {
case '<': os << "&lt;"; break;
case '&': os << "&amp;"; break;
for ( std::size_t idx = 0; idx < m_str.size(); ++idx ) {
unsigned char c = static_cast<unsigned char>( m_str[idx] );
switch ( c ) {
case '<':
write_to( idx );
os << "&lt;"_sr;
break;
case '&':
write_to( idx );
os << "&amp;"_sr;
break;
case '>':
// See: http://www.w3.org/TR/xml/#syntax
if (idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']')
os << "&gt;";
else
os << c;
if ( idx > 2 && m_str[idx - 1] == ']' && m_str[idx - 2] == ']' ) {
write_to( idx );
os << "&gt;"_sr;
}
break;
case '\"':
if (m_forWhat == ForAttributes)
os << "&quot;";
else
os << c;
if ( m_forWhat == ForAttributes ) {
write_to( idx );
os << "&quot;"_sr;
}
break;
default:
// Check for control characters and invalid utf-8
// Escape control characters in standard ascii
// see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
if (c < 0x09 || (c > 0x0D && c < 0x20) || c == 0x7F) {
hexEscapeChar(os, c);
// see
// http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
if ( c < 0x09 || ( c > 0x0D && c < 0x20 ) || c == 0x7F ) {
write_to( idx );
hexEscapeChar( os, c );
break;
}
// Plain ASCII: Write it to stream
if (c < 0x7F) {
os << c;
if ( c < 0x7F ) {
break;
}
// UTF-8 territory
// Check if the encoding is valid and if it is not, hex escape bytes.
// Important: We do not check the exact decoded values for validity, only the encoding format
// First check that this bytes is a valid lead byte:
// This means that it is not encoded as 1111 1XXX
// Check if the encoding is valid and if it is not, hex escape
// bytes. Important: We do not check the exact decoded values for
// validity, only the encoding format First check that this bytes is
// a valid lead byte: This means that it is not encoded as 1111 1XXX
// Or as 10XX XXXX
if (c < 0xC0 ||
c >= 0xF8) {
hexEscapeChar(os, c);
if ( c < 0xC0 || c >= 0xF8 ) {
write_to( idx );
hexEscapeChar( os, c );
break;
}
auto encBytes = trailingBytes(c);
// Are there enough bytes left to avoid accessing out-of-bounds memory?
if (idx + encBytes - 1 >= m_str.size()) {
hexEscapeChar(os, c);
auto encBytes = trailingBytes( c );
// Are there enough bytes left to avoid accessing out-of-bounds
// memory?
if ( idx + encBytes - 1 >= m_str.size() ) {
write_to( idx );
hexEscapeChar( os, c );
break;
}
// The header is valid, check data
// The next encBytes bytes must together be a valid utf-8
// This means: bitpattern 10XX XXXX and the extracted value is sane (ish)
// This means: bitpattern 10XX XXXX and the extracted value is sane
// (ish)
bool valid = true;
uint32_t value = headerValue(c);
for (std::size_t n = 1; n < encBytes; ++n) {
unsigned char nc = static_cast<unsigned char>(m_str[idx + n]);
valid &= ((nc & 0xC0) == 0x80);
value = (value << 6) | (nc & 0x3F);
uint32_t value = headerValue( c );
for ( std::size_t n = 1; n < encBytes; ++n ) {
unsigned char nc = static_cast<unsigned char>( m_str[idx + n] );
valid &= ( ( nc & 0xC0 ) == 0x80 );
value = ( value << 6 ) | ( nc & 0x3F );
}
if (
// Wrong bit pattern of following bytes
(!valid) ||
( !valid ) ||
// Overlong encodings
(value < 0x80) ||
(0x80 <= value && value < 0x800 && encBytes > 2) ||
(0x800 < value && value < 0x10000 && encBytes > 3) ||
( value < 0x80 ) ||
( 0x80 <= value && value < 0x800 && encBytes > 2 ) ||
( 0x800 < value && value < 0x10000 && encBytes > 3 ) ||
// Encoded value out of range
(value >= 0x110000)
) {
hexEscapeChar(os, c);
( value >= 0x110000 ) ) {
write_to( idx );
hexEscapeChar( os, c );
break;
}
// If we got here, this is in fact a valid(ish) utf-8 sequence
for (std::size_t n = 0; n < encBytes; ++n) {
os << m_str[idx + n];
}
idx += encBytes - 1;
break;
}
}
write_to( m_str.size() );
}
std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {

View File

@@ -6,8 +6,8 @@
// SPDX-License-Identifier: BSL-1.0
// Catch v3.9.0
// Generated: 2025-07-24 22:00:24.654688
// Catch v3.10.0
// Generated: 2025-08-24 16:18:04.055916
// ----------------------------------------------------------
// This file is an amalgamation of multiple different files.
// You probably shouldn't edit it directly.
@@ -958,7 +958,7 @@ namespace Detail {
}
explicit operator bool() const {
return m_ptr;
return m_ptr != nullptr;
}
friend void swap(unique_ptr& lhs, unique_ptr& rhs) {
@@ -2151,9 +2151,7 @@ namespace Catch {
auto analysis = Detail::analyse(*cfg, samples.data(), samples.data() + samples.size());
BenchmarkStats<> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
getResultCapture().benchmarkEnded(stats);
} CATCH_CATCH_ANON (TestFailureException const&) {
getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr);
} CATCH_CATCH_ALL{
} CATCH_CATCH_ALL {
getResultCapture().benchmarkFailed(translateActiveException());
// We let the exception go further up so that the
// test case is marked as failed.
@@ -2566,11 +2564,17 @@ namespace Catch {
namespace Detail {
std::string makeExceptionHappenedString();
// This function dispatches all stringification requests inside of Catch.
// Should be preferably called fully qualified, like ::Catch::Detail::stringify
template <typename T>
std::string stringify(const T& e) {
return ::Catch::StringMaker<std::remove_cv_t<std::remove_reference_t<T>>>::convert(e);
std::string stringify( const T& e ) {
CATCH_TRY {
return ::Catch::StringMaker<
std::remove_cv_t<std::remove_reference_t<T>>>::convert( e );
}
CATCH_CATCH_ALL { return makeExceptionHappenedString(); }
}
template<typename E>
@@ -3053,17 +3057,19 @@ struct ratio_string<std::milli> {
template<typename Duration>
struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
auto converted = std::chrono::system_clock::to_time_t(time_point);
const auto systemish = std::chrono::time_point_cast<
std::chrono::system_clock::duration>( time_point );
const auto as_time_t = std::chrono::system_clock::to_time_t( systemish );
#ifdef _MSC_VER
std::tm timeInfo = {};
const auto err = gmtime_s(&timeInfo, &converted);
const auto err = gmtime_s( &timeInfo, &as_time_t );
if ( err ) {
return "gmtime from provided timepoint has failed. This "
"happens e.g. with pre-1970 dates using Microsoft libc";
}
#else
std::tm* timeInfo = std::gmtime(&converted);
std::tm* timeInfo = std::gmtime( &as_time_t );
#endif
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
@@ -3966,7 +3972,7 @@ namespace Catch {
return sequence < other.sequence;
}
private:
static unsigned int globalCount;
static thread_local unsigned int globalCount;
};
} // end namespace Catch
@@ -5238,10 +5244,11 @@ namespace Detail {
*
* 3) If a type has no linkage, we also cannot capture it by reference.
* The solution is once again to capture them by value. We handle
* the common cases by using `std::is_arithmetic` as the default
* for `Catch::capture_by_value`, but that is only a some-effort
* heuristic. But as with 2), users can specialize `capture_by_value`
* for their own types as needed.
* the common cases by using `std::is_arithmetic` and `std::is_enum`
* as the default for `Catch::capture_by_value`, but that is only a
* some-effort heuristic. These combine to capture all possible bitfield
* bases, and also some trait-like types. As with 2), users can
* specialize `capture_by_value` for their own types as needed.
*
* 4) To support C++20 and make the SFINAE on our decomposing operators
* work, the SFINAE has to happen in return type, rather than in
@@ -5293,13 +5300,22 @@ namespace Catch {
using RemoveCVRef_t = std::remove_cv_t<std::remove_reference_t<T>>;
}
// Note: There is nothing that stops us from extending this,
// e.g. to `std::is_scalar`, but the more encompassing
// traits are usually also more expensive. For now we
// keep this as it used to be and it can be changed later.
// Note: This is about as much as we can currently reasonably support.
// In an ideal world, we could capture by value small trivially
// copyable types, but the actual `std::is_trivially_copyable`
// trait is a huge mess with standard-violating results on
// GCC and Clang, which are unlikely to be fixed soon due to ABI
// concerns.
// `std::is_scalar` also causes issues due to the `is_pointer`
// component, which causes ambiguity issues with (references-to)
// function pointer. If those are resolved, we still need to
// disambiguate the overload set for arrays, through explicit
// overload for references to sized arrays.
template <typename T>
struct capture_by_value
: std::integral_constant<bool, std::is_arithmetic<T>{}> {};
: std::integral_constant<bool,
std::is_arithmetic<T>::value ||
std::is_enum<T>::value> {};
#if defined( CATCH_CONFIG_CPP20_COMPARE_OVERLOADS )
template <>
@@ -6241,9 +6257,13 @@ namespace Catch {
__assume( false );
# elif defined( __GNUC__ )
__builtin_unreachable();
# endif
# endif // ^^ NDEBUG
# else // vv platform without known optimization hint
std::terminate();
# endif
# else // ^^ NDEBUG
// For non-release builds, we prefer termination on bug over UB
std::terminate();
# endif //
}
} // namespace Detail
@@ -7446,7 +7466,7 @@ namespace Catch {
#define CATCH_VERSION_MACROS_HPP_INCLUDED
#define CATCH_VERSION_MAJOR 3
#define CATCH_VERSION_MINOR 9
#define CATCH_VERSION_MINOR 10
#define CATCH_VERSION_PATCH 0
#endif // CATCH_VERSION_MACROS_HPP_INCLUDED
@@ -9500,6 +9520,17 @@ namespace Catch {
bool isDebuggerActive();
}
#if !defined( CATCH_TRAP ) && defined( __clang__ ) && defined( __has_builtin )
# if __has_builtin( __builtin_debugtrap )
# define CATCH_TRAP() __builtin_debugtrap()
# endif
#endif
#if !defined( CATCH_TRAP ) && defined( _MSC_VER )
# define CATCH_TRAP() __debugbreak()
#endif
#if !defined(CATCH_TRAP) // If we couldn't use compiler-specific impl from above, we get into platform-specific options
#ifdef CATCH_PLATFORM_MAC
#if defined(__i386__) || defined(__x86_64__)
@@ -9535,15 +9566,15 @@ namespace Catch {
#define CATCH_TRAP() raise(SIGTRAP)
#endif
#elif defined(_MSC_VER)
#define CATCH_TRAP() __debugbreak()
#elif defined(__MINGW32__)
extern "C" __declspec(dllimport) void __stdcall DebugBreak();
#define CATCH_TRAP() DebugBreak()
#endif
#endif // ^^ CATCH_TRAP is not defined yet, so we define it
#ifndef CATCH_BREAK_INTO_DEBUGGER
#ifdef CATCH_TRAP
#if !defined(CATCH_BREAK_INTO_DEBUGGER)
#if defined(CATCH_TRAP)
#define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }()
#else
#define CATCH_BREAK_INTO_DEBUGGER() []{}()
@@ -10742,9 +10773,6 @@ namespace Catch {
Totals m_totals;
Detail::AtomicCounts m_atomicAssertionCount;
IEventListenerPtr m_reporter;
std::vector<MessageInfo> m_messages;
// Owners for the UNSCOPED_X information macro
std::vector<ScopedMessage> m_messageScopes;
std::vector<SectionEndInfo> m_unfinishedSections;
std::vector<ITracker*> m_activeSections;
TrackerContext m_trackerContext;

View File

@@ -8,7 +8,7 @@
project(
'catch2',
'cpp',
version: '3.9.0', # CML version placeholder, don't delete
version: '3.10.0', # CML version placeholder, don't delete
license: 'BSL-1.0',
meson_version: '>=0.54.1',
)

View File

@@ -76,11 +76,9 @@ set(IMPL_HEADERS
${SOURCES_DIR}/internal/catch_config_counter.hpp
${SOURCES_DIR}/internal/catch_config_prefix_messages.hpp
${SOURCES_DIR}/internal/catch_config_static_analysis_support.hpp
${SOURCES_DIR}/internal/catch_config_uncaught_exceptions.hpp
${SOURCES_DIR}/internal/catch_config_wchar.hpp
${SOURCES_DIR}/internal/catch_console_colour.hpp
${SOURCES_DIR}/internal/catch_console_width.hpp
${SOURCES_DIR}/internal/catch_container_nonmembers.hpp
${SOURCES_DIR}/internal/catch_context.hpp
${SOURCES_DIR}/internal/catch_debug_console.hpp
${SOURCES_DIR}/internal/catch_debugger.hpp
@@ -99,12 +97,10 @@ set(IMPL_HEADERS
${SOURCES_DIR}/internal/catch_lazy_expr.hpp
${SOURCES_DIR}/internal/catch_leak_detector.hpp
${SOURCES_DIR}/internal/catch_list.hpp
${SOURCES_DIR}/internal/catch_logical_traits.hpp
${SOURCES_DIR}/internal/catch_message_info.hpp
${SOURCES_DIR}/internal/catch_meta.hpp
${SOURCES_DIR}/internal/catch_move_and_forward.hpp
${SOURCES_DIR}/internal/catch_noncopyable.hpp
${SOURCES_DIR}/internal/catch_optional.hpp
${SOURCES_DIR}/internal/catch_output_redirect.hpp
${SOURCES_DIR}/internal/catch_parse_numbers.hpp
${SOURCES_DIR}/internal/catch_platform.hpp
@@ -128,7 +124,6 @@ set(IMPL_HEADERS
${SOURCES_DIR}/internal/catch_stdstreams.hpp
${SOURCES_DIR}/internal/catch_stream_end_stop.hpp
${SOURCES_DIR}/internal/catch_string_manip.hpp
${SOURCES_DIR}/internal/catch_stringref.hpp
${SOURCES_DIR}/internal/catch_tag_alias_registry.hpp
${SOURCES_DIR}/internal/catch_template_test_registry.hpp
${SOURCES_DIR}/internal/catch_test_case_info_hasher.hpp
@@ -205,7 +200,6 @@ set(IMPL_SOURCES
${SOURCES_DIR}/internal/catch_startup_exception_registry.cpp
${SOURCES_DIR}/internal/catch_stdstreams.cpp
${SOURCES_DIR}/internal/catch_string_manip.cpp
${SOURCES_DIR}/internal/catch_stringref.cpp
${SOURCES_DIR}/internal/catch_tag_alias_registry.cpp
${SOURCES_DIR}/internal/catch_test_case_info_hasher.cpp
${SOURCES_DIR}/internal/catch_test_case_registry_impl.cpp
@@ -365,8 +359,8 @@ set_target_properties(Catch2 PROPERTIES
SOVERSION ${PROJECT_VERSION}
)
# require C++14
target_compile_features(Catch2 PUBLIC cxx_std_14)
# require C++17
target_compile_features(Catch2 PUBLIC cxx_std_17)
configure_file(
"${SOURCES_DIR}/catch_user_config.hpp.in"
@@ -450,7 +444,7 @@ if(CATCH_BUILD_EXAMPLES OR CATCH_BUILD_EXTRA_TESTS)
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_definitions(Catch2_buildall_interface INTERFACE CATCH_CONFIG_STATIC)
target_compile_features(Catch2_buildall_interface INTERFACE cxx_std_14)
target_compile_features(Catch2_buildall_interface INTERFACE cxx_std_17)
endif()
list(APPEND CATCH_IMPL_TARGETS Catch2 Catch2WithMain)

View File

@@ -86,9 +86,7 @@ namespace Catch {
auto analysis = Detail::analyse(*cfg, samples.data(), samples.data() + samples.size());
BenchmarkStats<> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
getResultCapture().benchmarkEnded(stats);
} CATCH_CATCH_ANON (TestFailureException const&) {
getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr);
} CATCH_CATCH_ALL{
} CATCH_CATCH_ALL {
getResultCapture().benchmarkFailed(translateActiveException());
// We let the exception go further up so that the
// test case is marked as failed.

View File

@@ -64,12 +64,12 @@ namespace Catch {
}
template <typename Fn, typename... Args>
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same<void, decltype(fn(args...))>::value> {
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same_v<void, decltype(fn(args...))>> {
deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...));
}
template <typename Fn, typename... Args>
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same<void, decltype(fn(args...))>::value> {
inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same_v<void, decltype(fn(args...))>> {
CATCH_FORWARD((fn)) (CATCH_FORWARD(args)...);
}
} // namespace Benchmark

View File

@@ -46,7 +46,7 @@ namespace Catch {
std::vector<FDuration> samples2;
samples2.reserve(samples.size());
for (auto s : samples) {
samples2.push_back( FDuration( s ) );
samples2.emplace_back( s );
}
return {

View File

@@ -21,7 +21,7 @@ namespace Catch {
namespace Benchmark {
namespace Detail {
template <typename T, typename U>
static constexpr bool is_related_v = std::is_same<std::decay_t<T>, std::decay_t<U>>::value;
static constexpr bool is_related_v = std::is_same_v<std::decay_t<T>, std::decay_t<U>>;
/// We need to reinvent std::function because every piece of code that might add overhead
/// in a measurement context needs to have consistent performance characteristics so that we

View File

@@ -57,11 +57,9 @@
#include <catch2/internal/catch_config_counter.hpp>
#include <catch2/internal/catch_config_prefix_messages.hpp>
#include <catch2/internal/catch_config_static_analysis_support.hpp>
#include <catch2/internal/catch_config_uncaught_exceptions.hpp>
#include <catch2/internal/catch_config_wchar.hpp>
#include <catch2/internal/catch_console_colour.hpp>
#include <catch2/internal/catch_console_width.hpp>
#include <catch2/internal/catch_container_nonmembers.hpp>
#include <catch2/internal/catch_context.hpp>
#include <catch2/internal/catch_debug_console.hpp>
#include <catch2/internal/catch_debugger.hpp>
@@ -80,12 +78,10 @@
#include <catch2/internal/catch_lazy_expr.hpp>
#include <catch2/internal/catch_leak_detector.hpp>
#include <catch2/internal/catch_list.hpp>
#include <catch2/internal/catch_logical_traits.hpp>
#include <catch2/internal/catch_message_info.hpp>
#include <catch2/internal/catch_meta.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_optional.hpp>
#include <catch2/internal/catch_output_redirect.hpp>
#include <catch2/internal/catch_parse_numbers.hpp>
#include <catch2/internal/catch_platform.hpp>
@@ -110,7 +106,6 @@
#include <catch2/internal/catch_stdstreams.hpp>
#include <catch2/internal/catch_stream_end_stop.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_tag_alias_registry.hpp>
#include <catch2/internal/catch_template_test_registry.hpp>
#include <catch2/internal/catch_test_case_info_hasher.hpp>

View File

@@ -29,7 +29,7 @@ namespace Catch {
Approx operator-() const;
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
Approx operator()( T const& value ) const {
Approx approx( static_cast<double>(value) );
approx.m_epsilon = m_epsilon;
@@ -38,67 +38,67 @@ namespace Catch {
return approx;
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
explicit Approx( T const& value ): Approx(static_cast<double>(value))
{}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator == ( const T& lhs, Approx const& rhs ) {
auto lhs_v = static_cast<double>(lhs);
return rhs.equalityComparisonImpl(lhs_v);
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator == ( Approx const& lhs, const T& rhs ) {
return operator==( rhs, lhs );
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator != ( T const& lhs, Approx const& rhs ) {
return !operator==( lhs, rhs );
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator != ( Approx const& lhs, T const& rhs ) {
return !operator==( rhs, lhs );
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator <= ( T const& lhs, Approx const& rhs ) {
return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator <= ( Approx const& lhs, T const& rhs ) {
return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator >= ( T const& lhs, Approx const& rhs ) {
return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
friend bool operator >= ( Approx const& lhs, T const& rhs ) {
return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
Approx& epsilon( T const& newEpsilon ) {
const auto epsilonAsDouble = static_cast<double>(newEpsilon);
setEpsilon(epsilonAsDouble);
return *this;
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
Approx& margin( T const& newMargin ) {
const auto marginAsDouble = static_cast<double>(newMargin);
setMargin(marginAsDouble);
return *this;
}
template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
template <typename T, typename = std::enable_if_t<std::is_constructible_v<double, T>>>
Approx& scale( T const& newScale ) {
m_scale = static_cast<double>(newScale);
return *this;

View File

@@ -10,16 +10,17 @@
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <string_view>
namespace Catch {
struct AssertionInfo {
// AssertionInfo() = delete;
StringRef macroName;
std::string_view macroName;
SourceLineInfo lineInfo;
StringRef capturedExpression;
std::string_view capturedExpression;
ResultDisposition::Flags resultDisposition;
};

View File

@@ -91,14 +91,14 @@ namespace Catch {
: expr;
}
StringRef AssertionResult::getMessage() const {
std::string_view AssertionResult::getMessage() const {
return m_resultData.message;
}
SourceLineInfo AssertionResult::getSourceInfo() const {
return m_info.lineInfo;
}
StringRef AssertionResult::getTestMacroName() const {
std::string_view AssertionResult::getTestMacroName() const {
return m_info.macroName;
}

View File

@@ -11,7 +11,6 @@
#include <catch2/catch_assertion_info.hpp>
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_lazy_expr.hpp>
#include <string>
@@ -46,9 +45,9 @@ namespace Catch {
std::string getExpressionInMacro() const;
bool hasExpandedExpression() const;
std::string getExpandedExpression() const;
StringRef getMessage() const;
std::string_view getMessage() const;
SourceLineInfo getSourceInfo() const;
StringRef getTestMacroName() const;
std::string_view getTestMacroName() const;
//protected:
AssertionInfo m_info;

View File

@@ -10,13 +10,13 @@
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_parse_numbers.hpp>
#include <catch2/internal/catch_stdstreams.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/internal/catch_test_spec_parser.hpp>
#include <catch2/interfaces/catch_interfaces_tag_alias_registry.hpp>
#include <catch2/internal/catch_getenv.hpp>
#include <fstream>
#include <optional>
namespace Catch {
@@ -34,7 +34,7 @@ namespace Catch {
std::string shardFilePath;
};
static Optional<bazelShardingOptions> readBazelShardingOptions() {
static std::optional<bazelShardingOptions> readBazelShardingOptions() {
const auto bazelShardIndex = Detail::getEnv( "TEST_SHARD_INDEX" );
const auto bazelShardTotal = Detail::getEnv( "TEST_TOTAL_SHARDS" );
const auto bazelShardInfoFile = Detail::getEnv( "TEST_SHARD_STATUS_FILE" );
@@ -142,7 +142,7 @@ namespace Catch {
// We do the default-output check separately, while always
// using the default output below to make the code simpler
// and avoid superfluous copies.
if ( reporterSpec.outputFile().none() ) {
if ( !reporterSpec.outputFile() ) {
CATCH_ENFORCE( !defaultOutputUsed,
"Internal error: cannot use default output for "
"multiple reporters" );
@@ -153,7 +153,7 @@ namespace Catch {
reporterSpec.name(),
reporterSpec.outputFile() ? *reporterSpec.outputFile()
: data.defaultOutputFilename,
reporterSpec.colourMode().valueOr( data.defaultColourMode ),
reporterSpec.colourMode().value_or( data.defaultColourMode ),
reporterSpec.customOptions() } );
}
}
@@ -185,7 +185,7 @@ namespace Catch {
// IConfig interface
bool Config::allowThrows() const { return !m_data.noThrow; }
StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
std::string_view Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
bool Config::warnAboutMissingAssertions() const {
return !!( m_data.warnings & WarnAbout::NoAssertions );

View File

@@ -11,8 +11,6 @@
#include <catch2/catch_test_spec.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_optional.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_random_seed_generation.hpp>
#include <catch2/internal/catch_reporter_spec_parser.hpp>
@@ -116,7 +114,7 @@ namespace Catch {
// IConfig interface
bool allowThrows() const override;
StringRef name() const override;
std::string_view name() const override;
bool includeSuccessfulResults() const override;
bool warnAboutMissingAssertions() const override;
bool warnAboutUnmatchedTestSpecs() const override;

View File

@@ -19,27 +19,26 @@ namespace Catch {
ScopedMessage::ScopedMessage( MessageBuilder&& builder ):
m_info( CATCH_MOVE(builder.m_info) ) {
m_info.message = builder.m_stream.str();
getResultCapture().pushScopedMessage( m_info );
m_messageId( builder.m_info.sequence ) {
MessageInfo info( CATCH_MOVE( builder.m_info ) );
info.message = builder.m_stream.str();
getResultCapture().pushScopedMessage( CATCH_MOVE(info) );
}
ScopedMessage::ScopedMessage( ScopedMessage&& old ) noexcept:
m_info( CATCH_MOVE( old.m_info ) ) {
m_messageId( old.m_messageId ) {
old.m_moved = true;
}
ScopedMessage::~ScopedMessage() {
if ( !m_moved ){
getResultCapture().popScopedMessage(m_info);
}
if ( !m_moved ) { getResultCapture().popScopedMessage( m_messageId ); }
}
Capturer::Capturer( StringRef macroName,
Capturer::Capturer( std::string_view macroName,
SourceLineInfo const& lineInfo,
ResultWas::OfType resultType,
StringRef names ):
std::string_view names ):
m_resultCapture( getResultCapture() ) {
auto trimmed = [&] (size_t start, size_t end) {
while (names[start] == ',' || isspace(static_cast<unsigned char>(names[start]))) {
@@ -86,7 +85,7 @@ namespace Catch {
case ',':
if (start != pos && openings.empty()) {
m_messages.emplace_back(macroName, lineInfo, resultType);
m_messages.back().message = static_cast<std::string>(trimmed(start, pos));
m_messages.back().message += trimmed(start, pos);
m_messages.back().message += " := ";
start = pos;
}
@@ -96,19 +95,20 @@ namespace Catch {
}
assert(openings.empty() && "Mismatched openings");
m_messages.emplace_back(macroName, lineInfo, resultType);
m_messages.back().message = static_cast<std::string>(trimmed(start, names.size() - 1));
m_messages.back().message += trimmed(start, names.size() - 1);
m_messages.back().message += " := ";
}
Capturer::~Capturer() {
assert( m_captured == m_messages.size() );
for ( size_t i = 0; i < m_captured; ++i )
m_resultCapture.popScopedMessage( m_messages[i] );
for (auto const& message : m_messages) {
m_resultCapture.popScopedMessage( message.sequence );
}
}
void Capturer::captureValue( size_t index, std::string const& value ) {
assert( index < m_messages.size() );
m_messages[index].message += value;
m_resultCapture.pushScopedMessage( m_messages[index] );
m_resultCapture.pushScopedMessage( CATCH_MOVE(m_messages[index]) );
m_captured++;
}

View File

@@ -36,7 +36,7 @@ namespace Catch {
};
struct MessageBuilder : MessageStream {
MessageBuilder( StringRef macroName,
MessageBuilder( std::string_view macroName,
SourceLineInfo const& lineInfo,
ResultWas::OfType type ):
m_info(macroName, lineInfo, type) {}
@@ -57,7 +57,7 @@ namespace Catch {
ScopedMessage( ScopedMessage&& old ) noexcept;
~ScopedMessage();
MessageInfo m_info;
unsigned int m_messageId;
bool m_moved = false;
};
@@ -66,7 +66,7 @@ namespace Catch {
IResultCapture& m_resultCapture;
size_t m_captured = 0;
public:
Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
Capturer( std::string_view macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, std::string_view names );
Capturer(Capturer const&) = delete;
Capturer& operator=(Capturer const&) = delete;
@@ -92,26 +92,26 @@ namespace Catch {
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
do { \
Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, std::string_view(), resultDisposition ); \
catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
catchAssertionHandler.complete(); \
} while( false )
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
Catch::Capturer varName( macroName##_catch_sr, \
Catch::Capturer varName( macroName, \
CATCH_INTERNAL_LINEINFO, \
Catch::ResultWas::Info, \
#__VA_ARGS__##_catch_sr ); \
#__VA_ARGS__ ); \
varName.captureValues( 0, __VA_ARGS__ )
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_INFO( macroName, log ) \
const Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
const Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
#if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)

View File

@@ -10,7 +10,6 @@
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/catch_totals.hpp>
#include <string>

View File

@@ -16,7 +16,6 @@
namespace Catch {
// TODO: Use C++17 `inline` variables
constexpr int UnspecifiedErrorExitCode = 1;
constexpr int NoTestsRunExitCode = 2;
constexpr int UnmatchedTestSpecExitCode = 3;

View File

@@ -14,6 +14,7 @@
#include <cassert>
#include <cctype>
#include <algorithm>
#include <string_view>
namespace Catch {
@@ -47,28 +48,28 @@ namespace Catch {
return tcp != TestCaseProperties::None;
}
TestCaseProperties parseSpecialTag( StringRef tag ) {
TestCaseProperties parseSpecialTag( std::string_view tag ) {
if( !tag.empty() && tag[0] == '.' )
return TestCaseProperties::IsHidden;
else if( tag == "!throws"_sr )
else if( tag == "!throws" )
return TestCaseProperties::Throws;
else if( tag == "!shouldfail"_sr )
else if( tag == "!shouldfail" )
return TestCaseProperties::ShouldFail;
else if( tag == "!mayfail"_sr )
else if( tag == "!mayfail" )
return TestCaseProperties::MayFail;
else if( tag == "!nonportable"_sr )
else if( tag == "!nonportable" )
return TestCaseProperties::NonPortable;
else if( tag == "!benchmark"_sr )
else if( tag == "!benchmark" )
return TestCaseProperties::Benchmark | TestCaseProperties::IsHidden;
else
return TestCaseProperties::None;
}
bool isReservedTag( StringRef tag ) {
bool isReservedTag( std::string_view tag ) {
return parseSpecialTag( tag ) == TestCaseProperties::None
&& tag.size() > 0
&& !std::isalnum( static_cast<unsigned char>(tag[0]) );
}
void enforceNotReservedTag( StringRef tag, SourceLineInfo const& _lineInfo ) {
void enforceNotReservedTag( std::string_view tag, SourceLineInfo const& _lineInfo ) {
CATCH_ENFORCE( !isReservedTag(tag),
"Tag name: [" << tag << "] is not allowed.\n"
<< "Tag names starting with non alphanumeric characters are reserved\n"
@@ -80,13 +81,13 @@ namespace Catch {
return "Anonymous test case " + std::to_string(++counter);
}
constexpr StringRef extractFilenamePart(StringRef filename) {
constexpr std::string_view extractFilenamePart(std::string_view filename) {
size_t lastDot = filename.size();
while (lastDot > 0 && filename[lastDot - 1] != '.') {
--lastDot;
}
// In theory we could have filename without any extension in it
if ( lastDot == 0 ) { return StringRef(); }
if ( lastDot == 0 ) { return std::string_view(); }
--lastDot;
size_t nameStart = lastDot;
@@ -98,7 +99,7 @@ namespace Catch {
}
// Returns the upper bound on size of extra tags ([#file]+[.])
constexpr size_t sizeOfExtraTags(StringRef filepath) {
constexpr size_t sizeOfExtraTags(std::string_view filepath) {
// [.] is 3, [#] is another 3
const size_t extras = 3 + 3;
return extractFilenamePart(filepath).size() + extras;
@@ -115,20 +116,20 @@ namespace Catch {
}
Detail::unique_ptr<TestCaseInfo>
makeTestCaseInfo(StringRef _className,
makeTestCaseInfo(std::string_view _className,
NameAndTags const& nameAndTags,
SourceLineInfo const& _lineInfo ) {
return Detail::make_unique<TestCaseInfo>(_className, nameAndTags, _lineInfo);
}
TestCaseInfo::TestCaseInfo(StringRef _className,
TestCaseInfo::TestCaseInfo(std::string_view _className,
NameAndTags const& _nameAndTags,
SourceLineInfo const& _lineInfo):
name( _nameAndTags.name.empty() ? makeDefaultName() : _nameAndTags.name ),
className( _className ),
lineInfo( _lineInfo )
{
StringRef originalTags = _nameAndTags.tags;
std::string_view originalTags = _nameAndTags.tags;
// We need to reserve enough space to store all of the tags
// (including optional hidden tag and filename tag)
auto requiredSize = originalTags.size() + sizeOfExtraTags(_lineInfo.file);
@@ -163,7 +164,7 @@ namespace Catch {
// We need to check the tag for special meanings, copy
// it over to backing storage and actually reference the
// backing storage in the saved tags
StringRef tagStr = originalTags.substr(tagStart+1, tagEnd - tagStart - 1);
std::string_view tagStr = originalTags.substr(tagStart+1, tagEnd - tagStart - 1);
CATCH_ENFORCE( !tagStr.empty(),
"Found an empty tag while registering test case '"
<< _nameAndTags.name << "' at "
@@ -190,7 +191,7 @@ namespace Catch {
// Add [.] if relevant
if (isHidden()) {
internalAppendTag("."_sr);
internalAppendTag(".");
}
// Sort and prepare tags
@@ -235,13 +236,13 @@ namespace Catch {
return ret;
}
void TestCaseInfo::internalAppendTag(StringRef tagStr) {
void TestCaseInfo::internalAppendTag(std::string_view tagStr) {
backingTags += '[';
const auto backingStart = backingTags.size();
backingTags += tagStr;
const auto backingEnd = backingTags.size();
backingTags += ']';
tags.emplace_back(StringRef(backingTags.c_str() + backingStart, backingEnd - backingStart));
tags.emplace_back(std::string_view(backingTags.c_str() + backingStart, backingEnd - backingStart));
}
bool operator<( TestCaseInfo const& lhs, TestCaseInfo const& rhs ) {

View File

@@ -11,12 +11,12 @@
#include <catch2/interfaces/catch_interfaces_test_invoker.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
#ifdef __clang__
@@ -34,10 +34,10 @@ namespace Catch {
* as "cool-tag" internally.
*/
struct Tag {
constexpr Tag(StringRef original_):
constexpr Tag(std::string_view original_):
original(original_)
{}
StringRef original;
std::string_view original;
friend bool operator< ( Tag const& lhs, Tag const& rhs );
friend bool operator==( Tag const& lhs, Tag const& rhs );
@@ -67,7 +67,7 @@ namespace Catch {
*/
struct TestCaseInfo : Detail::NonCopyable {
TestCaseInfo(StringRef _className,
TestCaseInfo(std::string_view _className,
NameAndTags const& _nameAndTags,
SourceLineInfo const& _lineInfo);
@@ -87,12 +87,12 @@ namespace Catch {
std::string tagsAsString() const;
std::string name;
StringRef className;
std::string_view className;
private:
std::string backingTags;
// Internally we copy tags to the backing storage and then add
// refs to this storage to the tags vector.
void internalAppendTag(StringRef tagString);
void internalAppendTag(std::string_view tagString);
public:
std::vector<Tag> tags;
SourceLineInfo lineInfo;
@@ -130,7 +130,7 @@ namespace Catch {
};
Detail::unique_ptr<TestCaseInfo>
makeTestCaseInfo( StringRef className,
makeTestCaseInfo( std::string_view className,
NameAndTags const& nameAndTags,
SourceLineInfo const& lineInfo );
}

View File

@@ -8,13 +8,13 @@
#ifndef CATCH_TEST_RUN_INFO_HPP_INCLUDED
#define CATCH_TEST_RUN_INFO_HPP_INCLUDED
#include <catch2/internal/catch_stringref.hpp>
#include <string_view>
namespace Catch {
struct TestRunInfo {
constexpr TestRunInfo(StringRef _name) : name(_name) {}
StringRef name;
constexpr TestRunInfo(std::string_view _name) : name(_name) {}
std::string_view name;
};
} // end namespace Catch

View File

@@ -8,10 +8,12 @@
#include <catch2/catch_tostring.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
#include <catch2/internal/catch_context.hpp>
#include <catch2/internal/catch_polyfills.hpp>
#include <iomanip>
#include <cstddef>
namespace Catch {
@@ -56,7 +58,7 @@ namespace Detail {
}
} // end unnamed namespace
std::string convertIntoString(StringRef string, bool escapeInvisibles) {
std::string convertIntoString(std::string_view string, bool escapeInvisibles) {
std::string ret;
// This is enough for the "don't escape invisibles" case, and a good
// lower bound on the "escape invisibles" case.
@@ -94,7 +96,7 @@ namespace Detail {
return ret;
}
std::string convertIntoString(StringRef string) {
std::string convertIntoString(std::string_view string) {
return convertIntoString(string, getCurrentContext().getConfig()->showInvisibles());
}
@@ -113,6 +115,13 @@ namespace Detail {
rss << std::setw(2) << static_cast<unsigned>(bytes[i]);
return rss.str();
}
std::string makeExceptionHappenedString() {
return "{ stringification failed with an exception: \"" +
translateActiveException() + "\" }";
}
} // end Detail namespace
@@ -127,11 +136,9 @@ std::string StringMaker<std::string>::convert(const std::string& str) {
return Detail::convertIntoString( str );
}
#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
std::string StringMaker<std::string_view>::convert(std::string_view str) {
return Detail::convertIntoString( StringRef( str.data(), str.size() ) );
return Detail::convertIntoString( std::string_view( str.data(), str.size() ) );
}
#endif
std::string StringMaker<char const*>::convert(char const* str) {
if (str) {
@@ -158,11 +165,9 @@ std::string StringMaker<std::wstring>::convert(const std::wstring& wstr) {
return ::Catch::Detail::stringify(s);
}
# ifdef CATCH_CONFIG_CPP17_STRING_VIEW
std::string StringMaker<std::wstring_view>::convert(std::wstring_view str) {
return StringMaker<std::wstring>::convert(std::wstring(str));
}
# endif
std::string StringMaker<wchar_t const*>::convert(wchar_t const * str) {
if (str) {
@@ -180,12 +185,9 @@ std::string StringMaker<wchar_t *>::convert(wchar_t * str) {
}
#endif
#if defined(CATCH_CONFIG_CPP17_BYTE)
#include <cstddef>
std::string StringMaker<std::byte>::convert(std::byte value) {
return ::Catch::Detail::stringify(std::to_integer<unsigned long long>(value));
}
#endif // defined(CATCH_CONFIG_CPP17_BYTE)
std::string StringMaker<int>::convert(int value) {
return ::Catch::Detail::stringify(static_cast<long long>(value));

View File

@@ -20,9 +20,7 @@
#include <catch2/internal/catch_void_type.hpp>
#include <catch2/interfaces/catch_interfaces_enum_values_registry.hpp>
#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
#include <string_view>
#endif
#ifdef _MSC_VER
#pragma warning(push)
@@ -48,14 +46,14 @@ namespace Catch {
return n;
}
constexpr StringRef unprintableString = "{?}"_sr;
constexpr std::string_view unprintableString = "{?}";
//! Encases `string in quotes, and optionally escapes invisibles
std::string convertIntoString( StringRef string, bool escapeInvisibles );
std::string convertIntoString( std::string_view string, bool escapeInvisibles );
//! Encases `string` in quotes, and escapes invisibles if user requested
//! it via CLI
std::string convertIntoString( StringRef string );
std::string convertIntoString( std::string_view string );
std::string rawMemoryToString( const void *object, std::size_t size );
@@ -78,13 +76,13 @@ namespace Catch {
template<typename T>
std::enable_if_t<
!std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value,
!std::is_enum_v<T> && !std::is_base_of_v<std::exception, T>,
std::string> convertUnstreamable( T const& ) {
return std::string(Detail::unprintableString);
}
template<typename T>
std::enable_if_t<
!std::is_enum<T>::value && std::is_base_of<std::exception, T>::value,
!std::is_enum_v<T> && std::is_base_of_v<std::exception, T>,
std::string> convertUnstreamable(T const& ex) {
return ex.what();
}
@@ -92,7 +90,7 @@ namespace Catch {
template<typename T>
std::enable_if_t<
std::is_enum<T>::value,
std::is_enum_v<T>,
std::string> convertUnstreamable( T const& value ) {
return convertUnknownEnumToString( value );
}
@@ -139,11 +137,17 @@ namespace Catch {
namespace Detail {
std::string makeExceptionHappenedString();
// This function dispatches all stringification requests inside of Catch.
// Should be preferably called fully qualified, like ::Catch::Detail::stringify
template <typename T>
std::string stringify(const T& e) {
return ::Catch::StringMaker<std::remove_cv_t<std::remove_reference_t<T>>>::convert(e);
std::string stringify( const T& e ) {
CATCH_TRY {
return ::Catch::StringMaker<
std::remove_cv_t<std::remove_reference_t<T>>>::convert( e );
}
CATCH_CATCH_ALL { return makeExceptionHappenedString(); }
}
template<typename E>
@@ -167,12 +171,10 @@ namespace Catch {
static std::string convert(const std::string& str);
};
#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
template<>
struct StringMaker<std::string_view> {
static std::string convert(std::string_view str);
};
#endif
template<>
struct StringMaker<char const *> {
@@ -189,12 +191,10 @@ namespace Catch {
static std::string convert(const std::wstring& wstr);
};
# ifdef CATCH_CONFIG_CPP17_STRING_VIEW
template<>
struct StringMaker<std::wstring_view> {
static std::string convert(std::wstring_view str);
};
# endif
template<>
struct StringMaker<wchar_t const *> {
@@ -210,7 +210,7 @@ namespace Catch {
struct StringMaker<char[SZ]> {
static std::string convert(char const* str) {
return Detail::convertIntoString(
StringRef( str, Detail::catch_strnlen( str, SZ ) ) );
std::string_view( str, Detail::catch_strnlen( str, SZ ) ) );
}
};
template<size_t SZ>
@@ -218,7 +218,7 @@ namespace Catch {
static std::string convert(signed char const* str) {
auto reinterpreted = reinterpret_cast<char const*>(str);
return Detail::convertIntoString(
StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
std::string_view(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
}
};
template<size_t SZ>
@@ -226,16 +226,14 @@ namespace Catch {
static std::string convert(unsigned char const* str) {
auto reinterpreted = reinterpret_cast<char const*>(str);
return Detail::convertIntoString(
StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
std::string_view(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
}
};
#if defined(CATCH_CONFIG_CPP17_BYTE)
template<>
struct StringMaker<std::byte> {
static std::string convert(std::byte value);
};
#endif // defined(CATCH_CONFIG_CPP17_BYTE)
template<>
struct StringMaker<int> {
static std::string convert(int value);
@@ -381,7 +379,7 @@ namespace Catch {
}
#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
#if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL)
#if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER)
#include <optional>
namespace Catch {
template<typename T>
@@ -411,7 +409,7 @@ namespace Catch {
template<
typename Tuple,
std::size_t N = 0,
bool = (N < std::tuple_size<Tuple>::value)
bool = (N < std::tuple_size_v<Tuple>)
>
struct TupleElementPrinter {
static void print(const Tuple& tuple, std::ostream& os) {
@@ -445,7 +443,7 @@ namespace Catch {
}
#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
#if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER)
#include <variant>
namespace Catch {
template<>
@@ -626,17 +624,19 @@ struct ratio_string<std::milli> {
template<typename Duration>
struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
auto converted = std::chrono::system_clock::to_time_t(time_point);
const auto systemish = std::chrono::time_point_cast<
std::chrono::system_clock::duration>( time_point );
const auto as_time_t = std::chrono::system_clock::to_time_t( systemish );
#ifdef _MSC_VER
std::tm timeInfo = {};
const auto err = gmtime_s(&timeInfo, &converted);
const auto err = gmtime_s( &timeInfo, &as_time_t );
if ( err ) {
return "gmtime from provided timepoint has failed. This "
"happens e.g. with pre-1970 dates using Microsoft libc";
}
#else
std::tm* timeInfo = std::gmtime(&converted);
std::tm* timeInfo = std::gmtime( &as_time_t );
#endif
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");

View File

@@ -60,56 +60,6 @@
#cmakedefine CATCH_CONFIG_CPP17_BYTE
#cmakedefine CATCH_CONFIG_NO_CPP17_BYTE
#if defined( CATCH_CONFIG_CPP17_BYTE ) && \
defined( CATCH_CONFIG_NO_CPP17_BYTE )
# error Cannot force CPP17_BYTE to both ON and OFF
#endif
#cmakedefine CATCH_CONFIG_CPP17_OPTIONAL
#cmakedefine CATCH_CONFIG_NO_CPP17_OPTIONAL
#if defined( CATCH_CONFIG_CPP17_OPTIONAL ) && \
defined( CATCH_CONFIG_NO_CPP17_OPTIONAL )
# error Cannot force CPP17_OPTIONAL to both ON and OFF
#endif
#cmakedefine CATCH_CONFIG_CPP17_STRING_VIEW
#cmakedefine CATCH_CONFIG_NO_CPP17_STRING_VIEW
#if defined( CATCH_CONFIG_CPP17_STRING_VIEW ) && \
defined( CATCH_CONFIG_NO_CPP17_STRING_VIEW )
# error Cannot force CPP17_STRING_VIEW to both ON and OFF
#endif
#cmakedefine CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
#cmakedefine CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS
#if defined( CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS ) && \
defined( CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS )
# error Cannot force CPP17_UNCAUGHT_EXCEPTIONS to both ON and OFF
#endif
#cmakedefine CATCH_CONFIG_CPP17_VARIANT
#cmakedefine CATCH_CONFIG_NO_CPP17_VARIANT
#if defined( CATCH_CONFIG_CPP17_VARIANT ) && \
defined( CATCH_CONFIG_NO_CPP17_VARIANT )
# error Cannot force CPP17_VARIANT to both ON and OFF
#endif
#cmakedefine CATCH_CONFIG_GLOBAL_NEXTAFTER
#cmakedefine CATCH_CONFIG_NO_GLOBAL_NEXTAFTER

View File

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

View File

@@ -9,7 +9,7 @@
#define CATCH_VERSION_MACROS_HPP_INCLUDED
#define CATCH_VERSION_MAJOR 3
#define CATCH_VERSION_MINOR 9
#define CATCH_VERSION_MINOR 10
#define CATCH_VERSION_PATCH 0
#endif // CATCH_VERSION_MACROS_HPP_INCLUDED

View File

@@ -27,11 +27,11 @@ namespace Detail {
GeneratorUntypedBase::~GeneratorUntypedBase() = default;
IGeneratorTracker* acquireGeneratorTracker(StringRef generatorName, SourceLineInfo const& lineInfo ) {
IGeneratorTracker* acquireGeneratorTracker(std::string_view generatorName, SourceLineInfo const& lineInfo ) {
return getResultCapture().acquireGeneratorTracker( generatorName, lineInfo );
}
IGeneratorTracker* createGeneratorTracker( StringRef generatorName,
IGeneratorTracker* createGeneratorTracker( std::string_view generatorName,
SourceLineInfo lineInfo,
GeneratorBasePtr&& generator ) {
return getResultCapture().createGeneratorTracker(

View File

@@ -11,7 +11,6 @@
#include <catch2/catch_tostring.hpp>
#include <catch2/interfaces/catch_interfaces_generatortracker.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_unique_name.hpp>
@@ -88,7 +87,7 @@ namespace Detail {
template<typename T>
class FixedValuesGenerator final : public IGenerator<T> {
static_assert(!std::is_same<T, bool>::value,
static_assert(!std::is_same_v<T, bool>,
"FixedValuesGenerator does not support bools because of std::vector<bool>"
"specialization, use SingleValue Generator instead.");
std::vector<T> m_values;
@@ -131,7 +130,7 @@ namespace Detail {
m_generators.emplace_back( value( CATCH_MOVE( val ) ) );
}
template <typename U>
std::enable_if_t<!std::is_same<std::decay_t<U>, T>::value>
std::enable_if_t<!std::is_same_v<std::decay_t<U>, T>>
add_generator( U&& val ) {
add_generator( T( CATCH_FORWARD( val ) ) );
}
@@ -197,14 +196,14 @@ namespace Detail {
return makeGenerators( value( T( CATCH_FORWARD( val ) ) ), CATCH_FORWARD( moreGenerators )... );
}
IGeneratorTracker* acquireGeneratorTracker( StringRef generatorName,
IGeneratorTracker* acquireGeneratorTracker( std::string_view generatorName,
SourceLineInfo const& lineInfo );
IGeneratorTracker* createGeneratorTracker( StringRef generatorName,
IGeneratorTracker* createGeneratorTracker( std::string_view generatorName,
SourceLineInfo lineInfo,
GeneratorBasePtr&& generator );
template<typename L>
auto generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> typename decltype(generatorExpression())::type {
auto generate( std::string_view generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> typename decltype(generatorExpression())::type {
using UnderlyingType = typename decltype(generatorExpression())::type;
IGeneratorTracker* tracker = acquireGeneratorTracker( generatorName, lineInfo );
@@ -225,7 +224,7 @@ namespace Detail {
} // namespace Generators
} // namespace Catch
#define CATCH_INTERNAL_GENERATOR_STRINGIZE_IMPL( ... ) #__VA_ARGS__##_catch_sr
#define CATCH_INTERNAL_GENERATOR_STRINGIZE_IMPL( ... ) #__VA_ARGS__
#define CATCH_INTERNAL_GENERATOR_STRINGIZE(...) CATCH_INTERNAL_GENERATOR_STRINGIZE_IMPL(__VA_ARGS__)
#define GENERATE( ... ) \

View File

@@ -58,8 +58,9 @@ namespace Generators {
class FilterGenerator final : public IGenerator<T> {
GeneratorWrapper<T> m_generator;
Predicate m_predicate;
static_assert(!std::is_reference_v<Predicate>, "This would most likely result in a dangling reference");
public:
template <typename P = Predicate>
template <typename P>
FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
m_generator(CATCH_MOVE(generator)),
m_predicate(CATCH_FORWARD(pred))
@@ -91,12 +92,12 @@ namespace Generators {
template <typename T, typename Predicate>
GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {
return GeneratorWrapper<T>(Catch::Detail::make_unique<FilterGenerator<T, Predicate>>(CATCH_FORWARD(pred), CATCH_MOVE(generator)));
return GeneratorWrapper<T>(Catch::Detail::make_unique<FilterGenerator<T, typename std::remove_reference<Predicate>::type>>(CATCH_FORWARD(pred), CATCH_MOVE(generator)));
}
template <typename T>
class RepeatGenerator final : public IGenerator<T> {
static_assert(!std::is_same<T, bool>::value,
static_assert(!std::is_same_v<T, bool>,
"RepeatGenerator currently does not support bools"
"because of std::vector<bool> specialization");
GeneratorWrapper<T> m_generator;

View File

@@ -83,7 +83,7 @@ public:
};
template <typename T>
std::enable_if_t<std::is_integral<T>::value, GeneratorWrapper<T>>
std::enable_if_t<std::is_integral_v<T>, GeneratorWrapper<T>>
random(T a, T b) {
return GeneratorWrapper<T>(
Catch::Detail::make_unique<RandomIntegerGenerator<T>>(a, b, Detail::getSeed())
@@ -91,7 +91,7 @@ random(T a, T b) {
}
template <typename T>
std::enable_if_t<std::is_floating_point<T>::value,
std::enable_if_t<std::is_floating_point_v<T>,
GeneratorWrapper<T>>
random(T a, T b) {
return GeneratorWrapper<T>(

View File

@@ -52,20 +52,20 @@ public:
template <typename T>
GeneratorWrapper<T> range(T const& start, T const& end, T const& step) {
static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric");
static_assert(std::is_arithmetic_v<T> && !std::is_same_v<T, bool>, "Type must be numeric");
return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end, step));
}
template <typename T>
GeneratorWrapper<T> range(T const& start, T const& end) {
static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer");
static_assert(std::is_integral_v<T> && !std::is_same_v<T, bool>, "Type must be an integer");
return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end));
}
template <typename T>
class IteratorGenerator final : public IGenerator<T> {
static_assert(!std::is_same<T, bool>::value,
static_assert(!std::is_same_v<T, bool>,
"IteratorGenerator currently does not support bools"
"because of std::vector<bool> specialization");

View File

@@ -10,7 +10,6 @@
#include <string>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/benchmark/detail/catch_benchmark_stats_fwd.hpp>
@@ -43,31 +42,31 @@ namespace Catch {
virtual ~IResultCapture();
virtual void notifyAssertionStarted( AssertionInfo const& info ) = 0;
virtual bool sectionStarted( StringRef sectionName,
virtual bool sectionStarted( std::string_view sectionName,
SourceLineInfo const& sectionLineInfo,
Counts& assertions ) = 0;
virtual void sectionEnded( SectionEndInfo&& endInfo ) = 0;
virtual void sectionEndedEarly( SectionEndInfo&& endInfo ) = 0;
virtual IGeneratorTracker*
acquireGeneratorTracker( StringRef generatorName,
acquireGeneratorTracker( std::string_view generatorName,
SourceLineInfo const& lineInfo ) = 0;
virtual IGeneratorTracker*
createGeneratorTracker( StringRef generatorName,
createGeneratorTracker( std::string_view generatorName,
SourceLineInfo lineInfo,
Generators::GeneratorBasePtr&& generator ) = 0;
virtual void benchmarkPreparing( StringRef name ) = 0;
virtual void benchmarkPreparing( std::string_view name ) = 0;
virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
virtual void benchmarkFailed( StringRef error ) = 0;
virtual void benchmarkFailed( std::string_view error ) = 0;
virtual void pushScopedMessage( MessageInfo const& message ) = 0;
virtual void popScopedMessage( MessageInfo const& message ) = 0;
virtual void pushScopedMessage( MessageInfo&& message ) = 0;
virtual void popScopedMessage( unsigned int messageId ) = 0;
virtual void emplaceUnscopedMessage( MessageBuilder&& builder ) = 0;
virtual void handleFatalErrorCondition( StringRef message ) = 0;
virtual void handleFatalErrorCondition( std::string_view message ) = 0;
virtual void handleExpr
( AssertionInfo const& info,

View File

@@ -9,7 +9,6 @@
#define CATCH_INTERFACES_CONFIG_HPP_INCLUDED
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <chrono>
#include <string>
@@ -66,7 +65,7 @@ namespace Catch {
virtual ~IConfig();
virtual bool allowThrows() const = 0;
virtual StringRef name() const = 0;
virtual std::string_view name() const = 0;
virtual bool includeSuccessfulResults() const = 0;
virtual bool shouldDebugBreak() const = 0;
virtual bool warnAboutMissingAssertions() const = 0;

View File

@@ -8,20 +8,19 @@
#ifndef CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
#define CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
#include <catch2/internal/catch_stringref.hpp>
#include <string_view>
#include <vector>
namespace Catch {
namespace Detail {
struct EnumInfo {
StringRef m_name;
std::vector<std::pair<int, StringRef>> m_values;
std::string_view m_name;
std::vector<std::pair<int, std::string_view>> m_values;
~EnumInfo();
StringRef lookup( int value ) const;
std::string_view lookup( int value ) const;
};
} // namespace Detail
@@ -29,10 +28,10 @@ namespace Catch {
public:
virtual ~IMutableEnumValuesRegistry(); // = default;
virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
virtual Detail::EnumInfo const& registerEnum( std::string_view enumName, std::string_view allEnums, std::vector<int> const& values ) = 0;
template<typename E>
Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
Detail::EnumInfo const& registerEnum( std::string_view enumName, std::string_view allEnums, std::initializer_list<E> values ) {
static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int");
std::vector<int> intValues;
intValues.reserve( values.size() );

View File

@@ -21,7 +21,7 @@ namespace Catch {
return ret;
}
StringRef GeneratorUntypedBase::currentElementAsString() const {
std::string_view GeneratorUntypedBase::currentElementAsString() const {
if ( m_stringReprCache.empty() ) {
m_stringReprCache = stringifyImpl();
}

View File

@@ -9,7 +9,6 @@
#define CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <string>
@@ -71,7 +70,7 @@ namespace Catch {
* is destructed, or it moves onto the next element, whichever
* comes first.
*/
StringRef currentElementAsString() const;
std::string_view currentElementAsString() const;
};
using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>;

View File

@@ -13,7 +13,6 @@
#include <catch2/catch_totals.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/internal/catch_message_info.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/benchmark/detail/catch_benchmark_stats.hpp>
@@ -154,9 +153,9 @@ namespace Catch {
}
//! Called when no test cases match provided test spec
virtual void noMatchingTestCases( StringRef unmatchedSpec ) = 0;
virtual void noMatchingTestCases( std::string_view unmatchedSpec ) = 0;
//! Called for all invalid test specs from the cli
virtual void reportInvalidTestSpec( StringRef invalidArgument ) = 0;
virtual void reportInvalidTestSpec( std::string_view invalidArgument ) = 0;
/**
* Called once in a testing run before tests are started
@@ -173,13 +172,13 @@ namespace Catch {
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
//! Called when user-code is being probed before the actual benchmark runs
virtual void benchmarkPreparing( StringRef benchmarkName ) = 0;
virtual void benchmarkPreparing( std::string_view benchmarkName ) = 0;
//! Called after probe but before the user-code is being benchmarked
virtual void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) = 0;
//! Called with the benchmark results if benchmark successfully finishes
virtual void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) = 0;
//! Called if running the benchmarks fails for any reason
virtual void benchmarkFailed( StringRef benchmarkName ) = 0;
virtual void benchmarkFailed( std::string_view benchmarkName ) = 0;
//! Called before assertion success/failure is evaluated
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
@@ -209,7 +208,7 @@ namespace Catch {
virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
//! Called if a fatal error (signal/structured exception) occurred
virtual void fatalErrorEncountered( StringRef error ) = 0;
virtual void fatalErrorEncountered( std::string_view error ) = 0;
//! Writes out information about provided reporters using reporter-specific format
virtual void listReporters(std::vector<ReporterDescription> const& descriptions) = 0;

View File

@@ -9,7 +9,6 @@
#define CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <string>
@@ -36,7 +35,7 @@ namespace Catch {
virtual ~EventListenerFactory(); // = default
virtual IEventListenerPtr create( IConfig const* config ) const = 0;
//! Return a meaningful name for the listener, e.g. its type name
virtual StringRef getName() const = 0;
virtual std::string_view getName() const = 0;
//! Return listener's description if available
virtual std::string getDescription() const = 0;
};

View File

@@ -15,9 +15,9 @@
namespace Catch {
AssertionHandler::AssertionHandler
( StringRef macroName,
( std::string_view macroName,
SourceLineInfo const& lineInfo,
StringRef capturedExpression,
std::string_view capturedExpression,
ResultDisposition::Flags resultDisposition )
: m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition },
m_resultCapture( getResultCapture() )

View File

@@ -30,9 +30,9 @@ namespace Catch {
public:
AssertionHandler
( StringRef macroName,
( std::string_view macroName,
SourceLineInfo const& lineInfo,
StringRef capturedExpression,
std::string_view capturedExpression,
ResultDisposition::Flags resultDisposition );
~AssertionHandler() {
if ( !m_completed ) {

View File

@@ -14,8 +14,8 @@
namespace Catch {
namespace Detail {
bool CaseInsensitiveLess::operator()( StringRef lhs,
StringRef rhs ) const {
bool CaseInsensitiveLess::operator()( std::string_view lhs,
std::string_view rhs ) const {
return std::lexicographical_compare(
lhs.begin(), lhs.end(),
rhs.begin(), rhs.end(),
@@ -23,8 +23,8 @@ namespace Catch {
}
bool
CaseInsensitiveEqualTo::operator()( StringRef lhs,
StringRef rhs ) const {
CaseInsensitiveEqualTo::operator()( std::string_view lhs,
std::string_view rhs ) const {
return std::equal(
lhs.begin(), lhs.end(),
rhs.begin(), rhs.end(),

View File

@@ -8,20 +8,20 @@
#ifndef CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
#define CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
#include <catch2/internal/catch_stringref.hpp>
#include <string_view>
namespace Catch {
namespace Detail {
//! Provides case-insensitive `op<` semantics when called
struct CaseInsensitiveLess {
bool operator()( StringRef lhs,
StringRef rhs ) const;
bool operator()( std::string_view lhs,
std::string_view rhs ) const;
};
//! Provides case-insensitive `op==` semantics when called
struct CaseInsensitiveEqualTo {
bool operator()( StringRef lhs,
StringRef rhs ) const;
bool operator()( std::string_view lhs,
std::string_view rhs ) const;
};
} // namespace Detail

View File

@@ -25,7 +25,7 @@ namespace {
;
}
Catch::StringRef normaliseOpt( Catch::StringRef optName ) {
std::string_view normaliseOpt( std::string_view optName ) {
if ( optName[0] == '-'
#if defined(CATCH_PLATFORM_WINDOWS)
|| optName[0] == '/'
@@ -37,7 +37,7 @@ namespace {
return optName;
}
static size_t find_first_separator(Catch::StringRef sr) {
static size_t find_first_separator(std::string_view sr) {
auto is_separator = []( char c ) {
return c == ' ' || c == ':' || c == '=';
};
@@ -47,7 +47,7 @@ namespace {
++pos;
}
return Catch::StringRef::npos;
return std::string_view::npos;
}
} // namespace
@@ -65,10 +65,10 @@ namespace Catch {
}
if ( it != itEnd ) {
StringRef next = *it;
std::string_view next = *it;
if ( isOptPrefix( next[0] ) ) {
auto delimiterPos = find_first_separator(next);
if ( delimiterPos != StringRef::npos ) {
if ( delimiterPos != std::string_view::npos ) {
m_tokenBuffer.push_back(
{ TokenType::Option,
next.substr( 0, delimiterPos ) } );
@@ -205,7 +205,7 @@ namespace Catch {
return { oss.str(), m_description };
}
bool Opt::isMatch(StringRef optToken) const {
bool Opt::isMatch(std::string_view optToken) const {
auto normalisedToken = normaliseOpt(optToken);
for (auto const& name : m_optNames) {
if (normaliseOpt(name) == normalisedToken)
@@ -243,12 +243,12 @@ namespace Catch {
if (!tokens)
return Detail::InternalParseResult::runtimeError(
"Expected argument following " +
token.token);
std::string(token.token));
auto const& argToken = *tokens;
if (argToken.type != Detail::TokenType::Argument)
return Detail::InternalParseResult::runtimeError(
"Expected argument following " +
token.token);
std::string(token.token));
const auto result = valueRef->setValue(static_cast<std::string>(argToken.token));
if (!result)
return Detail::InternalParseResult(result);
@@ -436,7 +436,7 @@ namespace Catch {
if ( !tokenParsed )
return Detail::InternalParseResult::runtimeError(
"Unrecognised token: " +
result.value().remainingTokens()->token );
std::string(result.value().remainingTokens()->token) );
}
// !TBD Check missing required options
return result;
@@ -445,7 +445,7 @@ namespace Catch {
Args::Args(int argc, char const* const* argv) :
m_exeName(argv[0]), m_args(argv + 1, argv + argc) {}
Args::Args(std::initializer_list<StringRef> args) :
Args::Args(std::initializer_list<std::string_view> args) :
m_exeName(*args.begin()),
m_args(args.begin() + 1, args.end()) {}

View File

@@ -20,16 +20,8 @@
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#ifndef CLARA_CONFIG_OPTIONAL_TYPE
# ifdef __has_include
# if __has_include( <optional>) && __cplusplus >= 201703L
# include <optional>
# define CLARA_CONFIG_OPTIONAL_TYPE std::optional
# endif
# endif
#endif
#include <optional>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_void_type.hpp>
@@ -100,13 +92,13 @@ namespace Catch {
enum class TokenType { Option, Argument };
struct Token {
TokenType type;
StringRef token;
std::string_view token;
};
// Abstracts iterators into args as a stream of tokens, with option
// arguments uniformly handled
class TokenStream {
using Iterator = std::vector<StringRef>::const_iterator;
using Iterator = std::vector<std::string_view>::const_iterator;
Iterator it;
Iterator itEnd;
std::vector<Token> m_tokenBuffer;
@@ -309,7 +301,7 @@ namespace Catch {
struct HelpColumns {
std::string left;
StringRef descriptions;
std::string_view descriptions;
};
template <typename T>
@@ -328,10 +320,9 @@ namespace Catch {
std::string& target );
ParserResult convertInto( std::string const& source, bool& target );
#ifdef CLARA_CONFIG_OPTIONAL_TYPE
template <typename T>
auto convertInto( std::string const& source,
CLARA_CONFIG_OPTIONAL_TYPE<T>& target )
std::optional<T>& target )
-> ParserResult {
T temp;
auto result = convertInto( source, temp );
@@ -339,7 +330,6 @@ namespace Catch {
target = CATCH_MOVE( temp );
return result;
}
#endif // CLARA_CONFIG_OPTIONAL_TYPE
struct BoundRef : Catch::Detail::NonCopyable {
virtual ~BoundRef() = default;
@@ -393,7 +383,7 @@ namespace Catch {
template <typename ReturnType> struct LambdaInvoker {
static_assert(
std::is_same<ReturnType, ParserResult>::value,
std::is_same_v<ReturnType, ParserResult>,
"Lambda must return void or clara::ParserResult" );
template <typename L, typename ArgType>
@@ -449,8 +439,8 @@ namespace Catch {
UnaryLambdaTraits<L>::isValid,
"Supplied lambda must take exactly one argument" );
static_assert(
std::is_same<typename UnaryLambdaTraits<L>::ArgType,
bool>::value,
std::is_same_v<typename UnaryLambdaTraits<L>::ArgType,
bool>,
"flags must be boolean" );
explicit BoundFlagLambda( L const& lambda ):
@@ -489,8 +479,8 @@ namespace Catch {
protected:
Optionality m_optionality = Optionality::Optional;
std::shared_ptr<BoundRef> m_ref;
StringRef m_hint;
StringRef m_description;
std::string_view m_hint;
std::string_view m_description;
explicit ParserRefImpl( std::shared_ptr<BoundRef> const& ref ):
m_ref( ref ) {}
@@ -499,29 +489,29 @@ namespace Catch {
template <typename LambdaT>
ParserRefImpl( accept_many_t,
LambdaT const& ref,
StringRef hint ):
std::string_view hint ):
m_ref( std::make_shared<BoundManyLambda<LambdaT>>( ref ) ),
m_hint( hint ) {}
template <typename T,
typename = typename std::enable_if_t<
!Detail::is_unary_function_v<T>>>
ParserRefImpl( T& ref, StringRef hint ):
ParserRefImpl( T& ref, std::string_view hint ):
m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
m_hint( hint ) {}
template <typename LambdaT,
typename = typename std::enable_if_t<
Detail::is_unary_function_v<LambdaT>>>
ParserRefImpl( LambdaT const& ref, StringRef hint ):
ParserRefImpl( LambdaT const& ref, std::string_view hint ):
m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
m_hint( hint ) {}
DerivedT& operator()( StringRef description ) & {
DerivedT& operator()( std::string_view description ) & {
m_description = description;
return static_cast<DerivedT&>( *this );
}
DerivedT&& operator()( StringRef description ) && {
DerivedT&& operator()( std::string_view description ) && {
m_description = description;
return static_cast<DerivedT&&>( *this );
}
@@ -547,7 +537,7 @@ namespace Catch {
return 1;
}
StringRef hint() const { return m_hint; }
std::string_view hint() const { return m_hint; }
};
} // namespace detail
@@ -567,7 +557,7 @@ namespace Catch {
// A parser for options
class Opt : public Detail::ParserRefImpl<Opt> {
protected:
std::vector<StringRef> m_optNames;
std::vector<std::string_view> m_optNames;
public:
template <typename LambdaT>
@@ -580,31 +570,31 @@ namespace Catch {
template <typename LambdaT,
typename = typename std::enable_if_t<
Detail::is_unary_function_v<LambdaT>>>
Opt( LambdaT const& ref, StringRef hint ):
Opt( LambdaT const& ref, std::string_view hint ):
ParserRefImpl( ref, hint ) {}
template <typename LambdaT>
Opt( accept_many_t, LambdaT const& ref, StringRef hint ):
Opt( accept_many_t, LambdaT const& ref, std::string_view hint ):
ParserRefImpl( accept_many, ref, hint ) {}
template <typename T,
typename = typename std::enable_if_t<
!Detail::is_unary_function_v<T>>>
Opt( T& ref, StringRef hint ):
Opt( T& ref, std::string_view hint ):
ParserRefImpl( ref, hint ) {}
Opt& operator[]( StringRef optName ) & {
Opt& operator[]( std::string_view optName ) & {
m_optNames.push_back(optName);
return *this;
}
Opt&& operator[]( StringRef optName ) && {
Opt&& operator[]( std::string_view optName ) && {
m_optNames.push_back( optName );
return CATCH_MOVE(*this);
}
Detail::HelpColumns getHelpColumns() const;
bool isMatch(StringRef optToken) const;
bool isMatch(std::string_view optToken) const;
using ParserBase::parse;
@@ -705,15 +695,15 @@ namespace Catch {
*/
class Args {
friend Detail::TokenStream;
StringRef m_exeName;
std::vector<StringRef> m_args;
std::string_view m_exeName;
std::vector<std::string_view> m_args;
public:
Args(int argc, char const* const* argv);
// Helper constructor for testing
Args(std::initializer_list<StringRef> args);
Args(std::initializer_list<std::string_view> args);
StringRef exeName() const { return m_exeName; }
std::string_view exeName() const { return m_exeName; }
};

View File

@@ -88,7 +88,7 @@ namespace Catch {
return ParserResult::ok( ParseResultType::Matched );
};
auto const setDefaultColourMode = [&]( std::string const& colourMode ) {
Optional<ColourMode> maybeMode = Catch::Detail::stringToColourMode(toLower( colourMode ));
std::optional<ColourMode> maybeMode = Catch::Detail::stringToColourMode(toLower( colourMode ));
if ( !maybeMode ) {
return ParserResult::runtimeError(
"colour mode must be one of: default, ansi, win32, "
@@ -135,7 +135,7 @@ namespace Catch {
return ParserResult::runtimeError( "Received empty reporter spec." );
}
Optional<ReporterSpec> parsed =
std::optional<ReporterSpec> parsed =
parseReporterSpec( userReporterSpec );
if ( !parsed ) {
return ParserResult::runtimeError(
@@ -156,7 +156,7 @@ namespace Catch {
}
const bool hadOutputFile = reporterSpec.outputFile().some();
const bool hadOutputFile = reporterSpec.outputFile().has_value();
config.reporterSpecifications.push_back( CATCH_MOVE( *parsed ) );
// It would be enough to check this only once at the very end, but
// there is not a place where we could call this check, so do it
@@ -165,7 +165,7 @@ namespace Catch {
if (!hadOutputFile) {
int n_reporters_without_file = 0;
for (auto const& spec : config.reporterSpecifications) {
if (spec.outputFile().none()) {
if (!spec.outputFile()) {
n_reporters_without_file++;
}
}

View File

@@ -29,10 +29,6 @@
#ifdef __cplusplus
# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
# define CATCH_CPP17_OR_GREATER
# endif
# if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
# define CATCH_CPP20_OR_GREATER
# endif
@@ -198,8 +194,7 @@
# define _BSD_SOURCE
// some versions of cygwin (most) do not support std::to_string. Use the libstd check.
// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
&& !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
# if !(defined(_GLIBCXX_USE_C99) && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
@@ -220,13 +215,17 @@
# endif
// Universal Windows platform does not support SEH
// Or console colours (or console at all...)
# if defined(CATCH_PLATFORM_WINDOWS_UWP)
# define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
# else
# if !defined(CATCH_PLATFORM_WINDOWS_UWP)
# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
# endif
// Only some Windows platform families support the console
# if defined(WINAPI_FAMILY_PARTITION)
# if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM)
# define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
# endif
# endif
// MSVC traditional preprocessor needs some workaround for __VA_ARGS__
// _MSVC_TRADITIONAL == 0 means new conformant preprocessor
// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor
@@ -271,43 +270,6 @@
#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER
#endif
// Various stdlib support checks that require __has_include
#if defined(__has_include)
// Check if string_view is available and usable
#if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
# define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
#endif
// Check if optional is available and usable
# if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
# define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
# endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
// Check if byte is available and usable
# if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
# include <cstddef>
# if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0)
# define CATCH_INTERNAL_CONFIG_CPP17_BYTE
# endif
# endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
// Check if variant is available and usable
# if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
# if defined(__clang__) && (__clang_major__ < 8)
// work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
// fix should be in clang 8, workaround in libstdc++ 8.2
# include <ciso646>
# if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
# define CATCH_CONFIG_NO_CPP17_VARIANT
# else
# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
# endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
# else
# define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
# endif // defined(__clang__) && (__clang_major__ < 8)
# endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
#endif // defined(__has_include)
#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH)
# define CATCH_CONFIG_WINDOWS_SEH
@@ -325,22 +287,6 @@
# define CATCH_CONFIG_CPP11_TO_STRING
#endif
#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL)
# define CATCH_CONFIG_CPP17_OPTIONAL
#endif
#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
# define CATCH_CONFIG_CPP17_STRING_VIEW
#endif
#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
# define CATCH_CONFIG_CPP17_VARIANT
#endif
#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE)
# define CATCH_CONFIG_CPP17_BYTE
#endif
#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE

View File

@@ -1,46 +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
/** \file
* Wrapper for UNCAUGHT_EXCEPTIONS configuration option
*
* For some functionality, Catch2 requires to know whether there is
* an active exception. Because `std::uncaught_exception` is deprecated
* in C++17, we want to use `std::uncaught_exceptions` if possible.
*/
#ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
#define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
#include <catch2/catch_user_config.hpp>
#if defined(_MSC_VER)
# if _MSC_VER >= 1900 // Visual Studio 2015 or newer
# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
# endif
#endif
#include <exception>
#if defined(__cpp_lib_uncaught_exceptions) \
&& !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
#endif // __cpp_lib_uncaught_exceptions
#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \
&& !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \
&& !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
#endif
#endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED

View File

@@ -161,7 +161,7 @@ namespace {
#endif // Windows/ ANSI/ None
#if defined( CATCH_PLATFORM_LINUX ) || defined( CATCH_PLATFORM_MAC ) || defined( __GLIBC__ )
#if defined( CATCH_PLATFORM_LINUX ) || defined( CATCH_PLATFORM_MAC ) || defined( __GLIBC__ ) || defined(__FreeBSD__)
# define CATCH_INTERNAL_HAS_ISATTY
# include <unistd.h>
#endif

View File

@@ -1,73 +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
#ifndef CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
#define CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <cstddef>
#include <initializer_list>
// We want a simple polyfill over `std::empty`, `std::size` and so on
// for C++14 or C++ libraries with incomplete support.
// We also have to handle that MSVC std lib will happily provide these
// under older standards.
#if defined(CATCH_CPP17_OR_GREATER) || defined(_MSC_VER)
// We are already using this header either way, so there shouldn't
// be much additional overhead in including it to get the feature
// test macros
#include <string>
# if !defined(__cpp_lib_nonmember_container_access)
# define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
# endif
#else
#define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
#endif
namespace Catch {
namespace Detail {
#if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
template <typename Container>
constexpr auto empty(Container const& cont) -> decltype(cont.empty()) {
return cont.empty();
}
template <typename T, std::size_t N>
constexpr bool empty(const T (&)[N]) noexcept {
// GCC < 7 does not support the const T(&)[] parameter syntax
// so we have to ignore the length explicitly
(void)N;
return false;
}
template <typename T>
constexpr bool empty(std::initializer_list<T> list) noexcept {
return list.size() > 0;
}
template <typename Container>
constexpr auto size(Container const& cont) -> decltype(cont.size()) {
return cont.size();
}
template <typename T, std::size_t N>
constexpr std::size_t size(const T(&)[N]) noexcept {
return N;
}
#endif // CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
} // end namespace Detail
} // end namespace Catch
#endif // CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED

View File

@@ -14,6 +14,17 @@ namespace Catch {
bool isDebuggerActive();
}
#if !defined( CATCH_TRAP ) && defined( __clang__ ) && defined( __has_builtin )
# if __has_builtin( __builtin_debugtrap )
# define CATCH_TRAP() __builtin_debugtrap()
# endif
#endif
#if !defined( CATCH_TRAP ) && defined( _MSC_VER )
# define CATCH_TRAP() __debugbreak()
#endif
#if !defined(CATCH_TRAP) // If we couldn't use compiler-specific impl from above, we get into platform-specific options
#ifdef CATCH_PLATFORM_MAC
#if defined(__i386__) || defined(__x86_64__)
@@ -49,15 +60,15 @@ namespace Catch {
#define CATCH_TRAP() raise(SIGTRAP)
#endif
#elif defined(_MSC_VER)
#define CATCH_TRAP() __debugbreak()
#elif defined(__MINGW32__)
extern "C" __declspec(dllimport) void __stdcall DebugBreak();
#define CATCH_TRAP() DebugBreak()
#endif
#endif // ^^ CATCH_TRAP is not defined yet, so we define it
#ifndef CATCH_BREAK_INTO_DEBUGGER
#ifdef CATCH_TRAP
#if !defined(CATCH_BREAK_INTO_DEBUGGER)
#if defined(CATCH_TRAP)
#define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }()
#else
#define CATCH_BREAK_INTO_DEBUGGER() []{}()

View File

@@ -17,7 +17,7 @@ namespace Catch {
os << "Some class derived from ITransientExpression without overriding streamReconstructedExpression";
}
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) {
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, std::string_view op, std::string const& rhs ) {
if( lhs.size() + rhs.size() < 40 &&
lhs.find('\n') == std::string::npos &&
rhs.find('\n') == std::string::npos )

View File

@@ -9,10 +9,8 @@
#define CATCH_DECOMPOSER_HPP_INCLUDED
#include <catch2/catch_tostring.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_compare_traits.hpp>
#include <catch2/internal/catch_test_failure_exception.hpp>
#include <catch2/internal/catch_logical_traits.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <type_traits>
@@ -78,10 +76,11 @@
*
* 3) If a type has no linkage, we also cannot capture it by reference.
* The solution is once again to capture them by value. We handle
* the common cases by using `std::is_arithmetic` as the default
* for `Catch::capture_by_value`, but that is only a some-effort
* heuristic. But as with 2), users can specialize `capture_by_value`
* for their own types as needed.
* the common cases by using `std::is_arithmetic` and `std::is_enum`
* as the default for `Catch::capture_by_value`, but that is only a
* some-effort heuristic. These combine to capture all possible bitfield
* bases, and also some trait-like types. As with 2), users can
* specialize `capture_by_value` for their own types as needed.
*
* 4) To support C++20 and make the SFINAE on our decomposing operators
* work, the SFINAE has to happen in return type, rather than in
@@ -128,18 +127,27 @@
namespace Catch {
namespace Detail {
// This was added in C++20, but we require only C++14 for now.
// This was added in C++20, but we require only C++17 for now.
template <typename T>
using RemoveCVRef_t = std::remove_cv_t<std::remove_reference_t<T>>;
}
// Note: There is nothing that stops us from extending this,
// e.g. to `std::is_scalar`, but the more encompassing
// traits are usually also more expensive. For now we
// keep this as it used to be and it can be changed later.
// Note: This is about as much as we can currently reasonably support.
// In an ideal world, we could capture by value small trivially
// copyable types, but the actual `std::is_trivially_copyable`
// trait is a huge mess with standard-violating results on
// GCC and Clang, which are unlikely to be fixed soon due to ABI
// concerns.
// `std::is_scalar` also causes issues due to the `is_pointer`
// component, which causes ambiguity issues with (references-to)
// function pointer. If those are resolved, we still need to
// disambiguate the overload set for arrays, through explicit
// overload for references to sized arrays.
template <typename T>
struct capture_by_value
: std::integral_constant<bool, std::is_arithmetic<T>{}> {};
: std::integral_constant<bool,
std::is_arithmetic_v<T> ||
std::is_enum_v<T>> {};
#if defined( CATCH_CONFIG_CPP20_COMPARE_OVERLOADS )
template <>
@@ -180,12 +188,12 @@ namespace Catch {
}
};
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, std::string_view op, std::string const& rhs );
template<typename LhsT, typename RhsT>
class BinaryExpr : public ITransientExpression {
LhsT m_lhs;
StringRef m_op;
std::string_view m_op;
RhsT m_rhs;
void streamReconstructedExpression( std::ostream &os ) const override {
@@ -194,7 +202,7 @@ namespace Catch {
}
public:
constexpr BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs )
constexpr BinaryExpr( bool comparisonResult, LhsT lhs, std::string_view op, RhsT rhs )
: ITransientExpression{ true, comparisonResult },
m_lhs( lhs ),
m_op( op ),
@@ -284,48 +292,48 @@ namespace Catch {
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \
-> std::enable_if_t< \
Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
Detail::negation<capture_by_value< \
Detail::RemoveCVRef_t<RhsT>>>>::value, \
std::conjunction_v<Detail::is_##id##_comparable<LhsT, RhsT>, \
std::negation<capture_by_value< \
Detail::RemoveCVRef_t<RhsT>>>>, \
BinaryExpr<LhsT, RhsT const&>> { \
return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op, rhs }; \
} \
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
-> std::enable_if_t< \
Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
capture_by_value<RhsT>>::value, \
std::conjunction_v<Detail::is_##id##_comparable<LhsT, RhsT>, \
capture_by_value<RhsT>>, \
BinaryExpr<LhsT, RhsT>> { \
return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op, rhs }; \
} \
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
-> std::enable_if_t< \
Detail::conjunction< \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
std::conjunction_v< \
std::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
Detail::is_eq_0_comparable<LhsT>, \
/* We allow long because we want `ptr op NULL` to be accepted */ \
Detail::disjunction<std::is_same<RhsT, int>, \
std::is_same<RhsT, long>>>::value, \
std::disjunction<std::is_same<RhsT, int>, \
std::is_same<RhsT, long>>>, \
BinaryExpr<LhsT, RhsT>> { \
if ( rhs != 0 ) { throw_test_failure_exception(); } \
return { \
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op, rhs }; \
} \
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
-> std::enable_if_t< \
Detail::conjunction< \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
std::conjunction_v< \
std::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
Detail::is_eq_0_comparable<RhsT>, \
/* We allow long because we want `ptr op NULL` to be accepted */ \
Detail::disjunction<std::is_same<LhsT, int>, \
std::is_same<LhsT, long>>>::value, \
std::disjunction<std::is_same<LhsT, int>, \
std::is_same<LhsT, long>>>, \
BinaryExpr<LhsT, RhsT>> { \
if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op, rhs }; \
}
CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == )
@@ -338,44 +346,44 @@ namespace Catch {
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \
-> std::enable_if_t< \
Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
Detail::negation<capture_by_value< \
Detail::RemoveCVRef_t<RhsT>>>>::value, \
std::conjunction_v<Detail::is_##id##_comparable<LhsT, RhsT>, \
std::negation<capture_by_value< \
Detail::RemoveCVRef_t<RhsT>>>>, \
BinaryExpr<LhsT, RhsT const&>> { \
return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op, rhs }; \
} \
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
-> std::enable_if_t< \
Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
capture_by_value<RhsT>>::value, \
std::conjunction_v<Detail::is_##id##_comparable<LhsT, RhsT>, \
capture_by_value<RhsT>> , \
BinaryExpr<LhsT, RhsT>> { \
return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op, rhs }; \
} \
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
-> std::enable_if_t< \
Detail::conjunction< \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
std::conjunction_v< \
std::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
Detail::is_##id##_0_comparable<LhsT>, \
std::is_same<RhsT, int>>::value, \
std::is_same<RhsT, int>>, \
BinaryExpr<LhsT, RhsT>> { \
if ( rhs != 0 ) { throw_test_failure_exception(); } \
return { \
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op, rhs }; \
} \
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
-> std::enable_if_t< \
Detail::conjunction< \
Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
std::conjunction_v< \
std::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
Detail::is_##id##_0_comparable<RhsT>, \
std::is_same<LhsT, int>>::value, \
std::is_same<LhsT, int>>, \
BinaryExpr<LhsT, RhsT>> { \
if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op, rhs }; \
}
CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( lt, < )
@@ -393,14 +401,14 @@ namespace Catch {
!capture_by_value<Detail::RemoveCVRef_t<RhsT>>::value, \
BinaryExpr<LhsT, RhsT const&>> { \
return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op, rhs }; \
} \
template <typename RhsT> \
constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
-> std::enable_if_t<capture_by_value<RhsT>::value, \
BinaryExpr<LhsT, RhsT>> { \
return { \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op, rhs }; \
}
CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(|)

View File

@@ -19,7 +19,7 @@ namespace Catch {
namespace {
// Extracts the actual name part of an enum instance
// In other words, it returns the Blue part of Bikeshed::Colour::Blue
StringRef extractInstanceName(StringRef enumInstance) {
std::string_view extractInstanceName(std::string_view enumInstance) {
// Find last occurrence of ":"
size_t name_start = enumInstance.size();
while (name_start > 0 && enumInstance[name_start - 1] != ':') {
@@ -29,9 +29,9 @@ namespace Catch {
}
}
std::vector<StringRef> parseEnums( StringRef enums ) {
std::vector<std::string_view> parseEnums( std::string_view enums ) {
auto enumValues = splitStringRef( enums, ',' );
std::vector<StringRef> parsed;
std::vector<std::string_view> parsed;
parsed.reserve( enumValues.size() );
for( auto const& enumValue : enumValues ) {
parsed.push_back(trim(extractInstanceName(enumValue)));
@@ -41,15 +41,15 @@ namespace Catch {
EnumInfo::~EnumInfo() = default;
StringRef EnumInfo::lookup( int value ) const {
std::string_view EnumInfo::lookup( int value ) const {
for( auto const& valueToName : m_values ) {
if( valueToName.first == value )
return valueToName.second;
}
return "{** unexpected enum value **}"_sr;
return "{** unexpected enum value **}";
}
Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( std::string_view enumName, std::string_view allValueNames, std::vector<int> const& values ) {
auto enumInfo = Catch::Detail::make_unique<EnumInfo>();
enumInfo->m_name = enumName;
enumInfo->m_values.reserve( values.size() );
@@ -63,11 +63,10 @@ namespace Catch {
return enumInfo;
}
EnumInfo const& EnumValuesRegistry::registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values ) {
EnumInfo const& EnumValuesRegistry::registerEnum( std::string_view enumName, std::string_view allValueNames, std::vector<int> const& values ) {
m_enumInfos.push_back(makeEnumInfo(enumName, allValueNames, values));
return *m_enumInfos.back();
}
} // Detail
} // Catch

View File

@@ -10,7 +10,6 @@
#include <catch2/interfaces/catch_interfaces_enum_values_registry.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <vector>
@@ -18,16 +17,16 @@ namespace Catch {
namespace Detail {
Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( std::string_view enumName, std::string_view allValueNames, std::vector<int> const& values );
class EnumValuesRegistry : public IMutableEnumValuesRegistry {
std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos;
EnumInfo const& registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values) override;
EnumInfo const& registerEnum( std::string_view enumName, std::string_view allValueNames, std::vector<int> const& values) override;
};
std::vector<StringRef> parseEnums( StringRef enums );
std::vector<std::string_view> parseEnums( std::string_view enums );
} // Detail

View File

@@ -59,10 +59,10 @@ namespace Catch {
// To avoid having to handle TFE explicitly everywhere, we just
// rethrow it so that it goes back up the caller.
catch( TestFailureException& ) {
std::rethrow_exception(std::current_exception());
return "{ nested assertion failed }";
}
catch( TestSkipException& ) {
std::rethrow_exception(std::current_exception());
return "{ nested SKIP() called }";
}
catch( std::exception const& ex ) {
return ex.what();

View File

@@ -49,7 +49,7 @@ namespace Catch {
template <typename ForwardIter, typename Sentinel>
constexpr
std::enable_if_t<!std::is_same<ForwardIter, Sentinel>::value,
std::enable_if_t<!std::is_same_v<ForwardIter, Sentinel>,
std::ptrdiff_t>
sentinel_distance( ForwardIter iter, const Sentinel sentinel ) {
std::ptrdiff_t dist = 0;

View File

@@ -7,8 +7,36 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_jsonwriter.hpp>
#include <catch2/internal/catch_unreachable.hpp>
namespace Catch {
namespace {
static bool needsEscape( char c ) {
return c == '"' || c == '\\' || c == '\b' || c == '\f' ||
c == '\n' || c == '\r' || c == '\t';
}
static std::string_view makeEscapeStringRef( char c ) {
if ( c == '"' ) {
return "\\\"";
} else if ( c == '\\' ) {
return "\\\\";
} else if ( c == '\b' ) {
return "\\b";
} else if ( c == '\f' ) {
return "\\f";
} else if ( c == '\n' ) {
return "\\n";
} else if ( c == '\r' ) {
return "\\r";
} else if ( c == '\t' ) {
return "\\t";
}
Catch::Detail::Unreachable();
}
} // namespace
void JsonUtils::indent( std::ostream& os, std::uint64_t level ) {
for ( std::uint64_t i = 0; i < level; ++i ) {
os << " ";
@@ -47,7 +75,7 @@ namespace Catch {
m_os << '}';
}
JsonValueWriter JsonObjectWriter::write( StringRef key ) {
JsonValueWriter JsonObjectWriter::write( std::string_view key ) {
JsonUtils::appendCommaNewline(
m_os, m_should_comma, m_indent_level + 1 );
@@ -108,40 +136,29 @@ namespace Catch {
return JsonArrayWriter{ m_os, m_indent_level };
}
void JsonValueWriter::write( Catch::StringRef value ) && {
void JsonValueWriter::write( std::string_view value ) && {
writeImpl( value, true );
}
void JsonValueWriter::write( bool value ) && {
writeImpl( value ? "true"_sr : "false"_sr, false );
writeImpl( value ? "true" : "false", false );
}
void JsonValueWriter::writeImpl( Catch::StringRef value, bool quote ) {
void JsonValueWriter::writeImpl( std::string_view value, bool quote ) {
if ( quote ) { m_os << '"'; }
for (char c : value) {
// Escape list taken from https://www.json.org/json-en.html,
// string definition.
// Note that while forward slash _can_ be escaped, it does
// not have to be, if JSON is not further embedded somewhere
// where forward slash is meaningful.
if ( c == '"' ) {
m_os << "\\\"";
} else if ( c == '\\' ) {
m_os << "\\\\";
} else if ( c == '\b' ) {
m_os << "\\b";
} else if ( c == '\f' ) {
m_os << "\\f";
} else if ( c == '\n' ) {
m_os << "\\n";
} else if ( c == '\r' ) {
m_os << "\\r";
} else if ( c == '\t' ) {
m_os << "\\t";
} else {
m_os << c;
size_t current_start = 0;
for ( size_t i = 0; i < value.size(); ++i ) {
if ( needsEscape( value[i] ) ) {
if ( current_start < i ) {
m_os << value.substr( current_start, i - current_start );
}
m_os << makeEscapeStringRef( value[i] );
current_start = i + 1;
}
}
if ( current_start < value.size() ) {
m_os << value.substr( current_start, value.size() - current_start );
}
if ( quote ) { m_os << '"'; }
}

View File

@@ -9,7 +9,6 @@
#define CATCH_JSONWRITER_HPP_INCLUDED
#include <catch2/internal/catch_reusable_string_stream.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <cstdint>
#include <sstream>
@@ -35,13 +34,13 @@ namespace Catch {
template <typename T>
void write( T const& value ) && {
writeImpl( value, !std::is_arithmetic<T>::value );
writeImpl( value, !std::is_arithmetic_v<T> );
}
void write( StringRef value ) &&;
void write( std::string_view value ) &&;
void write( bool value ) &&;
private:
void writeImpl( StringRef value, bool quote );
void writeImpl( std::string_view value, bool quote );
// Without this SFINAE, this overload is a better match
// for `std::string`, `char const*`, `char const[N]` args.
@@ -49,7 +48,7 @@ namespace Catch {
// and multiple iteration over the strings
template <typename T,
typename = typename std::enable_if_t<
!std::is_convertible<T, StringRef>::value>>
!std::is_convertible_v<T, std::string_view>>>
void writeImpl( T const& value, bool quote_value ) {
m_sstream << value;
writeImpl( m_sstream.str(), quote_value );
@@ -70,7 +69,7 @@ namespace Catch {
~JsonObjectWriter();
JsonValueWriter write( StringRef key );
JsonValueWriter write( std::string_view key );
private:
std::ostream& m_os;

View File

@@ -30,7 +30,7 @@ namespace Catch {
auto const& testSpec = config.testSpec();
std::vector<TestCaseHandle> matchedTestCases = filterTests(getAllTestCasesSorted(config), testSpec, config);
std::map<StringRef, TagInfo, Detail::CaseInsensitiveLess> tagCounts;
std::map<std::string_view, TagInfo, Detail::CaseInsensitiveLess> tagCounts;
for (auto const& testCase : matchedTestCases) {
for (auto const& tagName : testCase.getTestCaseInfo().tags) {
auto it = tagCounts.find(tagName.original);
@@ -75,7 +75,7 @@ namespace Catch {
} // end anonymous namespace
void TagInfo::add( StringRef spelling ) {
void TagInfo::add( std::string_view spelling ) {
++count;
spellings.insert( spelling );
}

View File

@@ -8,10 +8,9 @@
#ifndef CATCH_LIST_HPP_INCLUDED
#define CATCH_LIST_HPP_INCLUDED
#include <catch2/internal/catch_stringref.hpp>
#include <set>
#include <string>
#include <string_view>
namespace Catch {
@@ -24,15 +23,15 @@ namespace Catch {
std::string name, description;
};
struct ListenerDescription {
StringRef name;
std::string_view name;
std::string description;
};
struct TagInfo {
void add(StringRef spelling);
void add(std::string_view spelling);
std::string all() const;
std::set<StringRef> spellings;
std::set<std::string_view> spellings;
std::size_t count = 0;
};

View File

@@ -1,44 +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
#ifndef CATCH_LOGICAL_TRAITS_HPP_INCLUDED
#define CATCH_LOGICAL_TRAITS_HPP_INCLUDED
#include <type_traits>
namespace Catch {
namespace Detail {
#if defined( __cpp_lib_logical_traits ) && __cpp_lib_logical_traits >= 201510
using std::conjunction;
using std::disjunction;
using std::negation;
#else
template <class...> struct conjunction : std::true_type {};
template <class B1> struct conjunction<B1> : B1 {};
template <class B1, class... Bn>
struct conjunction<B1, Bn...>
: std::conditional_t<bool( B1::value ), conjunction<Bn...>, B1> {};
template <class...> struct disjunction : std::false_type {};
template <class B1> struct disjunction<B1> : B1 {};
template <class B1, class... Bn>
struct disjunction<B1, Bn...>
: std::conditional_t<bool( B1::value ), B1, disjunction<Bn...>> {};
template <class B>
struct negation : std::integral_constant<bool, !bool(B::value)> {};
#endif
} // namespace Detail
} // namespace Catch
#endif // CATCH_LOGICAL_TRAITS_HPP_INCLUDED

View File

@@ -10,16 +10,17 @@
namespace Catch {
MessageInfo::MessageInfo( StringRef _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type )
MessageInfo::MessageInfo( std::string_view _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type )
: macroName( _macroName ),
lineInfo( _lineInfo ),
type( _type ),
sequence( ++globalCount )
{}
// This may need protecting if threading support is added
unsigned int MessageInfo::globalCount = 0;
// Messages are owned by their individual threads, so the counter should be thread-local as well.
// Alternative consideration: atomic, so threads don't share IDs and things are easier to debug.
thread_local unsigned int MessageInfo::globalCount = 0;
} // end namespace Catch

View File

@@ -11,21 +11,21 @@
#include <catch2/internal/catch_deprecation_macro.hpp>
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <string>
namespace Catch {
struct MessageInfo {
MessageInfo( StringRef _macroName,
MessageInfo( std::string_view _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type );
StringRef macroName;
std::string_view macroName;
std::string message;
SourceLineInfo lineInfo;
ResultWas::OfType type;
// The "ID" of the message, used to know when to remove it from reporter context.
unsigned int sequence;
DEPRECATED( "Explicitly use the 'sequence' member instead" )
@@ -37,7 +37,7 @@ namespace Catch {
return sequence < other.sequence;
}
private:
static unsigned int globalCount;
static thread_local unsigned int globalCount;
};
} // end namespace Catch

View File

@@ -27,16 +27,8 @@ namespace Catch {
template <typename Fun, typename... Args>
struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
// std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
// replaced with std::invoke_result here.
template <typename Func, typename... U>
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
#else
template <typename Func, typename... U>
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::result_of_t<Func(U...)>>>;
#endif
} // namespace Catch

View File

@@ -1,117 +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
#ifndef CATCH_OPTIONAL_HPP_INCLUDED
#define CATCH_OPTIONAL_HPP_INCLUDED
#include <catch2/internal/catch_move_and_forward.hpp>
#include <cassert>
namespace Catch {
// An optional type
template<typename T>
class Optional {
public:
Optional(): nullableValue( nullptr ) {}
~Optional() { reset(); }
Optional( T const& _value ):
nullableValue( new ( storage ) T( _value ) ) {}
Optional( T&& _value ):
nullableValue( new ( storage ) T( CATCH_MOVE( _value ) ) ) {}
Optional& operator=( T const& _value ) {
reset();
nullableValue = new ( storage ) T( _value );
return *this;
}
Optional& operator=( T&& _value ) {
reset();
nullableValue = new ( storage ) T( CATCH_MOVE( _value ) );
return *this;
}
Optional( Optional const& _other ):
nullableValue( _other ? new ( storage ) T( *_other ) : nullptr ) {}
Optional( Optional&& _other ):
nullableValue( _other ? new ( storage ) T( CATCH_MOVE( *_other ) )
: nullptr ) {}
Optional& operator=( Optional const& _other ) {
if ( &_other != this ) {
reset();
if ( _other ) { nullableValue = new ( storage ) T( *_other ); }
}
return *this;
}
Optional& operator=( Optional&& _other ) {
if ( &_other != this ) {
reset();
if ( _other ) {
nullableValue = new ( storage ) T( CATCH_MOVE( *_other ) );
}
}
return *this;
}
void reset() {
if ( nullableValue ) { nullableValue->~T(); }
nullableValue = nullptr;
}
T& operator*() {
assert(nullableValue);
return *nullableValue;
}
T const& operator*() const {
assert(nullableValue);
return *nullableValue;
}
T* operator->() {
assert(nullableValue);
return nullableValue;
}
const T* operator->() const {
assert(nullableValue);
return nullableValue;
}
T valueOr( T const& defaultValue ) const {
return nullableValue ? *nullableValue : defaultValue;
}
bool some() const { return nullableValue != nullptr; }
bool none() const { return nullableValue == nullptr; }
bool operator !() const { return nullableValue == nullptr; }
explicit operator bool() const {
return some();
}
friend bool operator==(Optional const& a, Optional const& b) {
if (a.none() && b.none()) {
return true;
} else if (a.some() && b.some()) {
return *a == *b;
} else {
return false;
}
}
friend bool operator!=(Optional const& a, Optional const& b) {
return !( a == b );
}
private:
T* nullableValue;
alignas(alignof(T)) char storage[sizeof(T)];
};
} // end namespace Catch
#endif // CATCH_OPTIONAL_HPP_INCLUDED

View File

@@ -311,23 +311,6 @@ namespace Catch {
}
}
RedirectGuard::RedirectGuard( RedirectGuard&& rhs ) noexcept:
m_redirect( rhs.m_redirect ),
m_activate( rhs.m_activate ),
m_previouslyActive( rhs.m_previouslyActive ),
m_moved( false ) {
rhs.m_moved = true;
}
RedirectGuard& RedirectGuard::operator=( RedirectGuard&& rhs ) noexcept {
m_redirect = rhs.m_redirect;
m_activate = rhs.m_activate;
m_previouslyActive = rhs.m_previouslyActive;
m_moved = false;
rhs.m_moved = true;
return *this;
}
} // namespace Catch
#if defined( CATCH_CONFIG_NEW_CAPTURE )

View File

@@ -63,10 +63,6 @@ namespace Catch {
RedirectGuard( RedirectGuard const& ) = delete;
RedirectGuard& operator=( RedirectGuard const& ) = delete;
// C++14 needs move-able guards to return them from functions
RedirectGuard( RedirectGuard&& rhs ) noexcept;
RedirectGuard& operator=( RedirectGuard&& rhs ) noexcept;
};
RedirectGuard scopedActivate( OutputRedirect& redirectImpl );

View File

@@ -12,10 +12,11 @@
#include <limits>
#include <stdexcept>
#include <optional>
namespace Catch {
Optional<unsigned int> parseUInt(std::string const& input, int base) {
std::optional<unsigned int> parseUInt(std::string const& input, int base) {
auto trimmed = trim( input );
// std::stoull is annoying and accepts numbers starting with '-',
// it just negates them into unsigned int

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