Compare commits

...

8 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
196 changed files with 1438 additions and 4626 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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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,20 +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

@@ -13,6 +13,7 @@
#include <catch2/internal/catch_polyfills.hpp>
#include <iomanip>
#include <cstddef>
namespace Catch {
@@ -57,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.
@@ -95,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());
}
@@ -135,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) {
@@ -166,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) {
@@ -188,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 );
}
@@ -173,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 *> {
@@ -195,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 *> {
@@ -216,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>
@@ -224,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>
@@ -232,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);
@@ -387,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>
@@ -417,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) {
@@ -451,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<>

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

@@ -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,7 +58,7 @@ namespace Generators {
class FilterGenerator final : public IGenerator<T> {
GeneratorWrapper<T> m_generator;
Predicate m_predicate;
static_assert(!std::is_reference<Predicate>::value, "This would most likely result in a dangling reference");
static_assert(!std::is_reference_v<Predicate>, "This would most likely result in a dangling reference");
public:
template <typename P>
FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
@@ -97,7 +97,7 @@ namespace Generators {
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

@@ -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

@@ -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>
@@ -129,7 +127,7 @@
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>>;
}
@@ -148,8 +146,8 @@ namespace Catch {
template <typename T>
struct capture_by_value
: std::integral_constant<bool,
std::is_arithmetic<T>::value ||
std::is_enum<T>::value> {};
std::is_arithmetic_v<T> ||
std::is_enum_v<T>> {};
#if defined( CATCH_CONFIG_CPP20_COMPARE_OVERLOADS )
template <>
@@ -190,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 {
@@ -204,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 ),
@@ -294,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, == )
@@ -348,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, < )
@@ -403,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

@@ -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

@@ -17,21 +17,21 @@ namespace Catch {
c == '\n' || c == '\r' || c == '\t';
}
static Catch::StringRef makeEscapeStringRef( char c ) {
static std::string_view makeEscapeStringRef( char c ) {
if ( c == '"' ) {
return "\\\""_sr;
return "\\\"";
} else if ( c == '\\' ) {
return "\\\\"_sr;
return "\\\\";
} else if ( c == '\b' ) {
return "\\b"_sr;
return "\\b";
} else if ( c == '\f' ) {
return "\\f"_sr;
return "\\f";
} else if ( c == '\n' ) {
return "\\n"_sr;
return "\\n";
} else if ( c == '\r' ) {
return "\\r"_sr;
return "\\r";
} else if ( c == '\t' ) {
return "\\t"_sr;
return "\\t";
}
Catch::Detail::Unreachable();
}
@@ -75,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 );
@@ -136,15 +136,15 @@ 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 << '"'; }
size_t current_start = 0;
for ( size_t i = 0; i < value.size(); ++i ) {

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,7 +10,7 @@
namespace Catch {
MessageInfo::MessageInfo( StringRef _macroName,
MessageInfo::MessageInfo( std::string_view _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type )
: macroName( _macroName ),

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" )

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

View File

@@ -8,8 +8,7 @@
#ifndef CATCH_PARSE_NUMBERS_HPP_INCLUDED
#define CATCH_PARSE_NUMBERS_HPP_INCLUDED
#include <catch2/internal/catch_optional.hpp>
#include <optional>
#include <string>
namespace Catch {
@@ -20,7 +19,7 @@ namespace Catch {
* Effectively a wrapper around std::stoul but with better error checking
* e.g. "-1" is rejected, instead of being parsed as UINT_MAX.
*/
Optional<unsigned int> parseUInt(std::string const& input, int base = 10);
std::optional<unsigned int> parseUInt(std::string const& input, int base = 10);
}
#endif // CATCH_PARSE_NUMBERS_HPP_INCLUDED

View File

@@ -176,7 +176,7 @@ namespace Catch {
template<typename... Ts>\
void reg_test(TypeList<Ts...>, Catch::NameAndTags nameAndTags)\
{\
Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Ts...>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Ts...>), CATCH_INTERNAL_LINEINFO, std::string_view(), nameAndTags);\
}
#define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature, ...)
@@ -184,19 +184,19 @@ namespace Catch {
template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\
{\
Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, std::string_view(), nameAndTags);\
}
#define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\
template<typename Type>\
void reg_test(TypeList<Type>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
void reg_test(TypeList<Type>, std::string_view className, Catch::NameAndTags nameAndTags)\
{\
Catch::AutoReg( Catch::makeTestInvoker(&TestName<Type>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
}
#define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\
template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
void reg_test(Nttp<__VA_ARGS__>, std::string_view className, Catch::NameAndTags nameAndTags)\
{\
Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
}

View File

@@ -11,9 +11,9 @@
#include <catch2/catch_user_config.hpp>
#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
#define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__##_catch_sr
#define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
#else
#define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"_catch_sr
#define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
#endif
#endif // CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED

View File

@@ -27,7 +27,7 @@ namespace Catch {
*/
template <typename FloatType>
FloatType gamma(FloatType a, FloatType b) {
static_assert( std::is_floating_point<FloatType>::value,
static_assert( std::is_floating_point_v<FloatType>,
"gamma returns the largest ULP magnitude within "
"floating point range [a, b]. This only makes sense "
"for floating point types" );

View File

@@ -122,7 +122,7 @@ namespace Catch {
template <typename UInt>
constexpr ExtendedMultResult<UInt> extendedMult( UInt lhs, UInt rhs ) {
static_assert( std::is_unsigned<UInt>::value,
static_assert( std::is_unsigned_v<UInt>,
"extendedMult can only handle unsigned integers" );
static_assert( sizeof( UInt ) < sizeof( std::uint64_t ),
"Generic extendedMult can only handle types smaller "
@@ -141,7 +141,7 @@ namespace Catch {
std::enable_if_t<sizeof(typename Generator::result_type) >= sizeof(TargetType),
TargetType> fillBitsFrom(Generator& gen) {
using gresult_type = typename Generator::result_type;
static_assert( std::is_unsigned<TargetType>::value, "Only unsigned integers are supported" );
static_assert( std::is_unsigned_v<TargetType>, "Only unsigned integers are supported" );
static_assert( Generator::min() == 0 &&
Generator::max() == static_cast<gresult_type>( -1 ),
"Generator must be able to output all numbers in its result type (effectively it must be a random bit generator)" );
@@ -160,7 +160,7 @@ namespace Catch {
std::enable_if_t<sizeof(typename Generator::result_type) < sizeof(TargetType),
TargetType> fillBitsFrom(Generator& gen) {
using gresult_type = typename Generator::result_type;
static_assert( std::is_unsigned<TargetType>::value,
static_assert( std::is_unsigned_v<TargetType>,
"Only unsigned integers are supported" );
static_assert( Generator::min() == 0 &&
Generator::max() == static_cast<gresult_type>( -1 ),
@@ -188,12 +188,12 @@ namespace Catch {
*/
template <typename OriginalType, typename UnsignedType>
constexpr
std::enable_if_t<std::is_signed<OriginalType>::value, UnsignedType>
std::enable_if_t<std::is_signed_v<OriginalType>, UnsignedType>
transposeToNaturalOrder( UnsignedType in ) {
static_assert(
sizeof( OriginalType ) == sizeof( UnsignedType ),
"reordering requires the same sized types on both sides" );
static_assert( std::is_unsigned<UnsignedType>::value,
static_assert( std::is_unsigned_v<UnsignedType>,
"Input type must be unsigned" );
// Assuming 2s complement (standardized in current C++), the
// positive and negative numbers are already internally ordered,
@@ -209,12 +209,12 @@ namespace Catch {
template <typename OriginalType,
typename UnsignedType>
constexpr
std::enable_if_t<std::is_unsigned<OriginalType>::value, UnsignedType>
std::enable_if_t<std::is_unsigned_v<OriginalType>, UnsignedType>
transposeToNaturalOrder(UnsignedType in) {
static_assert(
sizeof( OriginalType ) == sizeof( UnsignedType ),
"reordering requires the same sized types on both sides" );
static_assert( std::is_unsigned<UnsignedType>::value, "Input type must be unsigned" );
static_assert( std::is_unsigned_v<UnsignedType>, "Input type must be unsigned" );
// No reordering is needed for unsigned -> unsigned
return in;
}

View File

@@ -12,26 +12,30 @@
#include <catch2/internal/catch_move_and_forward.hpp>
#include <algorithm>
#include <cassert>
namespace Catch {
namespace {
struct kvPair {
StringRef key, value;
std::string_view key, value;
};
kvPair splitKVPair(StringRef kvString) {
auto splitPos = static_cast<size_t>(
std::find( kvString.begin(), kvString.end(), '=' ) -
kvString.begin() );
kvPair splitKVPair(std::string_view kvString) {
const auto splitPos = kvString.find_first_of('=');
return { kvString.substr( 0, splitPos ),
kvString.substr( splitPos + 1, kvString.size() ) };
const std::string_view key = kvString.substr( 0, splitPos );
std::string_view value;
if (splitPos < kvString.size())
value = kvString.substr( splitPos + 1, kvString.size() );
return { key, value };
}
}
namespace Detail {
std::vector<std::string> splitReporterSpec( StringRef reporterSpec ) {
std::vector<std::string> splitReporterSpec( std::string_view reporterSpec ) {
static constexpr auto separator = "::";
static constexpr size_t separatorSize = 2;
@@ -80,7 +84,7 @@ namespace Catch {
return parts;
}
Optional<ColourMode> stringToColourMode( StringRef colourMode ) {
std::optional<ColourMode> stringToColourMode( std::string_view colourMode ) {
if ( colourMode == "default" ) {
return ColourMode::PlatformDefault;
} else if ( colourMode == "ansi" ) {
@@ -103,19 +107,18 @@ namespace Catch {
lhs.m_customOptions == rhs.m_customOptions;
}
Optional<ReporterSpec> parseReporterSpec( StringRef reporterSpec ) {
std::optional<ReporterSpec> parseReporterSpec( std::string_view reporterSpec ) {
auto parts = Detail::splitReporterSpec( reporterSpec );
assert( parts.size() > 0 && "Split should never return empty vector" );
std::map<std::string, std::string> kvPairs;
Optional<std::string> outputFileName;
Optional<ColourMode> colourMode;
std::optional<std::string> outputFileName;
std::optional<ColourMode> colourMode;
// First part is always reporter name, so we skip it
for ( size_t i = 1; i < parts.size(); ++i ) {
auto kv = splitKVPair( parts[i] );
auto key = kv.key, value = kv.value;
const auto [key, value] = splitKVPair( parts[i] );
if ( key.empty() || value.empty() ) { // NOLINT(bugprone-branch-clone)
return {};
@@ -126,7 +129,7 @@ namespace Catch {
return {};
}
auto ret = kvPairs.emplace( std::string(kv.key), std::string(kv.value) );
auto ret = kvPairs.emplace( std::string(key), std::string(value) );
if ( !ret.second ) {
// Duplicated key. We might want to handle this differently,
// e.g. by overwriting the existing value?
@@ -137,7 +140,7 @@ namespace Catch {
if ( outputFileName ) {
return {};
}
outputFileName = static_cast<std::string>( value );
outputFileName = std::string( value );
} else if ( key == "colour-mode" ) {
// Duplicated key
if ( colourMode ) {
@@ -162,8 +165,8 @@ namespace Catch {
ReporterSpec::ReporterSpec(
std::string name,
Optional<std::string> outputFileName,
Optional<ColourMode> colourMode,
std::optional<std::string> outputFileName,
std::optional<ColourMode> colourMode,
std::map<std::string, std::string> customOptions ):
m_name( CATCH_MOVE( name ) ),
m_outputFileName( CATCH_MOVE( outputFileName ) ),

View File

@@ -9,12 +9,11 @@
#define CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/internal/catch_optional.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <map>
#include <string>
#include <vector>
#include <optional>
namespace Catch {
@@ -22,9 +21,9 @@ namespace Catch {
namespace Detail {
//! Splits the reporter spec into reporter name and kv-pair options
std::vector<std::string> splitReporterSpec( StringRef reporterSpec );
std::vector<std::string> splitReporterSpec( std::string_view reporterSpec );
Optional<ColourMode> stringToColourMode( StringRef colourMode );
std::optional<ColourMode> stringToColourMode( std::string_view colourMode );
}
/**
@@ -37,8 +36,8 @@ namespace Catch {
*/
class ReporterSpec {
std::string m_name;
Optional<std::string> m_outputFileName;
Optional<ColourMode> m_colourMode;
std::optional<std::string> m_outputFileName;
std::optional<ColourMode> m_colourMode;
std::map<std::string, std::string> m_customOptions;
friend bool operator==( ReporterSpec const& lhs,
@@ -51,17 +50,17 @@ namespace Catch {
public:
ReporterSpec(
std::string name,
Optional<std::string> outputFileName,
Optional<ColourMode> colourMode,
std::optional<std::string> outputFileName,
std::optional<ColourMode> colourMode,
std::map<std::string, std::string> customOptions );
std::string const& name() const { return m_name; }
Optional<std::string> const& outputFile() const {
std::optional<std::string> const& outputFile() const {
return m_outputFileName;
}
Optional<ColourMode> const& colourMode() const { return m_colourMode; }
std::optional<ColourMode> const& colourMode() const { return m_colourMode; }
std::map<std::string, std::string> const& customOptions() const {
return m_customOptions;
@@ -78,7 +77,7 @@ namespace Catch {
* * empty key/value in an custom kv pair
* * ...
*/
Optional<ReporterSpec> parseReporterSpec( StringRef reporterSpec );
std::optional<ReporterSpec> parseReporterSpec( std::string_view reporterSpec );
}

View File

@@ -355,7 +355,7 @@ namespace Catch {
// Reset working state. assertion info will be reset after
// populateReaction is run if it is needed
m_lastResult = CATCH_MOVE( result );
m_lastResult.emplace(CATCH_MOVE( result ));
}
void RunContext::notifyAssertionStarted( AssertionInfo const& info ) {
@@ -366,7 +366,7 @@ namespace Catch {
}
}
bool RunContext::sectionStarted( StringRef sectionName,
bool RunContext::sectionStarted( std::string_view sectionName,
SourceLineInfo const& sectionLineInfo,
Counts& assertions ) {
ITracker& sectionTracker =
@@ -392,7 +392,7 @@ namespace Catch {
return true;
}
IGeneratorTracker*
RunContext::acquireGeneratorTracker( StringRef generatorName,
RunContext::acquireGeneratorTracker( std::string_view generatorName,
SourceLineInfo const& lineInfo ) {
auto* tracker = Generators::GeneratorTracker::acquire(
m_trackerContext,
@@ -403,7 +403,7 @@ namespace Catch {
}
IGeneratorTracker* RunContext::createGeneratorTracker(
StringRef generatorName,
std::string_view generatorName,
SourceLineInfo lineInfo,
Generators::GeneratorBasePtr&& generator ) {
@@ -466,7 +466,7 @@ namespace Catch {
m_unfinishedSections.push_back(CATCH_MOVE(endInfo));
}
void RunContext::benchmarkPreparing( StringRef name ) {
void RunContext::benchmarkPreparing( std::string_view name ) {
auto _ = scopedDeactivate( *m_outputRedirect );
m_reporter->benchmarkPreparing( name );
}
@@ -478,16 +478,16 @@ namespace Catch {
auto _ = scopedDeactivate( *m_outputRedirect );
m_reporter->benchmarkEnded( stats );
}
void RunContext::benchmarkFailed( StringRef error ) {
void RunContext::benchmarkFailed( std::string_view error ) {
auto _ = scopedDeactivate( *m_outputRedirect );
m_reporter->benchmarkFailed( error );
}
void RunContext::pushScopedMessage( MessageInfo const& message ) {
Detail::g_messages.push_back( message );
void RunContext::pushScopedMessage( MessageInfo&& message ) {
Detail::g_messages.push_back( CATCH_MOVE(message) );
}
void RunContext::popScopedMessage( MessageInfo const& message ) {
void RunContext::popScopedMessage( unsigned int messageId ) {
// Note: On average, it would probably be better to look for the message
// backwards. However, we do not expect to have to deal with more
// messages than low single digits, so the optimization is tiny,
@@ -496,8 +496,8 @@ namespace Catch {
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;
[=]( MessageInfo const& msg ) {
return msg.sequence == messageId;
} ) );
}
@@ -531,7 +531,7 @@ namespace Catch {
m_shouldReportUnexpected = false;
}
void RunContext::handleFatalErrorCondition( StringRef message ) {
void RunContext::handleFatalErrorCondition( std::string_view message ) {
// We lock only when touching the reporters directly, to avoid
// deadlocks when we call into other functions that also want
// to lock the mutex before touching reporters.
@@ -791,9 +791,9 @@ namespace Catch {
m_activeTestCase->getTestCaseInfo().lineInfo;
return AssertionInfo{
testCaseJustStarted ? "TEST_CASE"_sr : StringRef(),
testCaseJustStarted ? "TEST_CASE" : std::string_view(),
Detail::g_lastKnownLineInfo,
testCaseJustStarted ? StringRef() : "{Unknown expression after the reported line}"_sr,
testCaseJustStarted ? std::string_view() : "{Unknown expression after the reported line}",
ResultDisposition::Normal
};
}

View File

@@ -18,10 +18,10 @@
#include <catch2/internal/catch_test_case_tracker.hpp>
#include <catch2/catch_assertion_info.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/internal/catch_optional.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_thread_support.hpp>
#include <optional>
#include <string>
namespace Catch {
@@ -73,7 +73,7 @@ namespace Catch {
AssertionReaction &reaction ) override;
void notifyAssertionStarted( AssertionInfo const& info ) override;
bool sectionStarted( StringRef sectionName,
bool sectionStarted( std::string_view sectionName,
SourceLineInfo const& sectionLineInfo,
Counts& assertions ) override;
@@ -81,21 +81,21 @@ namespace Catch {
void sectionEndedEarly( SectionEndInfo&& endInfo ) override;
IGeneratorTracker*
acquireGeneratorTracker( StringRef generatorName,
acquireGeneratorTracker( std::string_view generatorName,
SourceLineInfo const& lineInfo ) override;
IGeneratorTracker* createGeneratorTracker(
StringRef generatorName,
std::string_view generatorName,
SourceLineInfo lineInfo,
Generators::GeneratorBasePtr&& generator ) override;
void benchmarkPreparing( StringRef name ) override;
void benchmarkPreparing( std::string_view name ) override;
void benchmarkStarting( BenchmarkInfo const& info ) override;
void benchmarkEnded( BenchmarkStats<> const& stats ) override;
void benchmarkFailed( StringRef error ) override;
void benchmarkFailed( std::string_view error ) override;
void pushScopedMessage( MessageInfo const& message ) override;
void popScopedMessage( MessageInfo const& message ) override;
void pushScopedMessage( MessageInfo&& message ) override;
void popScopedMessage( unsigned int messageId ) override;
void emplaceUnscopedMessage( MessageBuilder&& builder ) override;
@@ -105,7 +105,7 @@ namespace Catch {
void exceptionEarlyReported() override;
void handleFatalErrorCondition( StringRef message ) override;
void handleFatalErrorCondition( std::string_view message ) override;
bool lastAssertionPassed() override;
@@ -144,7 +144,7 @@ namespace Catch {
TestRunInfo m_runInfo;
TestCaseHandle const* m_activeTestCase = nullptr;
ITracker* m_testCaseTracker = nullptr;
Optional<AssertionResult> m_lastResult;
std::optional<AssertionResult> m_lastResult;
IConfig const* m_config;
Totals m_totals;
Detail::AtomicCounts m_atomicAssertionCount;

View File

@@ -24,7 +24,7 @@ namespace Catch {
}
Section::Section( SourceLineInfo const& _lineInfo,
StringRef _name,
std::string_view _name,
const char* const ):
m_info( { "invalid", static_cast<std::size_t>( -1 ) }, std::string{} ),
m_sectionIncluded(

View File

@@ -22,7 +22,7 @@ namespace Catch {
public:
Section( SectionInfo&& info );
Section( SourceLineInfo const& _lineInfo,
StringRef _name,
std::string_view _name,
const char* const = nullptr );
~Section();
@@ -71,7 +71,7 @@ namespace Catch {
// symbol for static analysis.
// The arguments are used as a dummy for checking warnings in the passed
// expressions.
int GetNewSectionHint( StringRef, const char* const = nullptr );
int GetNewSectionHint( std::string_view, const char* const = nullptr );
} // namespace Detail
} // namespace Catch

View File

@@ -8,7 +8,7 @@
#ifndef CATCH_STREAM_END_STOP_HPP_INCLUDED
#define CATCH_STREAM_END_STOP_HPP_INCLUDED
#include <catch2/internal/catch_stringref.hpp>
#include <string_view>
namespace Catch {
@@ -17,7 +17,7 @@ namespace Catch {
// as well as
// << stuff +StreamEndStop
struct StreamEndStop {
constexpr StringRef operator+() const { return StringRef(); }
constexpr std::string_view operator+() const { return std::string_view(); }
template <typename T>
constexpr friend T const& operator+( T const& value, StreamEndStop ) {

View File

@@ -7,28 +7,28 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <ostream>
#include <cstring>
#include <cctype>
#include <string_view>
#include <vector>
namespace Catch {
bool startsWith( std::string const& s, std::string const& prefix ) {
bool startsWith( std::string_view s, std::string_view prefix ) {
return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
}
bool startsWith( StringRef s, char prefix ) {
bool startsWith( std::string_view s, char prefix ) {
return !s.empty() && s[0] == prefix;
}
bool endsWith( std::string const& s, std::string const& suffix ) {
bool endsWith( std::string_view s, std::string_view suffix ) {
return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
}
bool endsWith( std::string const& s, char suffix ) {
bool endsWith( std::string_view s, char suffix ) {
return !s.empty() && s[s.size()-1] == suffix;
}
bool contains( std::string const& s, std::string const& infix ) {
bool contains( std::string_view s, std::string_view infix ) {
return s.find( infix ) != std::string::npos;
}
void toLowerInPlace( std::string& s ) {
@@ -36,8 +36,8 @@ namespace Catch {
c = toLower( c );
}
}
std::string toLower( std::string const& s ) {
std::string lc = s;
std::string toLower( std::string_view s ) {
std::string lc(s);
toLowerInPlace( lc );
return lc;
}
@@ -53,7 +53,7 @@ namespace Catch {
return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
}
StringRef trim(StringRef ref) {
std::string_view trim(std::string_view ref) {
const auto is_ws = [](char c) {
return c == ' ' || c == '\t' || c == '\n' || c == '\r';
};
@@ -65,7 +65,7 @@ namespace Catch {
return ref.substr(real_begin, real_end - real_begin);
}
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
bool replaceInPlace( std::string& str, std::string_view replaceThis, std::string_view withThis ) {
std::size_t i = str.find( replaceThis );
if (i == std::string::npos) {
return false;
@@ -91,8 +91,8 @@ namespace Catch {
return true;
}
std::vector<StringRef> splitStringRef( StringRef str, char delimiter ) {
std::vector<StringRef> subStrings;
std::vector<std::string_view> splitStringRef( std::string_view str, char delimiter ) {
std::vector<std::string_view> subStrings;
std::size_t start = 0;
for(std::size_t pos = 0; pos < str.size(); ++pos ) {
if( str[pos] == delimiter ) {

View File

@@ -8,31 +8,30 @@
#ifndef CATCH_STRING_MANIP_HPP_INCLUDED
#define CATCH_STRING_MANIP_HPP_INCLUDED
#include <catch2/internal/catch_stringref.hpp>
#include <cstdint>
#include <string>
#include <string_view>
#include <iosfwd>
#include <vector>
namespace Catch {
bool startsWith( std::string const& s, std::string const& prefix );
bool startsWith( StringRef s, char prefix );
bool endsWith( std::string const& s, std::string const& suffix );
bool endsWith( std::string const& s, char suffix );
bool contains( std::string const& s, std::string const& infix );
bool startsWith( std::string_view s, std::string_view prefix );
bool startsWith( std::string_view s, char prefix );
bool endsWith( std::string_view s, std::string_view suffix );
bool endsWith( std::string_view s, char suffix );
bool contains( std::string_view s, std::string_view infix );
void toLowerInPlace( std::string& s );
std::string toLower( std::string const& s );
std::string toLower( std::string_view s );
char toLower( char c );
//! Returns a new string without whitespace at the start/end
std::string trim( std::string const& str );
//! Returns a substring of the original ref without whitespace. Beware lifetimes!
StringRef trim(StringRef ref);
std::string_view trim(std::string_view ref);
// !!! Be aware, returns refs into original string - make sure original string outlives them
std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
std::vector<std::string_view> splitStringRef( std::string_view str, char delimiter );
bool replaceInPlace( std::string& str, std::string_view replaceThis, std::string_view withThis );
/**
* Helper for streaming a "count [maybe-plural-of-label]" human-friendly string
@@ -46,10 +45,10 @@ namespace Catch {
*/
class pluralise {
std::uint64_t m_count;
StringRef m_label;
std::string_view m_label;
public:
constexpr pluralise(std::uint64_t count, StringRef label):
constexpr pluralise(std::uint64_t count, std::string_view label):
m_count(count),
m_label(label)
{}

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