Upgrade to C++17

This commit is contained in:
Chris Thrasher
2025-09-21 13:23:25 -06:00
parent dc3a4ea41a
commit 9c089788ab
92 changed files with 428 additions and 913 deletions

View File

@@ -194,15 +194,15 @@ TEST_CASE("#1403", "[compilation]") {
}
TEST_CASE("Optionally static assertions", "[compilation]") {
STATIC_REQUIRE( std::is_void<void>::value );
STATIC_REQUIRE_FALSE( std::is_void<int>::value );
STATIC_CHECK( std::is_void<void>::value );
STATIC_CHECK_FALSE( std::is_void<int>::value );
STATIC_REQUIRE( std::is_void_v<void> );
STATIC_REQUIRE_FALSE( std::is_void_v<int> );
STATIC_CHECK( std::is_void_v<void> );
STATIC_CHECK_FALSE( std::is_void_v<int> );
}
TEST_CASE("#1548", "[compilation]") {
using namespace bar;
REQUIRE(std::is_same<TypeList<int>, TypeList<int>>::value);
REQUIRE(std::is_same_v<TypeList<int>, TypeList<int>>);
}
// #925

View File

@@ -193,13 +193,13 @@ TEST_CASE("Generators -- adapters", "[generators][generic]") {
TEST_CASE("Random generator", "[generators][approvals]") {
SECTION("Infer int from integral arguments") {
auto val = GENERATE(take(4, random(0, 1)));
STATIC_REQUIRE(std::is_same<decltype(val), int>::value);
STATIC_REQUIRE(std::is_same_v<decltype(val), int>);
REQUIRE(0 <= val);
REQUIRE(val <= 1);
}
SECTION("Infer double from double arguments") {
auto val = GENERATE(take(4, random(0., 1.)));
STATIC_REQUIRE(std::is_same<decltype(val), double>::value);
STATIC_REQUIRE(std::is_same_v<decltype(val), double>);
REQUIRE(0. <= val);
REQUIRE(val < 1);
}

View File

@@ -879,10 +879,10 @@ TEST_CASE( "Combining concrete matchers does not use templated matchers",
using Catch::Matchers::StartsWith;
STATIC_REQUIRE(
std::is_same<decltype( StartsWith( "foo" ) ||
std::is_same_v<decltype( StartsWith( "foo" ) ||
( StartsWith( "bar" ) && EndsWith( "bar" ) &&
!EndsWith( "foo" ) ) ),
Catch::Matchers::Detail::MatchAnyOf<std::string>>::value );
Catch::Matchers::Detail::MatchAnyOf<std::string>> );
}
struct MatcherA : Catch::Matchers::MatcherGenericBase {
@@ -910,25 +910,25 @@ struct MatcherD : Catch::Matchers::MatcherGenericBase {
TEST_CASE( "Combining only templated matchers", "[matchers][templated]" ) {
STATIC_REQUIRE(
std::is_same<decltype( MatcherA() || MatcherB() ),
std::is_same_v<decltype( MatcherA() || MatcherB() ),
Catch::Matchers::Detail::
MatchAnyOfGeneric<MatcherA, MatcherB>>::value );
MatchAnyOfGeneric<MatcherA, MatcherB>> );
REQUIRE_THAT( 1, MatcherA() || MatcherB() );
STATIC_REQUIRE(
std::is_same<decltype( MatcherA() && MatcherB() ),
std::is_same_v<decltype( MatcherA() && MatcherB() ),
Catch::Matchers::Detail::
MatchAllOfGeneric<MatcherA, MatcherB>>::value );
MatchAllOfGeneric<MatcherA, MatcherB>> );
REQUIRE_THAT( 1, MatcherA() && MatcherB() );
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( MatcherA() || !MatcherB() ),
Catch::Matchers::Detail::MatchAnyOfGeneric<
MatcherA,
Catch::Matchers::Detail::MatchNotOfGeneric<MatcherB>>>::value );
Catch::Matchers::Detail::MatchNotOfGeneric<MatcherB>>> );
REQUIRE_THAT( 1, MatcherA() || !MatcherB() );
}
@@ -937,30 +937,29 @@ TEST_CASE( "Combining MatchAnyOfGeneric does not nest",
"[matchers][templated]" ) {
// MatchAnyOfGeneric LHS + some matcher RHS
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( ( MatcherA() || MatcherB() ) || MatcherC() ),
Catch::Matchers::Detail::
MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC>>::value );
MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC>> );
REQUIRE_THAT( 1, ( MatcherA() || MatcherB() ) || MatcherC() );
// some matcher LHS + MatchAnyOfGeneric RHS
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( MatcherA() || ( MatcherB() || MatcherC() ) ),
Catch::Matchers::Detail::
MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC>>::value );
MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC>> );
REQUIRE_THAT( 1, MatcherA() || ( MatcherB() || MatcherC() ) );
// MatchAnyOfGeneric LHS + MatchAnyOfGeneric RHS
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( ( MatcherA() || MatcherB() ) ||
( MatcherC() || MatcherD() ) ),
Catch::Matchers::Detail::
MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC, MatcherD>>::
value );
MatchAnyOfGeneric<MatcherA, MatcherB, MatcherC, MatcherD>>);
REQUIRE_THAT(
1, ( MatcherA() || MatcherB() ) || ( MatcherC() || MatcherD() ) );
@@ -970,30 +969,29 @@ TEST_CASE( "Combining MatchAllOfGeneric does not nest",
"[matchers][templated]" ) {
// MatchAllOfGeneric lhs + some matcher RHS
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( ( MatcherA() && MatcherB() ) && MatcherC() ),
Catch::Matchers::Detail::
MatchAllOfGeneric<MatcherA, MatcherB, MatcherC>>::value );
MatchAllOfGeneric<MatcherA, MatcherB, MatcherC>> );
REQUIRE_THAT( 1, ( MatcherA() && MatcherB() ) && MatcherC() );
// some matcher LHS + MatchAllOfGeneric RSH
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( MatcherA() && ( MatcherB() && MatcherC() ) ),
Catch::Matchers::Detail::
MatchAllOfGeneric<MatcherA, MatcherB, MatcherC>>::value );
MatchAllOfGeneric<MatcherA, MatcherB, MatcherC>> );
REQUIRE_THAT( 1, MatcherA() && ( MatcherB() && MatcherC() ) );
// MatchAllOfGeneric LHS + MatchAllOfGeneric RHS
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( ( MatcherA() && MatcherB() ) &&
( MatcherC() && MatcherD() ) ),
Catch::Matchers::Detail::
MatchAllOfGeneric<MatcherA, MatcherB, MatcherC, MatcherD>>::
value );
MatchAllOfGeneric<MatcherA, MatcherB, MatcherC, MatcherD>>);
REQUIRE_THAT(
1, ( MatcherA() && MatcherB() ) && ( MatcherC() && MatcherD() ) );
@@ -1002,26 +1000,26 @@ TEST_CASE( "Combining MatchAllOfGeneric does not nest",
TEST_CASE( "Combining MatchNotOfGeneric does not nest",
"[matchers][templated]" ) {
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( !MatcherA() ),
Catch::Matchers::Detail::MatchNotOfGeneric<MatcherA>>::value );
Catch::Matchers::Detail::MatchNotOfGeneric<MatcherA>> );
REQUIRE_THAT( 0, !MatcherA() );
STATIC_REQUIRE(
std::is_same<decltype( !!MatcherA() ), MatcherA const&>::value );
std::is_same_v<decltype( !!MatcherA() ), MatcherA const&> );
REQUIRE_THAT( 1, !!MatcherA() );
STATIC_REQUIRE(
std::is_same<
std::is_same_v<
decltype( !!!MatcherA() ),
Catch::Matchers::Detail::MatchNotOfGeneric<MatcherA>>::value );
Catch::Matchers::Detail::MatchNotOfGeneric<MatcherA>> );
REQUIRE_THAT( 0, !!!MatcherA() );
STATIC_REQUIRE(
std::is_same<decltype( !!!!MatcherA() ), MatcherA const&>::value );
std::is_same_v<decltype( !!!!MatcherA() ), MatcherA const&> );
REQUIRE_THAT( 1, !!!!MatcherA() );
}

View File

@@ -123,7 +123,7 @@ TEST_CASE("Basic use of the Empty range matcher", "[matchers][templated][empty]"
REQUIRE_THAT(non_empty_vec, !IsEmpty());
std::list<std::list<std::list<int>>> inner_lists_are_empty;
inner_lists_are_empty.push_back({});
inner_lists_are_empty.emplace_back();
REQUIRE_THAT(inner_lists_are_empty, !IsEmpty());
REQUIRE_THAT(inner_lists_are_empty.front(), IsEmpty());
}
@@ -592,11 +592,6 @@ TEST_CASE("All/Any/None True matchers support types with ADL begin",
}
}
// Range loop iterating over range with different types for begin and end is a
// C++17 feature, and GCC refuses to compile such code unless the lang mode is
// set to C++17 or later.
#if defined(CATCH_CPP17_OR_GREATER)
TEST_CASE( "The quantifier range matchers support types with different types returned from begin and end",
"[matchers][templated][quantifiers][approvals]" ) {
using Catch::Matchers::AllMatch;
@@ -656,8 +651,6 @@ TEST_CASE( "RangeContains supports ranges with different types returned from "
REQUIRE_THAT( diff_types, Contains( LessThanMatcher( size_t( 4 ) ) ) );
}
#endif
TEST_CASE( "Usage of RangeEquals range matcher", "[matchers][templated][quantifiers]" ) {
using Catch::Matchers::RangeEquals;
@@ -849,8 +842,8 @@ static constexpr bool ContainerIsRandomAccess( const Container& ) {
using array_iter_category = typename std::iterator_traits<
typename Container::iterator>::iterator_category;
return std::is_base_of<std::random_access_iterator_tag,
array_iter_category>::value;
return std::is_base_of_v<std::random_access_iterator_tag,
array_iter_category>;
}
TEST_CASE( "Type conversions of RangeEquals and similar",
@@ -933,4 +926,4 @@ TEST_CASE( "Type conversions of RangeEquals and similar",
UnorderedRangeEquals( array_a_plus_1, close_enough ) );
}
}
}
}

View File

@@ -389,13 +389,13 @@ TEMPLATE_PRODUCT_TEST_CASE_SIG("A Template product test case with array signatur
}
TEMPLATE_PRODUCT_TEST_CASE("Product with differing arities", "[template][product]", std::tuple, (int, (int, double), (int, double, float))) {
REQUIRE(std::tuple_size<TestType>::value >= 1);
REQUIRE(std::tuple_size_v<TestType> >= 1);
}
using MyTypes = std::tuple<int, char, float>;
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside std::tuple", "[template][list]", MyTypes)
{
REQUIRE(std::is_arithmetic<TestType>::value);
REQUIRE(std::is_arithmetic_v<TestType>);
}
struct NonDefaultConstructibleType {
@@ -405,7 +405,7 @@ struct NonDefaultConstructibleType {
using MyNonDefaultConstructibleTypes = std::tuple<NonDefaultConstructibleType, float>;
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside non-default-constructible std::tuple", "[template][list]", MyNonDefaultConstructibleTypes)
{
REQUIRE(std::is_trivially_copyable<TestType>::value);
REQUIRE(std::is_trivially_copyable_v<TestType>);
}
struct NonCopyableAndNonMovableType {
@@ -420,7 +420,7 @@ struct NonCopyableAndNonMovableType {
using NonCopyableAndNonMovableTypes = std::tuple<NonCopyableAndNonMovableType, float>;
TEMPLATE_LIST_TEST_CASE("Template test case with test types specified inside non-copyable and non-movable std::tuple", "[template][list]", NonCopyableAndNonMovableTypes)
{
REQUIRE(std::is_default_constructible<TestType>::value);
REQUIRE(std::is_default_constructible_v<TestType>);
}
// https://github.com/philsquared/Catch/issues/166

View File

@@ -8,8 +8,6 @@
#include <catch2/catch_test_macros.hpp>
#if defined(CATCH_CONFIG_CPP17_BYTE)
TEST_CASE( "std::byte -> toString", "[toString][byte][approvals]" ) {
using type = std::byte;
REQUIRE( "0" == ::Catch::Detail::stringify( type{ 0 } ) );
@@ -19,5 +17,3 @@ TEST_CASE( "std::vector<std::byte> -> toString", "[toString][byte][approvals]" )
using type = std::vector<std::byte>;
REQUIRE( "{ 0, 1, 2 }" == ::Catch::Detail::stringify( type{ std::byte{0}, std::byte{1}, std::byte{2} } ) );
}
#endif // CATCH_INTERNAL_CONFIG_CPP17_BYTE

View File

@@ -106,8 +106,6 @@ TEST_CASE("Static arrays are convertible to string", "[toString]") {
}
}
#ifdef CATCH_CONFIG_CPP17_STRING_VIEW
TEST_CASE("String views are stringified like other strings", "[toString][approvals]") {
std::string_view view{"abc"};
CHECK(Catch::Detail::stringify(view) == R"("abc")");
@@ -116,8 +114,6 @@ TEST_CASE("String views are stringified like other strings", "[toString][approva
CHECK(Catch::Detail::stringify(arr) == R"({ "abc" })");
}
#endif
TEST_CASE("Precision of floating point stringification can be set", "[toString][floatingPoint]") {
SECTION("Floats") {
using sm = Catch::StringMaker<float>;

View File

@@ -9,8 +9,6 @@
#define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
#include <catch2/catch_test_macros.hpp>
#if defined(CATCH_CONFIG_CPP17_OPTIONAL)
TEST_CASE( "std::optional<int> -> toString", "[toString][optional][approvals]" ) {
using type = std::optional<int>;
REQUIRE( "{ }" == ::Catch::Detail::stringify( type{} ) );
@@ -31,5 +29,3 @@ TEST_CASE( "std::vector<std::optional<int> > -> toString", "[toString][optional]
TEST_CASE( "std::nullopt -> toString", "[toString][optional][approvals]" ) {
REQUIRE( "{ }" == ::Catch::Detail::stringify( std::nullopt ) );
}
#endif // CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL

View File

@@ -21,7 +21,7 @@ TEST_CASE( "std::pair<int,const std::string> -> toString", "[toString][pair]" )
TEST_CASE( "std::vector<std::pair<std::string,int> > -> toString", "[toString][pair]" ) {
std::vector<std::pair<std::string,int> > pr;
pr.push_back( std::make_pair("green", 55 ) );
pr.emplace_back( "green", 55 );
REQUIRE( ::Catch::Detail::stringify( pr ) == "{ { \"green\", 55 } }" );
}

View File

@@ -9,8 +9,6 @@
#define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
#include <catch2/catch_test_macros.hpp>
#if defined(CATCH_CONFIG_CPP17_VARIANT)
#include <string>
#include <variant>
@@ -95,5 +93,3 @@ TEST_CASE( "variant<nullptr,int,const char *>", "[toString][variant][approvals]"
CHECK( "42" == ::Catch::Detail::stringify(type{42}) );
CHECK( "\"Catch me\"" == ::Catch::Detail::stringify(type{"Catch me"}) );
}
#endif // CATCH_INTERNAL_CONFIG_CPP17_VARIANT