catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Build Catch3 as C++17
- Commit
8814bd0b796b2e291fa5b4a1033f0313c8a26065- Author
- Leitwolf11 ·
- Parents
6a42cdf6461b
Changes
.bazelrc | 8 +-- .github/workflows/linux-builds.yml | 4 +- .github/workflows/windows-simple-builds.yml | 2 +- CMake/catch3.pc.in | 2 +- README.md | 8 +-- docs/Readme.md | 2 +- docs/cmake-integration.md | 4 +- docs/contributing.md | 4 +- docs/faq.md | 2 +- docs/progmasoft-catch3.md | 6 +- docs/progmasoft-properties.md | 2 +- docs/why-catch3.md | 4 +- fuzzing/CMakeLists.txt | 2 +- src/CMakeLists.txt | 5 +- src/Progmasoft/BUILD.bazel | 15 +++-- src/Progmasoft/Catch3/Detail/TypeTraits.hpp | 47 +++++++++++++++ src/Progmasoft/Catch3/ForAll.hpp | 38 ++++++++---- src/Progmasoft/Catch3/Generators/Element.hpp | 12 ++-- src/Progmasoft/Catch3/Generators/Integer.hpp | 12 ++-- src/Progmasoft/Catch3/Generators/Tuple.hpp | 3 +- src/Progmasoft/Catch3/Property.hpp | 15 +++-- src/Progmasoft/Catch3/Random.hpp | 43 +++++--------- src/Progmasoft/Catch3/Strategy/ChoiceSource.hpp | 14 ++--- src/Progmasoft/Catch3/Strategy/Containers.hpp | 4 +- src/Progmasoft/Catch3/Strategy/Engine.hpp | 7 +-- src/Progmasoft/Catch3/Strategy/Numeric.hpp | 14 +++-- src/Progmasoft/Catch3/Strategy/Strategy.hpp | 27 +++++---- src/Progmasoft/Catch3/meson.build | 2 +- src/Progmasoft/ChoiceShrinker.cpp | 8 +-- src/Progmasoft/PropertyEngine.cpp | 16 +++-- src/Progmasoft/Runner/Process.cpp | 42 ++++++++------ src/Progmasoft/meson.build | 1 + tests/CMakeLists.txt | 4 +- tests/ExtraTests/CMakeLists.txt | 2 +- tests/Progmasoft/BUILD.bazel | 8 +-- tests/Progmasoft/Generators.tests.cpp | 76 +++++++++++++++++------- tests/Progmasoft/Property.tests.cpp | 66 ++++++++++++++++----- tests/Progmasoft/Results.tests.cpp | 2 +- tests/Progmasoft/Snapshot.tests.cpp | 77 +++++++++++++++---------- tests/Progmasoft/Strategy.tests.cpp | 34 ++++++++--- tests/meson.build | 4 +- 41 files changed, 408 insertions(+), 240 deletions(-) diff --git a/.bazelrc b/.bazelrc index b10a64f5..30415bed 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,12 +1,12 @@ build --enable_platform_specific_config -build:gcc9 --cxxopt=-std=c++2a -build:gcc11 --cxxopt=-std=c++2a -build:gcc13 --cxxopt=-std=c++2a +build:gcc9 --cxxopt=-std=c++17 +build:gcc11 --cxxopt=-std=c++17 +build:gcc13 --cxxopt=-std=c++17 build:clang13 --cxxopt=-std=c++17 build:vs2019 --cxxopt=/std:c++17 build:vs2022 --cxxopt=/std:c++17 build:windows --config=vs2022 build:linux --config=gcc11 -build:macos --cxxopt=-std=c++2b +build:macos --cxxopt=-std=c++17 diff --git a/.github/workflows/linux-builds.yml b/.github/workflows/linux-builds.yml index 8597f658..5290574b 100644 --- a/.github/workflows/linux-builds.yml +++ b/.github/workflows/linux-builds.yml @@ -25,7 +25,7 @@ jobs: fail-fast: false matrix: build_type: [Debug, Release] - std: [14, 17] + std: [17, 20] steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 @@ -93,7 +93,7 @@ jobs: fail-fast: false matrix: build_type: [Debug, Release] - std: [14, 17] + std: [17, 20] steps: # Git comes first: without it the checkout falls back to an archive of diff --git a/.github/workflows/windows-simple-builds.yml b/.github/workflows/windows-simple-builds.yml index 164ff839..3de156c6 100644 --- a/.github/workflows/windows-simple-builds.yml +++ b/.github/workflows/windows-simple-builds.yml @@ -22,7 +22,7 @@ jobs: os: [windows-2025-vs2026] platform: [Win32, x64] build_type: [Debug, Release] - std: [14, 17] + std: [17, 20] steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: diff --git a/CMake/catch3.pc.in b/CMake/catch3.pc.in index 60f81e7f..0e63b475 100644 --- a/CMake/catch3.pc.in +++ b/CMake/catch3.pc.in @@ -4,7 +4,7 @@ includedir=${prefix}/@include_dir@ libdir=${prefix}/@lib_dir@ Name: Catch3 -Description: A C++ test framework with a Catch2-compatible API; headers need C++14 and above +Description: A C++ test framework with a Catch2-compatible API; headers need C++17 and above URL: https://github.com/Progmasoft/catch3 Version: @Catch3_VERSION@ Cflags: -I${includedir} diff --git a/README.md b/README.md index bacde00d..14ee4bdf 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ An independently maintained C++ test framework: Catch3 keeps the practical, expressive test-writing model that developers expect, while adding a separately -owned C++20 library for property checks, snapshots, structured results, and XML +owned C++17 library for property checks, snapshots, structured results, and XML serialization. > Catch3 is not an official Catch2 release and is not endorsed by Catch2's @@ -33,7 +33,7 @@ serialization. - **Structured results and XML output.** The runner's result model, with every attempt, and its deterministic JUnit XML writer are public. - **A compiled library, not a header-only package.** Snapshot I/O and result/XML - serialization are compiled C++20 implementations; templates and assertion + serialization are compiled C++17 implementations; templates and assertion macros remain in headers where needed. Catch3 is in an early development stage. Catch2's command line and reporters @@ -87,8 +87,8 @@ target_link_libraries(MyTests PRIVATE Catch3::Catch3WithMain) `Catch3::Catch3` is the library: the engine, the runner, property testing and snapshots; `Catch3::Catch3WithMain` adds the default `main`. Tests include `<Progmasoft/Catch3/TestMacros.hpp>` and the other `Progmasoft/Catch3/` -headers. The library is built as C++20; code that includes only the engine's -headers needs C++14. Catch3 and Catch2 can be installed side by side, as +headers. The library is C++17, and its headers work in C++17 +and later. Catch3 and Catch2 can be installed side by side, as their package, target, header and pkg-config names differ. ## Documentation diff --git a/docs/Readme.md b/docs/Readme.md index 18bdf927..3da1a8ca 100644 --- a/docs/Readme.md +++ b/docs/Readme.md @@ -2,7 +2,7 @@ # Catch3 documentation Catch3 keeps Catch2's API for writing tests, runs them with -[its own runner](progmasoft-runner.md#top) and adds Progmasoft's C++20 +[its own runner](progmasoft-runner.md#top) and adds Progmasoft's C++17 extensions. Start with the [tutorial](tutorial.md#top), then read [the runner](progmasoft-runner.md#top), [what Catch3 adds](progmasoft-catch3.md), [native property testing](progmasoft-properties.md), [the roadmap](progmasoft-roadmap.md) and diff --git a/docs/cmake-integration.md b/docs/cmake-integration.md index 01c9905a..c6e3771c 100644 --- a/docs/cmake-integration.md +++ b/docs/cmake-integration.md @@ -16,8 +16,8 @@ Catch3's CMake package is `Catch3`. It exports two targets: 1. `Catch3::Catch3`, the library: the Catch2-compatible engine, the Catch3 - runner, property testing and snapshots. It is built as C++20; code that - includes only the engine's headers needs C++14. + runner, property testing and snapshots. It is C++17, and its headers + work in C++17 and later. 2. `Catch3::Catch3WithMain`, the library with the default `main`. `Catch3.cmake` registers each `TEST_CASE` with CTest. diff --git a/docs/contributing.md b/docs/contributing.md index 05c1f415..82e82675 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -62,13 +62,13 @@ distribution with `python tools/scripts/generateAmalgamatedFiles.py`. what Catch3 promises to keep: code that compiles against Catch2's headers must keep compiling. It stays under the Boost Software License 1.0, keeps the `Catch2 Authors` header and follows the style of the surrounding Catch2 code. -Code that includes only its headers needs C++14. +Code that includes its headers needs C++17 or later. `src/Progmasoft` holds what Progmasoft adds: the runner, the results model, property testing and snapshots. It is licensed `MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1`, follows the [Progmasoft C++ Style](https://github.com/Progmasoft/progmasoft-cpp), is -C++20, reports recoverable errors with `Expected` rather than exceptions, and +C++17, reports recoverable errors with `Expected` rather than exceptions, and is formatted with the `.clang-format` beside it. `tools/scripts/checkLicense.py` checks that every source file carries the diff --git a/docs/faq.md b/docs/faq.md index 1ae93bca..63ada4e2 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -41,7 +41,7 @@ as needed later. The bundled Catch2-compatible engine provides no ABI stability guarantee. Its C++ interfaces should be compiled with a consistent compiler and build -configuration. The Progmasoft C++20 extension library does not currently +configuration. The Progmasoft C++17 extension library does not currently promise a stable binary ABI either. Catch2 is not designed to be distributed as dynamic library, and you diff --git a/docs/progmasoft-catch3.md b/docs/progmasoft-catch3.md index 7dc09822..49754af1 100644 --- a/docs/progmasoft-catch3.md +++ b/docs/progmasoft-catch3.md @@ -170,8 +170,8 @@ call-site expansion require it. ## Build and integration The CMake package is `Catch3`, with the targets `Catch3::Catch3` and -`Catch3::Catch3WithMain`. The library is built as C++20; code that includes -only the engine's headers still needs only C++14. After installation, +`Catch3::Catch3WithMain`. The library is C++17, and its headers work in C++17 +and later. After installation, consumers can use: ```cmake @@ -186,7 +186,7 @@ ways to build the same engine and property tests. Their root files are `CMakeLists.txt`, `meson.build`, `xmake.lua`, and `premake5.lua`. Xmake and Premake materialize the default generated configuration header, `Progmasoft/Catch3/UserConfig.hpp`, from the checked-in template. Meson 1.1.0 or newer is required for the Clang-CL -C++20 test target. +C++17 test target. For project history, compatibility intent, license split, and current feature limits, read [Why Progmasoft Catch3?](why-catch3.md). diff --git a/docs/progmasoft-properties.md b/docs/progmasoft-properties.md index e4302383..0b13ad60 100644 --- a/docs/progmasoft-properties.md +++ b/docs/progmasoft-properties.md @@ -224,6 +224,6 @@ A mismatch reports both results as notes. ## Compatibility -The engine is C++20 and part of the `Catch3::Catch3` library. It does not +The engine is C++17 and part of the `Catch3::Catch3` library. It does not change the `Catch` namespace, and it needs no exceptions: a client built without them gets the same results, except that an exception thrown by a body cannot be caught. diff --git a/docs/why-catch3.md b/docs/why-catch3.md index 4d29c4ff..120295f0 100644 --- a/docs/why-catch3.md +++ b/docs/why-catch3.md @@ -17,7 +17,7 @@ Catch2's runner with [its own](progmasoft-runner.md#top). | --- | --- | --- | | Test execution | Catch2's test registration, `RunContext` and listeners | The Catch3 runner: parallel worker processes, retries, flaky-test detection, quarantine, history, selection, sharding and its own command line and reports; `CATCH3_CHECK_FOR_ALL` and `CATCH3_CHECK_PROPERTY` report property outcomes through Catch2's assertion path | | Public include path | The engine's headers moved to `Progmasoft/Catch3/...` with Progmasoft names, such as `TestMacros.hpp` | `Progmasoft/Catch3.hpp` and the other `Progmasoft/Catch3/...` headers | -| C++ baseline | Code that includes the engine's headers needs C++14; the library, which holds the runner, is built as C++20 | The added property API requires C++20 | +| C++ baseline | C++17; the headers work in C++17 and later | The same | | Randomness | Catch2's existing behavior is unchanged | A specified SplitMix64 sequence provides deterministic trial seeds and unbiased bounded integer sampling | | Generated values | No change to existing Catch2 generators | Strategies for numbers, text, collections and structures with `Map`, `Filter` and `FlatMap`; shrinking of recorded choices, so every combination shrinks; replay tokens and an example database; state machines, `Classify`/`Cover` statistics, targeted search, and differential and metamorphic oracles | | Build identity | One library: the `Catch3` CMake package with `Catch3::Catch3` and `Catch3::Catch3WithMain`, `//:catch3` in Bazel, `catch3` in Meson and pkg-config | The same library | @@ -41,7 +41,7 @@ continuity with the included Catch2 3.16.1 base; this is not a promise that ever future Catch2 upstream change will be adopted unchanged or that all downstream projects have already been validated. -The engine, the runner and the Progmasoft additions are one compiled C++20 +The engine, the runner and the Progmasoft additions are one compiled C++17 library. Template-based generators and call-site assertion macros remain in headers; snapshot I/O, result aggregation, and XML serialization are compiled implementations. diff --git a/fuzzing/CMakeLists.txt b/fuzzing/CMakeLists.txt index c5b71e9c..03e205ce 100644 --- a/fuzzing/CMakeLists.txt +++ b/fuzzing/CMakeLists.txt @@ -8,7 +8,7 @@ add_library(fuzzhelper NullOStream.h NullOStream.cpp) target_link_libraries(fuzzhelper PUBLIC Catch3::Catch3) # The runner fuzzers include its C++20 headers. -target_compile_features(fuzzhelper PUBLIC cxx_std_20) +target_compile_features(fuzzhelper PUBLIC cxx_std_17) # This should be possible to set from the outside to be oss-fuzz compatible, # fix later. For now, target libFuzzer only. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f3b7812d..398260fd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -398,8 +398,7 @@ set_target_properties(Catch3 PROPERTIES # Code that includes the engine's headers needs C++14, and the other # Progmasoft/ headers C++20; the library itself, with the runner, is built as C++20. -target_compile_features(Catch3 PUBLIC cxx_std_14) -set_target_properties(Catch3 PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON) +target_compile_features(Catch3 PUBLIC cxx_std_17) configure_file( "${SOURCES_DIR}/UserConfig.hpp.in" @@ -491,7 +490,7 @@ if(CATCH3_BUILD_EXAMPLES OR CATCH3_BUILD_EXTRA_TESTS) ) # These targets compile the library's sources themselves, the runner's # among them, which need C++20. - target_compile_features(Catch3_buildall_interface INTERFACE cxx_std_20) + target_compile_features(Catch3_buildall_interface INTERFACE cxx_std_17) endif() list(APPEND CATCH_IMPL_TARGETS Catch3 Catch3WithMain) diff --git a/src/Progmasoft/BUILD.bazel b/src/Progmasoft/BUILD.bazel index 5824d1b6..a3b4d68e 100644 --- a/src/Progmasoft/BUILD.bazel +++ b/src/Progmasoft/BUILD.bazel @@ -4,12 +4,11 @@ load("@bazel_skylib//rules:expand_template.bzl", "expand_template") load("@rules_cc//cc:defs.bzl", "cc_library") # Catch3: the Catch2-compatible engine in Catch3/, the runner in Runner/, -# property testing and snapshots. It is built as C++20; code that includes -# only the engine's headers needs C++14. //:catch3 and //:catch3_main are the -# public names. -CPP20 = select({ - "@platforms//os:windows": ["/std:c++20"], - "//conditions:default": ["-std=c++20"], +# property testing and snapshots. It is C++17 and its headers work in C++17 +# and later. //:catch3 and //:catch3_main are the public names. +CPP17 = select({ + "@platforms//os:windows": ["/std:c++17"], + "//conditions:default": ["-std=c++17"], }) # The engine's configuration header, with Bazel support switched on. @@ -89,7 +88,7 @@ cc_library( exclude = ["Catch3/Internal/Main.cpp"], ), hdrs = glob(["**/*.hpp"]) + [":Catch3/UserConfig.hpp"], - copts = CPP20, + copts = CPP17, linkstatic = True, strip_include_prefix = "/src", visibility = ["//:__pkg__"], @@ -102,7 +101,7 @@ cc_library( cc_library( name = "catch3_main", srcs = ["Catch3/Internal/Main.cpp"], - copts = CPP20, + copts = CPP17, linkstatic = True, visibility = ["//:__pkg__"], deps = [":catch3"], diff --git a/src/Progmasoft/Catch3/Detail/TypeTraits.hpp b/src/Progmasoft/Catch3/Detail/TypeTraits.hpp new file mode 100644 index 00000000..56f06665 --- /dev/null +++ b/src/Progmasoft/Catch3/Detail/TypeTraits.hpp @@ -0,0 +1,47 @@ +// Copyright (c) 2026 Progmasoft. +// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1 +#pragma once + +#include <type_traits> +#include <utility> + +namespace Progmasoft::Catch3::Detail +{ + + /// std::remove_cvref_t, which C++17 does not have. + template<typename Type> + using RemoveCvRef = std::remove_cv_t<std::remove_reference_t<Type>>; + + /// std::identity, which C++17 does not have. + struct Identity final + { + template<typename Type> + [[nodiscard]] constexpr Type && + operator()(Type &&value) const noexcept + { + return std::forward<Type>(value); + } + }; + + /// An integral type that holds numbers, so anything but bool. + template<typename Type> + inline constexpr bool kIsInteger + = std::is_integral_v<Type> + && !std::is_same_v<std::remove_cv_t<Type>, bool>; + + /// Limits a function template to the types of kIsInteger. + template<typename Type> + using EnableIfInteger = std::enable_if_t<kIsInteger<Type>, int>; + + template<typename Type, typename = void> + inline constexpr bool kIsEqualityComparable = false; + + template<typename Type> + inline constexpr bool kIsEqualityComparable< + Type, + std::enable_if_t< + std::is_convertible_v<decltype(std::declval<const Type &>() + == std::declval<const Type &>()), + bool>>> = true; + +} // namespace Progmasoft::Catch3::Detail diff --git a/src/Progmasoft/Catch3/ForAll.hpp b/src/Progmasoft/Catch3/ForAll.hpp index e41bfdb6..748b89c6 100644 --- a/src/Progmasoft/Catch3/ForAll.hpp +++ b/src/Progmasoft/Catch3/ForAll.hpp @@ -148,7 +148,27 @@ namespace Progmasoft::Catch3 template<typename Type> inline constexpr bool kIsPropertyOptions - = std::is_same_v<std::remove_cvref_t<Type>, PropertyOptions>; + = std::is_same_v<RemoveCvRef<Type>, PropertyOptions>; + + template<typename Arguments, std::size_t... Index> + [[nodiscard]] PropertyResult + ForAllWithOptions(Arguments &all, std::index_sequence<Index...>) + { + constexpr std::size_t kCount = std::tuple_size_v<Arguments>; + return ForAllWith(std::get<0>(all), + std::get<kCount - 1U>(all), + std::get<Index + 1U>(all)...); + } + + template<typename Arguments, std::size_t... Index> + [[nodiscard]] PropertyResult + ForAllWithDefaults(Arguments &all, std::index_sequence<Index...>) + { + constexpr std::size_t kCount = std::tuple_size_v<Arguments>; + return ForAllWith(PropertyOptions{}, + std::get<kCount - 1U>(all), + std::get<Index>(all)...); + } } // namespace Detail @@ -172,19 +192,15 @@ namespace Progmasoft::Catch3 using First = std::tuple_element_t<0, std::tuple<Arguments...>>; if constexpr (Detail::kIsPropertyOptions<First>) { - return [&]<std::size_t... Index>(std::index_sequence<Index...>) { - return Detail::ForAllWith(std::get<0>(all), - std::get<kCount - 1U>(all), - std::get<Index + 1U>(all)...); - }(std::make_index_sequence<kCount - 2U>{}); + return Detail::ForAllWithOptions( + all, + std::make_index_sequence<kCount - 2U>{}); } else { - return [&]<std::size_t... Index>(std::index_sequence<Index...>) { - return Detail::ForAllWith(PropertyOptions{}, - std::get<kCount - 1U>(all), - std::get<Index>(all)...); - }(std::make_index_sequence<kCount - 1U>{}); + return Detail::ForAllWithDefaults( + all, + std::make_index_sequence<kCount - 1U>{}); } } diff --git a/src/Progmasoft/Catch3/Generators/Element.hpp b/src/Progmasoft/Catch3/Generators/Element.hpp index 087b6355..2c270d18 100644 --- a/src/Progmasoft/Catch3/Generators/Element.hpp +++ b/src/Progmasoft/Catch3/Generators/Element.hpp @@ -2,9 +2,9 @@ // SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1 #pragma once +#include <Progmasoft/Catch3/Detail/TypeTraits.hpp> #include <Progmasoft/Catch3/Generator.hpp> #include <algorithm> -#include <concepts> #include <cstddef> #include <initializer_list> #include <iterator> @@ -20,8 +20,9 @@ namespace Progmasoft::Catch3 /// The list order is the simplicity order: a value shrinks to the values /// listed before it, earliest first, so place the simplest case first. /// A value that is not in the list has no candidates. - template<typename ValueType> - requires std::equality_comparable<ValueType> + template<typename ValueType, + std::enable_if_t<Detail::kIsEqualityComparable<ValueType>, int> + = 0> [[nodiscard]] Generator<ValueType> Element(std::vector<ValueType> values) { @@ -52,8 +53,9 @@ namespace Progmasoft::Catch3 } /// Convenience overload for a literal list of values. - template<typename ValueType> - requires std::equality_comparable<ValueType> + template<typename ValueType, + std::enable_if_t<Detail::kIsEqualityComparable<ValueType>, int> + = 0> [[nodiscard]] Generator<ValueType> Element(std::initializer_list<ValueType> values) { diff --git a/src/Progmasoft/Catch3/Generators/Integer.hpp b/src/Progmasoft/Catch3/Generators/Integer.hpp index 45192b3d..3659aa4f 100644 --- a/src/Progmasoft/Catch3/Generators/Integer.hpp +++ b/src/Progmasoft/Catch3/Generators/Integer.hpp @@ -2,9 +2,9 @@ // SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1 #pragma once +#include <Progmasoft/Catch3/Detail/TypeTraits.hpp> #include <Progmasoft/Catch3/Generator.hpp> #include <algorithm> -#include <concepts> #include <limits> #include <type_traits> @@ -13,8 +13,7 @@ namespace Progmasoft::Catch3 namespace Detail { - template<std::integral IntegerType> - requires(!std::same_as<IntegerType, bool>) + template<typename IntegerType, Detail::EnableIfInteger<IntegerType> = 0> [[nodiscard]] std::vector<IntegerType> ShrinkInteger(IntegerType value, IntegerType minimum, @@ -24,7 +23,9 @@ namespace Progmasoft::Catch3 const auto addCandidate = [&](IntegerType candidate) { if (candidate < minimum || candidate > maximum || candidate == value - || std::ranges::find(candidates, candidate) + || std::find(candidates.begin(), + candidates.end(), + candidate) != candidates.end()) { return; @@ -86,8 +87,7 @@ namespace Progmasoft::Catch3 /// Generates integers over the inclusive range and shrinks toward simple /// values. - template<std::integral IntegerType> - requires(!std::same_as<IntegerType, bool>) + template<typename IntegerType, Detail::EnableIfInteger<IntegerType> = 0> [[nodiscard]] Generator<IntegerType> Integer(IntegerType minimum = std::numeric_limits<IntegerType>::lowest(), IntegerType maximum = std::numeric_limits<IntegerType>::max()) diff --git a/src/Progmasoft/Catch3/Generators/Tuple.hpp b/src/Progmasoft/Catch3/Generators/Tuple.hpp index df58da05..3e889307 100644 --- a/src/Progmasoft/Catch3/Generators/Tuple.hpp +++ b/src/Progmasoft/Catch3/Generators/Tuple.hpp @@ -54,10 +54,11 @@ namespace Progmasoft::Catch3 /// runner's greedy restart this minimizes every component without /// trying the cross product of candidates. template<typename... ValueTypes> - requires(sizeof...(ValueTypes) > 0) [[nodiscard]] Generator<std::tuple<ValueTypes...>> Tuple(Generator<ValueTypes>... generators) { + static_assert(sizeof...(ValueTypes) > 0, + "Tuple requires at least one generator"); using Value = std::tuple<ValueTypes...>; const std::tuple<Generator<ValueTypes>...> components{ std::move( generators)... }; diff --git a/src/Progmasoft/Catch3/Property.hpp b/src/Progmasoft/Catch3/Property.hpp index 1ce97adb..5109fd37 100644 --- a/src/Progmasoft/Catch3/Property.hpp +++ b/src/Progmasoft/Catch3/Property.hpp @@ -2,9 +2,9 @@ // SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-1.1 #pragma once +#include <Progmasoft/Catch3/Detail/TypeTraits.hpp> #include <Progmasoft/Catch3/Generator.hpp> #include <Progmasoft/Catch3/ToString.hpp> -#include <concepts> #include <cstddef> #include <cstdint> #include <exception> @@ -304,8 +304,7 @@ namespace Progmasoft::Catch3 [[nodiscard]] std::string StringifyPropertyValue(const ValueType &value) { - return PropertyValuePrinter<std::remove_cvref_t<ValueType>>::Print( - value); + return PropertyValuePrinter<RemoveCvRef<ValueType>>::Print(value); } template<typename Predicate, typename ValueType> @@ -362,11 +361,11 @@ namespace Progmasoft::Catch3 /// Runs independently seeded trials and greedily accepts failing shrink /// candidates. - template<typename ValueType, typename Predicate> - requires std::invocable<Predicate &, const ValueType &> - && std::convertible_to< - std::invoke_result_t<Predicate &, const ValueType &>, - bool> + template<typename ValueType, + typename Predicate, + std::enable_if_t< + std::is_invocable_r_v<bool, Predicate &, const ValueType &>, + int> = 0> [[nodiscard]] PropertyResult CheckProperty(const Generator<ValueType> &generator, Predicate predicate, diff --git a/src/Progmasoft/Catch3/Random.hpp b/src/Progmasoft/Catch3/Random.hpp index a1f1ac94..31e9dd1d 100644 --- a/src/Progmasoft/Catch3/Random.hpp +++ b/src/Progmasoft/Catch3/Random.hpp @@ -3,8 +3,7 @@ #pragma once #include <Progmasoft/Catch3/Detail/InvalidArgument.hpp> -#include <bit> -#include <concepts> +#include <Progmasoft/Catch3/Detail/TypeTraits.hpp> #include <cstdint> #include <limits> #include <stdexcept> @@ -63,8 +62,7 @@ namespace Progmasoft::Catch3 /// Returns an inclusive integral value without overflowing at type /// limits. - template<std::integral IntegerType> - requires(!std::same_as<IntegerType, bool>) + template<typename IntegerType, Detail::EnableIfInteger<IntegerType> = 0> [[nodiscard]] IntegerType Between(IntegerType minimum, IntegerType maximum) { @@ -82,31 +80,15 @@ namespace Progmasoft::Catch3 constexpr UnsignedType kSignBit = UnsignedType{ 1 } << (kBitCount - 1U); - const auto encode - = [](IntegerType value) constexpr -> UnsignedType { - if constexpr (std::is_signed_v<IntegerType>) - { - return std::bit_cast<UnsignedType>(value) ^ kSignBit; - } - else - { - return value; - } - }; - const auto decode - = [](UnsignedType value) constexpr -> IntegerType { - if constexpr (std::is_signed_v<IntegerType>) - { - return std::bit_cast<IntegerType>(value ^ kSignBit); - } - else - { - return value; - } - }; - - const UnsignedType lower = encode(minimum); - const UnsignedType upper = encode(maximum); + // Flipping the sign bit orders signed values as unsigned ones. + const UnsignedType flip + = std::is_signed_v<IntegerType> ? kSignBit : UnsignedType{}; + const auto lower + = static_cast<UnsignedType>(static_cast<UnsignedType>(minimum) + ^ flip); + const auto upper + = static_cast<UnsignedType>(static_cast<UnsignedType>(maximum) + ^ flip); // Unsigned wrap to zero represents the complete value domain. const UnsignedType width = static_cast<UnsignedType>(upper - lower + UnsignedType{ 1 }); @@ -114,7 +96,8 @@ namespace Progmasoft::Catch3 = width == 0 ? static_cast<UnsignedType>(Next()) : static_cast<UnsignedType>( Below(static_cast<std::uint64_t>(width))); - return decode(static_cast<UnsignedType>(lower + offset)); + return static_cast<IntegerType>( + static_cast<UnsignedType>(lower + offset) ^ flip); } /// Derives an independent, reproducible seed for one trial. diff --git a/src/Progmasoft/Catch3/Strategy/ChoiceSource.hpp b/src/Progmasoft/Catch3/Strategy/ChoiceSource.hpp index aaa6c509..126d4420 100644 --- a/src/Progmasoft/Catch3/Strategy/ChoiceSource.hpp +++ b/src/Progmasoft/Catch3/Strategy/ChoiceSource.hpp @@ -6,7 +6,6 @@ #include <cstddef> #include <cstdint> #include <optional> -#include <span> #include <vector> namespace Progmasoft::Catch3 @@ -36,11 +35,12 @@ namespace Progmasoft::Catch3 , size_(size) {} - /// Replay: choices are read from a recorded sequence. - ChoiceSource(std::span<const std::uint64_t> replay, + /// Replay: choices are read from a recorded sequence, which has to + /// outlive this object. + ChoiceSource(const std::vector<std::uint64_t> &replay, std::size_t size) noexcept : random_(0) - , replay_(replay) + , replay_(&replay) , replaying_(true) , size_(size) {} @@ -148,12 +148,12 @@ namespace Progmasoft::Catch3 [[nodiscard]] std::uint64_t ReadReplay(std::uint64_t maximum) noexcept { - if (position_ >= replay_.size()) + if (position_ >= replay_->size()) { overran_ = true; return 0; } - const std::uint64_t value = replay_[position_++]; + const std::uint64_t value = (*replay_)[position_++]; // A shrink may lower a choice that an earlier, changed choice // now bounds more tightly; clamping keeps the replay valid. return value > maximum ? maximum : value; @@ -180,7 +180,7 @@ namespace Progmasoft::Catch3 } Random random_; - std::span<const std::uint64_t> replay_; + const std::vector<std::uint64_t> *replay_ = nullptr; std::size_t position_ = 0; bool replaying_ = false; bool overran_ = false; diff --git a/src/Progmasoft/Catch3/Strategy/Containers.hpp b/src/Progmasoft/Catch3/Strategy/Containers.hpp index ad4daf39..e0b95cd0 100644 --- a/src/Progmasoft/Catch3/Strategy/Containers.hpp +++ b/src/Progmasoft/Catch3/Strategy/Containers.hpp @@ -132,7 +132,7 @@ namespace Progmasoft::Catch3 /// Vectors whose elements are distinct under key. A duplicate is /// drawn again up to maximumRetries times before the trial gives /// up. - template<typename ElementType, typename Key = std::identity> + template<typename ElementType, typename Key = Detail::Identity> [[nodiscard]] Strategy<std::vector<ElementType>> UniqueVectors(Strategy<ElementType> element, SizeRange range = {}, @@ -210,7 +210,7 @@ namespace Progmasoft::Catch3 { return false; } - if (result.contains(*drawnKey)) + if (result.find(*drawnKey) != result.end()) { continue; } diff --git a/src/Progmasoft/Catch3/Strategy/Engine.hpp b/src/Progmasoft/Catch3/Strategy/Engine.hpp index fbe8d340..79690963 100644 --- a/src/Progmasoft/Catch3/Strategy/Engine.hpp +++ b/src/Progmasoft/Catch3/Strategy/Engine.hpp @@ -9,7 +9,6 @@ #include <cstdint> #include <functional> #include <optional> -#include <span> #include <string> #include <string_view> #include <vector> @@ -52,7 +51,7 @@ namespace Progmasoft::Catch3::Detail /// A replay token: the size of the trial and its choices. [[nodiscard]] std::string - EncodeChoices(std::size_t size, std::span<const std::uint64_t> choices); + EncodeChoices(std::size_t size, const std::vector<std::uint64_t> &choices); struct DecodedChoices final { @@ -79,7 +78,7 @@ namespace Progmasoft::Catch3::Detail /// Shortlex order: shorter first, then lexicographically smaller. [[nodiscard]] bool - IsSimpler(std::span<const std::uint64_t> candidate, - std::span<const std::uint64_t> current) noexcept; + IsSimpler(const std::vector<std::uint64_t> &candidate, + const std::vector<std::uint64_t> ¤t) noexcept; } // namespace Progmasoft::Catch3::Detail diff --git a/src/Progmasoft/Catch3/Strategy/Numeric.hpp b/src/Progmasoft/Catch3/Strategy/Numeric.hpp index 8f58b06d..80c4174e 100644 --- a/src/Progmasoft/Catch3/Strategy/Numeric.hpp +++ b/src/Progmasoft/Catch3/Strategy/Numeric.hpp @@ -4,10 +4,9 @@ #include <Progmasoft/Catch3/Strategy/Strategy.hpp> #include <array> -#include <bit> #include <cmath> -#include <concepts> #include <cstdint> +#include <cstring> #include <limits> #include <optional> #include <type_traits> @@ -34,8 +33,8 @@ namespace Progmasoft::Catch3::Gen /// Integers in [minimum, maximum]. They shrink towards the value of the /// range closest to zero; generation favours small magnitudes, zero and /// the bounds, scaled by the trial size. - template<std::integral IntegerType> - requires(!std::same_as<IntegerType, bool>) + template<typename IntegerType, + Catch3::Detail::EnableIfInteger<IntegerType> = 0> [[nodiscard]] Strategy<IntegerType> Integers(IntegerType minimum = std::numeric_limits<IntegerType>::lowest(), IntegerType maximum = std::numeric_limits<IntegerType>::max()) @@ -105,7 +104,8 @@ namespace Progmasoft::Catch3::Gen /// Generation mixes integral values, short binary fractions, uniform /// values of the range, arbitrary bit patterns, and edge values such as /// the smallest subnormal and the largest finite value. - template<std::floating_point FloatType> + template<typename FloatType, + std::enable_if_t<std::is_floating_point_v<FloatType>, int> = 0> [[nodiscard]] Strategy<FloatType> Floats(FloatOptions options = {}) { @@ -204,7 +204,9 @@ namespace Progmasoft::Catch3::Gen { // Any bit pattern; non-finite patterns fall back. const auto bits = source.Draw(UINT64_MAX); - const double value = std::bit_cast<double>(bits); + static_assert(sizeof(double) == sizeof(bits)); + double value{}; + std::memcpy(&value, &bits, sizeof(value)); return finish(std::isfinite(value) ? value : anchor); } default: diff --git a/src/Progmasoft/Catch3/Strategy/Strategy.hpp b/src/Progmasoft/Catch3/Strategy/Strategy.hpp index 5eb06d6f..77f24b82 100644 --- a/src/Progmasoft/Catch3/Strategy/Strategy.hpp +++ b/src/Progmasoft/Catch3/Strategy/Strategy.hpp @@ -3,9 +3,9 @@ #pragma once #include <Progmasoft/Catch3/Detail/InvalidArgument.hpp> +#include <Progmasoft/Catch3/Detail/TypeTraits.hpp> #include <Progmasoft/Catch3/Strategy/ChoiceSource.hpp> #include <algorithm> -#include <concepts> #include <cstddef> #include <cstdint> #include <functional> @@ -58,7 +58,7 @@ namespace Progmasoft::Catch3 [[nodiscard]] auto Map(Transform transform) const { - using Result = std::remove_cvref_t< + using Result = Catch3::Detail::RemoveCvRef< std::invoke_result_t<Transform &, ValueType>>; Strategy self = *this; return Strategy<Result>( @@ -114,8 +114,8 @@ namespace Progmasoft::Catch3 [[nodiscard]] auto FlatMap(Bind bind) const { - using Next - = std::remove_cvref_t<std::invoke_result_t<Bind &, ValueType>>; + using Next = Catch3::Detail::RemoveCvRef< + std::invoke_result_t<Bind &, ValueType>>; using Result = typename Next::Value; Strategy self = *this; return Strategy<Result>( @@ -136,17 +136,18 @@ namespace Progmasoft::Catch3 /// The value type of a strategy. template<typename StrategyType> - using StrategyValue = typename std::remove_cvref_t<StrategyType>::Value; + using StrategyValue = + typename Catch3::Detail::RemoveCvRef<StrategyType>::Value; namespace Gen { /// Always the same value; draws no choice. template<typename ValueType> - [[nodiscard]] Strategy<std::remove_cvref_t<ValueType>> + [[nodiscard]] Strategy<Catch3::Detail::RemoveCvRef<ValueType>> Just(ValueType value) { - using Result = std::remove_cvref_t<ValueType>; + using Result = Catch3::Detail::RemoveCvRef<ValueType>; return Strategy<Result>( [value = Result(std::move(value))](ChoiceSource &) -> std::optional<Result> { return value; }); @@ -172,9 +173,12 @@ namespace Progmasoft::Catch3 }); } - template<typename First, typename... Rest> - requires(std::same_as<StrategyValue<First>, StrategyValue<Rest>> - && ...) + template<typename First, + typename... Rest, + std::enable_if_t< + (std::is_same_v<StrategyValue<First>, StrategyValue<Rest>> + && ...), + int> = 0> [[nodiscard]] Strategy<StrategyValue<First>> OneOf(First first, Rest... rest) { @@ -249,7 +253,8 @@ namespace Progmasoft::Catch3 [[nodiscard]] auto Lazy(Factory factory) { - using Result = std::remove_cvref_t<std::invoke_result_t<Factory &>>; + using Result + = Catch3::Detail::RemoveCvRef<std::invoke_result_t<Factory &>>; using ValueType = typename Result::Value; return Strategy<ValueType>( [factory]( diff --git a/src/Progmasoft/Catch3/meson.build b/src/Progmasoft/Catch3/meson.build index 70bf336d..b8d38908 100644 --- a/src/Progmasoft/Catch3/meson.build +++ b/src/Progmasoft/Catch3/meson.build @@ -354,7 +354,7 @@ catch3 = static_library( sources, dependencies: catch3_dependencies, include_directories: '../..', - override_options: ['cpp_std=c++20'], + override_options: ['cpp_std=c++17'], install: get_option('install'), ) diff --git a/src/Progmasoft/ChoiceShrinker.cpp b/src/Progmasoft/ChoiceShrinker.cpp index c1aac19c..b9b5a47d 100644 --- a/src/Progmasoft/ChoiceShrinker.cpp +++ b/src/Progmasoft/ChoiceShrinker.cpp @@ -14,8 +14,8 @@ namespace Progmasoft::Catch3::Detail { bool - IsSimpler(std::span<const std::uint64_t> candidate, - std::span<const std::uint64_t> current) noexcept + IsSimpler(const std::vector<std::uint64_t> &candidate, + const std::vector<std::uint64_t> ¤t) noexcept { if (candidate.size() != current.size()) { @@ -299,7 +299,7 @@ namespace Progmasoft::Catch3::Detail } std::string - EncodeChoices(std::size_t size, std::span<const std::uint64_t> choices) + EncodeChoices(std::size_t size, const std::vector<std::uint64_t> &choices) { // c3.<size>.<choice>-<choice>-... with each number in base 36: short // enough to paste from a CI log, and only characters that survive @@ -329,7 +329,7 @@ namespace Progmasoft::Catch3::Detail std::optional<DecodedChoices> DecodeChoices(std::string_view token) { - if (!token.starts_with(kTokenPrefix)) + if (token.substr(0, kTokenPrefix.size()) != kTokenPrefix) { return std::nullopt; } diff --git a/src/Progmasoft/PropertyEngine.cpp b/src/Progmasoft/PropertyEngine.cpp index 571a5ac3..7151dd1a 100644 --- a/src/Progmasoft/PropertyEngine.cpp +++ b/src/Progmasoft/PropertyEngine.cpp @@ -231,7 +231,7 @@ namespace Progmasoft::Catch3::Detail std::size_t size, bool describe) { - return Execute(ChoiceSource(std::span(choices), size), describe); + return Execute(ChoiceSource(choices, size), describe); } static PropertyResult @@ -302,10 +302,16 @@ namespace Progmasoft::Catch3::Detail // Only the examples checked here are dropped; another // process may have stored new ones meanwhile. database_.Update([&](std::vector<std::string> &stored) { - std::erase_if(stored, [&](const std::string &token) { - return std::find(tokens.begin(), tokens.end(), token) - != tokens.end(); - }); + const auto removed = std::remove_if( + stored.begin(), + stored.end(), + [&](const std::string &token) { + return std::find(tokens.begin(), + tokens.end(), + token) + != tokens.end(); + }); + stored.erase(removed, stored.end()); }); } return std::nullopt; diff --git a/src/Progmasoft/Runner/Process.cpp b/src/Progmasoft/Runner/Process.cpp index 8ef02327..d0b5b512 100644 --- a/src/Progmasoft/Runner/Process.cpp +++ b/src/Progmasoft/Runner/Process.cpp @@ -191,18 +191,22 @@ namespace Progmasoft::Catch3::Runner for (const auto &[name, value] : additions) { const std::wstring wideName = Widen(name); - std::erase_if(entries, [&](const std::wstring &entry) { - // A leading '=' marks the hidden per-drive variables. - const auto equals = entry.find(L'=', 1); - return equals == wideName.size() - && CompareStringOrdinal( - entry.data(), - static_cast<int>(equals), - wideName.data(), - static_cast<int>(wideName.size()), - TRUE) - == CSTR_EQUAL; - }); + const auto removed = std::remove_if( + entries.begin(), + entries.end(), + [&](const std::wstring &entry) { + // A leading '=' marks the hidden per-drive variables. + const auto equals = entry.find(L'=', 1); + return equals == wideName.size() + && CompareStringOrdinal( + entry.data(), + static_cast<int>(equals), + wideName.data(), + static_cast<int>(wideName.size()), + TRUE) + == CSTR_EQUAL; + }); + entries.erase(removed, entries.end()); entries.push_back(wideName + L"=" + Widen(value)); } std::wstring block; @@ -957,11 +961,15 @@ namespace Progmasoft::Catch3::Runner } for (const auto &[name, value] : options.environment) { - std::erase_if(environmentStorage, [&](const std::string &entry) { - return entry.size() > name.size() - && entry.compare(0, name.size(), name) == 0 - && entry[name.size()] == '='; - }); + const auto removed = std::remove_if( + environmentStorage.begin(), + environmentStorage.end(), + [&](const std::string &entry) { + return entry.size() > name.size() + && entry.compare(0, name.size(), name) == 0 + && entry[name.size()] == '='; + }); + environmentStorage.erase(removed, environmentStorage.end()); environmentStorage.push_back(name + "=" + value); } std::vector<char *> environment; diff --git a/src/Progmasoft/meson.build b/src/Progmasoft/meson.build index 1e00ba69..885aaa4b 100644 --- a/src/Progmasoft/meson.build +++ b/src/Progmasoft/meson.build @@ -6,6 +6,7 @@ if get_option('install') install_headers('Catch3.hpp', subdir: 'Progmasoft') install_headers('Catch3/Assertions.hpp', subdir: 'Progmasoft/Catch3') + install_headers('Catch3/Detail/TypeTraits.hpp', subdir: 'Progmasoft/Catch3/Detail') install_headers('Catch3/Detail/InvalidArgument.hpp', subdir: 'Progmasoft/Catch3/Detail') install_headers('Catch3/Detail/Sequence.hpp', subdir: 'Progmasoft/Catch3/Detail') install_headers('Catch3/Generator.hpp', subdir: 'Progmasoft/Catch3') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5af76cab..a5524a38 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -172,12 +172,12 @@ add_executable(ProgmasoftSelfTest Progmasoft/Strategy.tests.cpp ) target_link_libraries(ProgmasoftSelfTest PRIVATE Catch3WithMain) -target_compile_features(ProgmasoftSelfTest PRIVATE cxx_std_20) +target_compile_features(ProgmasoftSelfTest PRIVATE cxx_std_17) # Tests that misbehave on purpose, for the runner's integration tests. add_executable(RunnerFixture Progmasoft/RunnerFixture.cpp) target_link_libraries(RunnerFixture PRIVATE Catch3WithMain) -target_compile_features(RunnerFixture PRIVATE cxx_std_20) +target_compile_features(RunnerFixture PRIVATE cxx_std_17) add_dependencies(ProgmasoftSelfTest RunnerFixture) add_test(NAME Progmasoft::PropertyTests COMMAND $<TARGET_FILE:ProgmasoftSelfTest> --no-history) diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt index 9518c733..e6488650 100644 --- a/tests/ExtraTests/CMakeLists.txt +++ b/tests/ExtraTests/CMakeLists.txt @@ -431,7 +431,7 @@ add_executable(AmalgamatedTestCompilation ) target_include_directories(AmalgamatedTestCompilation PRIVATE ${CATCH_DIR}/extras) # The amalgamated files hold the runner, which needs C++20. -target_compile_features(AmalgamatedTestCompilation PRIVATE cxx_std_20) +target_compile_features(AmalgamatedTestCompilation PRIVATE cxx_std_17) add_test(NAME AmalgamatedFileTest COMMAND AmalgamatedTestCompilation --no-history) set_tests_properties(AmalgamatedFileTest diff --git a/tests/Progmasoft/BUILD.bazel b/tests/Progmasoft/BUILD.bazel index 9627f65d..de7f124d 100644 --- a/tests/Progmasoft/BUILD.bazel +++ b/tests/Progmasoft/BUILD.bazel @@ -24,8 +24,8 @@ cc_test( "Strategy.tests.cpp", ], copts = select({ - "@platforms//os:windows": ["/std:c++20"], - "//conditions:default": ["-std=c++20"], + "@platforms//os:windows": ["/std:c++17"], + "//conditions:default": ["-std=c++17"], }), args = ["--no-history"], data = [":runner_fixture"], @@ -41,8 +41,8 @@ cc_binary( name = "runner_fixture", srcs = ["RunnerFixture.cpp"], copts = select({ - "@platforms//os:windows": ["/std:c++20"], - "//conditions:default": ["-std=c++20"], + "@platforms//os:windows": ["/std:c++17"], + "//conditions:default": ["-std=c++17"], }), deps = [ "//:catch3", diff --git a/tests/Progmasoft/Generators.tests.cpp b/tests/Progmasoft/Generators.tests.cpp index 553a8962..b59bab4a 100644 --- a/tests/Progmasoft/Generators.tests.cpp +++ b/tests/Progmasoft/Generators.tests.cpp @@ -96,11 +96,16 @@ TEST_CASE( "Vector shrinking offers a bounded number of candidates", TEST_CASE( "Vector properties shrink to a small counterexample", "[progmasoft][property][vector]" ) { const auto result = CheckProperty( - Vector( Integer<int>( 0, 100 ), 0, 20 ), - []( const std::vector<int>& values ) { + Vector(Integer<int>(0, 100), 0, 20), + [](const std::vector<int> &values) { return std::accumulate( values.begin(), values.end(), 0 ) < 10; }, - PropertyOptions{ .Trials = 200, .Seed = 0xF00D } ); + [&] { + PropertyOptions made; + made.Trials = 200; + made.Seed = 0xF00D; + return made; + }()); REQUIRE( result.Status == PropertyStatus::kFailed ); REQUIRE( result.Failure.has_value() ); @@ -113,10 +118,15 @@ TEST_CASE( "Vector<bool> values generate, shrink and print", const auto generator = Vector( Progmasoft::Catch3::Boolean(), 0, 8 ); const auto result = CheckProperty( generator, - []( const std::vector<bool>& flags ) { + [](const std::vector<bool> &flags) { return std::count( flags.begin(), flags.end(), true ) < 2; }, - PropertyOptions{ .Trials = 300, .Seed = 0xB001 } ); + [&] { + PropertyOptions made; + made.Trials = 300; + made.Seed = 0xB001; + return made; + }()); REQUIRE( result.Status == PropertyStatus::kFailed ); REQUIRE( result.Failure.has_value() ); CHECK( result.Failure->Counterexample == "{ true, true }" ); @@ -167,11 +177,16 @@ TEST_CASE( "Tuple shrinking changes one component at a time, first to last", TEST_CASE( "Tuple properties minimize every component", "[progmasoft][property][tuple]" ) { const auto result = CheckProperty( - Tuple( Integer<int>( 0, 1000 ), Integer<int>( 0, 1000 ) ), - []( const std::tuple<int, int>& value ) { + Tuple(Integer<int>(0, 1000), Integer<int>(0, 1000)), + [](const std::tuple<int, int> &value) { return std::get<0>( value ) < 50 || std::get<1>( value ) < 50; }, - PropertyOptions{ .Trials = 500, .Seed = 0x7007 } ); + [&] { + PropertyOptions made; + made.Trials = 500; + made.Seed = 0x7007; + return made; + }()); REQUIRE( result.Status == PropertyStatus::kFailed ); REQUIRE( result.Failure.has_value() ); @@ -234,11 +249,16 @@ TEST_CASE( "Text generators stay inside their alphabet and length range", TEST_CASE( "Text properties shrink to the shortest simplest string", "[progmasoft][property][text]" ) { const auto result = CheckProperty( - Text( "abcxyz", 0, 24 ), - []( const std::string& value ) { + Text("abcxyz", 0, 24), + [](const std::string &value) { return value.find( 'x' ) == std::string::npos; }, - PropertyOptions{ .Trials = 300, .Seed = 0x7E47 } ); + [&] { + PropertyOptions made; + made.Trials = 300; + made.Seed = 0x7E47; + return made; + }()); REQUIRE( result.Status == PropertyStatus::kFailed ); REQUIRE( result.Failure.has_value() ); @@ -260,8 +280,12 @@ TEST_CASE( "A reported replay seed reproduces exactly that trial", std::get<1>( value ).size() < 2; }; - const auto original = CheckProperty( - generator, predicate, PropertyOptions{ .Trials = 500, .Seed = 0x5EED } ); + const auto original = CheckProperty(generator, predicate, [&] { + PropertyOptions made; + made.Trials = 500; + made.Seed = 0x5EED; + return made; + }()); REQUIRE( original.Status == PropertyStatus::kFailed ); REQUIRE( original.Failure.has_value() ); // The failure was not on the first trial, so replay skips real work. @@ -273,12 +297,13 @@ TEST_CASE( "A reported replay seed reproduces exactly that trial", // A different root seed and trial count prove that only the replay seed // decides what runs. - const auto replayed = CheckProperty( - generator, - predicate, - PropertyOptions{ .Trials = 3, - .Seed = 1, - .ReplayTrialSeed = original.Failure->TrialSeed } ); + const auto replayed = CheckProperty(generator, predicate, [&] { + PropertyOptions made; + made.Trials = 3; + made.Seed = 1; + made.ReplayTrialSeed = original.Failure->TrialSeed; + return made; + }()); REQUIRE( replayed.Status == PropertyStatus::kFailed ); REQUIRE( replayed.Failure.has_value() ); CHECK( replayed.TrialsRun == 1 ); @@ -290,9 +315,16 @@ TEST_CASE( "A reported replay seed reproduces exactly that trial", // Replaying a seed whose trial passes reports one passing trial. const auto passing = CheckProperty( - Integer<int>( 0, 10 ), - []( int value ) { return value <= 10; }, - PropertyOptions{ .Trials = 50, .ReplayTrialSeed = 12345 } ); + Integer<int>(0, 10), + [](int value) { + return value <= 10; + }, + [&] { + PropertyOptions made; + made.Trials = 50; + made.ReplayTrialSeed = 12345; + return made; + }()); CHECK( passing.Succeeded() ); CHECK( passing.TrialsRun == 1 ); } diff --git a/tests/Progmasoft/Property.tests.cpp b/tests/Progmasoft/Property.tests.cpp index 5cec3979..9c4c95fb 100644 --- a/tests/Progmasoft/Property.tests.cpp +++ b/tests/Progmasoft/Property.tests.cpp @@ -63,11 +63,13 @@ TEST_CASE( "Integer generators preserve bounds and useful shrink order", Integer<int>( -100, 100 ).Shrink( 6 ); REQUIRE( !positiveShrinks.empty() ); CHECK( positiveShrinks.front() == 0 ); - CHECK( std::ranges::find( positiveShrinks, 5 ) != positiveShrinks.end() ); + CHECK(std::find(positiveShrinks.begin(), positiveShrinks.end(), 5) + != positiveShrinks.end()); const std::vector<int> negativeShrinks = generator.Shrink( -6 ); CHECK( negativeShrinks.front() == 0 ); - CHECK( std::ranges::find( negativeShrinks, -5 ) != negativeShrinks.end() ); + CHECK(std::find(negativeShrinks.begin(), negativeShrinks.end(), -5) + != negativeShrinks.end()); CHECK_THROWS_AS( Integer<int>( 5, -5 ), std::invalid_argument ); } @@ -93,8 +95,13 @@ TEST_CASE( "Properties count trials and reproduce their seed", using Progmasoft::Catch3::PropertyOptions; int checks = 0; - const PropertyOptions options{ - .Trials = 64, .Seed = 0xC0FFEE, .MaxShrinkSteps = 100 }; + const PropertyOptions options = [&] { + PropertyOptions made; + made.Trials = 64; + made.Seed = 0xC0FFEE; + made.MaxShrinkSteps = 100; + return made; + }(); const auto property = [&]( int value ) { ++checks; return value >= -100 && value <= 100; @@ -137,8 +144,16 @@ TEST_CASE( "Property failures shrink to and report a replayable counterexample", const auto result = CheckProperty( generator, - []( int value ) { return value >= 0; }, - PropertyOptions{ .Trials = 4, .Seed = 0xFACE, .MaxShrinkSteps = 20 } ); + [](int value) { + return value >= 0; + }, + [&] { + PropertyOptions made; + made.Trials = 4; + made.Seed = 0xFACE; + made.MaxShrinkSteps = 20; + return made; + }()); CHECK_FALSE( result.Succeeded() ); CHECK( result.Status == Progmasoft::Catch3::PropertyStatus::kFailed ); @@ -166,8 +181,16 @@ TEST_CASE( "Property shrink work is bounded", "[progmasoft][property]" ) { } ); const auto result = CheckProperty( generator, - []( int ) { return false; }, - PropertyOptions{ .Trials = 1, .Seed = 4, .MaxShrinkSteps = 3 } ); + [](int) { + return false; + }, + [&] { + PropertyOptions made; + made.Trials = 1; + made.Seed = 4; + made.MaxShrinkSteps = 3; + return made; + }()); REQUIRE( result.Failure.has_value() ); CHECK( result.Failure->ShrinkSteps == 3 ); @@ -198,8 +221,16 @@ TEST_CASE( []( const int& ) { return std::vector<int>{}; } ); const auto invalidOptions = CheckProperty( constantGenerator, - []( int ) { return true; }, - PropertyOptions{ .Trials = 0, .Seed = 1, .MaxShrinkSteps = 1 } ); + [](int) { + return true; + }, + [&] { + PropertyOptions made; + made.Trials = 0; + made.Seed = 1; + made.MaxShrinkSteps = 1; + return made; + }()); CHECK( invalidOptions.Status == PropertyStatus::kInvalidConfiguration ); } @@ -226,8 +257,15 @@ TEST_CASE( "Predicate exceptions are ordinary reproducible property failures", TEST_CASE( "Catch3 property assertions report successful runs", "[progmasoft][property]" ) { CATCH3_CHECK_PROPERTY( - Progmasoft::Catch3::Integer<int>( 1, 100 ), - []( int value ) { return value > 0; }, - Progmasoft::Catch3::PropertyOptions{ - .Trials = 25, .Seed = 42, .MaxShrinkSteps = 10 } ); + Progmasoft::Catch3::Integer<int>(1, 100), + [](int value) { + return value > 0; + }, + [&] { + Progmasoft::Catch3::PropertyOptions made; + made.Trials = 25; + made.Seed = 42; + made.MaxShrinkSteps = 10; + return made; + }()); } diff --git a/tests/Progmasoft/Results.tests.cpp b/tests/Progmasoft/Results.tests.cpp index ad52d311..a05a601d 100644 --- a/tests/Progmasoft/Results.tests.cpp +++ b/tests/Progmasoft/Results.tests.cpp @@ -207,7 +207,7 @@ TEST_CASE("JUnit XML keeps every attempt and marks flaky tests", CHECK(xml.find("<property name=\"random-seed\" value=\"42\" />") != std::string::npos); CHECK(xml.find("time=\"0.263500\"") != std::string::npos); - CHECK(xml.ends_with("</testsuites>\n")); + CHECK(xml.rfind("</testsuites>\n") == xml.size() - 14U); } TEST_CASE("JUnit XML replaces malformed UTF-8 and forbidden XML controls", diff --git a/tests/Progmasoft/Snapshot.tests.cpp b/tests/Progmasoft/Snapshot.tests.cpp index 65ee732e..c29cb143 100644 --- a/tests/Progmasoft/Snapshot.tests.cpp +++ b/tests/Progmasoft/Snapshot.tests.cpp @@ -42,10 +42,11 @@ TEST_CASE( "Snapshot comparison does not write during ordinary runs", using Progmasoft::Catch3::SnapshotStatus; const TemporarySnapshotDirectory directory; - const auto result = - CompareSnapshot( "greeting", - "hello\nworld\n", - SnapshotOptions{ .Directory = directory.Path } ); + const auto result = CompareSnapshot("greeting", "hello\nworld\n", [&] { + SnapshotOptions made; + made.Directory = directory.Path; + return made; + }()); CHECK( result.Status == SnapshotStatus::kMismatched ); CHECK_FALSE( result.Succeeded() ); @@ -62,10 +63,12 @@ TEST_CASE( "Snapshots normalize line endings and report precise differences", using Progmasoft::Catch3::SnapshotUpdateMode; const TemporarySnapshotDirectory directory; - const SnapshotOptions createOptions{ - .Directory = directory.Path, - .UpdateMode = SnapshotUpdateMode::kCreateMissing, - }; + const SnapshotOptions createOptions = [&] { + SnapshotOptions made; + made.Directory = directory.Path; + made.UpdateMode = SnapshotUpdateMode::kCreateMissing; + return made; + }(); const auto created = CompareSnapshot( "multiline", "one\ntwo\n", createOptions ); REQUIRE( created.Status == SnapshotStatus::kCreated ); @@ -76,10 +79,11 @@ TEST_CASE( "Snapshots normalize line endings and report precise differences", CHECK( normalized.Status == SnapshotStatus::kMatched ); CHECK( normalized.Expected == "one\ntwo\n" ); - const auto mismatch = - CompareSnapshot( "multiline", - "one\ntoo\n", - SnapshotOptions{ .Directory = directory.Path } ); + const auto mismatch = CompareSnapshot("multiline", "one\ntoo\n", [&] { + SnapshotOptions made; + made.Directory = directory.Path; + return made; + }()); CHECK( mismatch.Status == SnapshotStatus::kMismatched ); CHECK( mismatch.DifferenceLine == 2 ); CHECK( mismatch.DifferenceColumn == 2 ); @@ -94,10 +98,12 @@ TEST_CASE( "Snapshot creation and replacement require explicit update modes", using Progmasoft::Catch3::SnapshotUpdateMode; const TemporarySnapshotDirectory directory; - const SnapshotOptions createMissing{ - .Directory = directory.Path, - .UpdateMode = SnapshotUpdateMode::kCreateMissing, - }; + const SnapshotOptions createMissing = [&] { + SnapshotOptions made; + made.Directory = directory.Path; + made.UpdateMode = SnapshotUpdateMode::kCreateMissing; + return made; + }(); REQUIRE( CompareSnapshot( "answer", "first", createMissing ).Succeeded() ); const auto protectedMismatch = @@ -105,10 +111,12 @@ TEST_CASE( "Snapshot creation and replacement require explicit update modes", CHECK( protectedMismatch.Status == SnapshotStatus::kMismatched ); CHECK( protectedMismatch.Expected == "first" ); - const SnapshotOptions updateEverything{ - .Directory = directory.Path, - .UpdateMode = SnapshotUpdateMode::kAlways, - }; + const SnapshotOptions updateEverything = [&] { + SnapshotOptions made; + made.Directory = directory.Path; + made.UpdateMode = SnapshotUpdateMode::kAlways; + return made; + }(); const auto updated = CompareSnapshot( "answer", "second", updateEverything ); REQUIRE( updated.Status == SnapshotStatus::kUpdated ); @@ -125,7 +133,11 @@ TEST_CASE( "Snapshot names and I/O failures are returned as structured errors", using Progmasoft::Catch3::SnapshotUpdateMode; const TemporarySnapshotDirectory directory; - const SnapshotOptions options{ .Directory = directory.Path }; + const SnapshotOptions options = [&] { + SnapshotOptions made; + made.Directory = directory.Path; + return made; + }(); CHECK( CompareSnapshot( "../outside", "text", options ).Status == SnapshotStatus::kInvalidName ); CHECK( CompareSnapshot( "nested/name", "text", options ).Status == @@ -141,11 +153,12 @@ TEST_CASE( "Snapshot names and I/O failures are returned as structured errors", REQUIRE( output.good() ); output << "file"; } - const auto ioFailure = CompareSnapshot( - "snapshot", - "text", - SnapshotOptions{ .Directory = blockingFile, - .UpdateMode = SnapshotUpdateMode::kCreateMissing } ); + const auto ioFailure = CompareSnapshot("snapshot", "text", [&] { + SnapshotOptions made; + made.Directory = blockingFile; + made.UpdateMode = SnapshotUpdateMode::kCreateMissing; + return made; + }()); CHECK( ioFailure.Status == SnapshotStatus::kIoError ); CHECK_FALSE( ioFailure.Message.empty() ); } @@ -156,9 +169,11 @@ TEST_CASE( "Snapshot assertion macro reports successful explicit updates", CATCH3_CHECK_SNAPSHOT( "macro", "stable value", - ( Progmasoft::Catch3::SnapshotOptions{ - .Directory = directory.Path, - .UpdateMode = - Progmasoft::Catch3::SnapshotUpdateMode::kCreateMissing, - } ) ); + ([&] { + Progmasoft::Catch3::SnapshotOptions made; + made.Directory = directory.Path; + made.UpdateMode + = Progmasoft::Catch3::SnapshotUpdateMode::kCreateMissing; + return made; + }())); } diff --git a/tests/Progmasoft/Strategy.tests.cpp b/tests/Progmasoft/Strategy.tests.cpp index 5a1d5a2a..2bd49105 100644 --- a/tests/Progmasoft/Strategy.tests.cpp +++ b/tests/Progmasoft/Strategy.tests.cpp @@ -116,15 +116,23 @@ TEST_CASE( "Integer strategies respect every kind of range", TEST_CASE( "Float strategies stay finite and in range unless allowed", "[progmasoft][strategy]" ) { using Progmasoft::Catch3::FloatOptions; - const auto bounded = Gen::Floats<double>( - FloatOptions{ .Minimum = -2.5, .Maximum = 1000.0 } ); + const auto bounded = Gen::Floats<double>([&] { + FloatOptions made; + made.Minimum = -2.5; + made.Maximum = 1000.0; + return made; + }()); for ( double value : Sample( bounded, 3000, 6 ) ) { CHECK( std::isfinite( value ) ); CHECK( value >= -2.5 ); CHECK( value <= 1000.0 ); } - const auto everything = Gen::Floats<double>( - FloatOptions{ .AllowNaN = true, .AllowInfinity = true } ); + const auto everything = Gen::Floats<double>([&] { + FloatOptions made; + made.AllowNaN = true; + made.AllowInfinity = true; + return made; + }()); const auto values = Sample( everything, 3000, 7 ); CHECK( std::any_of( values.begin(), values.end(), []( double value ) { return std::isnan( value ); @@ -132,14 +140,22 @@ TEST_CASE( "Float strategies stay finite and in range unless allowed", CHECK( std::any_of( values.begin(), values.end(), []( double value ) { return std::isinf( value ); } ) ); - const auto positive = Gen::Floats<float>( - FloatOptions{ .Minimum = 1.0, .Maximum = 2.0 } ); + const auto positive = Gen::Floats<float>([&] { + FloatOptions made; + made.Minimum = 1.0; + made.Maximum = 2.0; + return made; + }()); const std::vector<std::uint64_t> zeros; ChoiceSource simplest( zeros, 0 ); CHECK( positive.Draw( simplest ) == 1.0F ); - CHECK_THROWS_AS( Gen::Floats<double>( FloatOptions{ .Minimum = 2.0, - .Maximum = 1.0 } ), - std::invalid_argument ); + CHECK_THROWS_AS(Gen::Floats<double>([&] { + FloatOptions made; + made.Minimum = 2.0; + made.Maximum = 1.0; + return made; + }()), + std::invalid_argument); } TEST_CASE( "Collection strategies respect their size ranges", diff --git a/tests/meson.build b/tests/meson.build index 340b61cf..95556f06 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -89,7 +89,7 @@ progmasoft_property_tests = executable( ], include_directories: '../src', dependencies: [catch3_with_main_dep], - override_options: ['cpp_std=c++20'], + override_options: ['cpp_std=c++17'], ) # Tests that misbehave on purpose, for the runner's integration tests. @@ -98,7 +98,7 @@ runner_fixture = executable( 'Progmasoft/RunnerFixture.cpp', include_directories: '../src', dependencies: [catch3_with_main_dep], - override_options: ['cpp_std=c++20'], + override_options: ['cpp_std=c++17'], ) test(