From 8a35d6443bfa5b36af5608c577658df21ee33e27 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 8 Jun 2023 09:24:15 +0200 Subject: tests: convert compile-time constant assertions Assertions that validate necessarily compile-time constant properties should be implemented using STATIC_REQUIRES*, since this will make sure that the test suite won't event build if there are low-level semantic issues in the library. --- source/tests/src/arithmetic.cpp | 40 ++++++++++----------- source/tests/src/conversion.cpp | 14 ++++---- source/tests/src/derivation_clause.cpp | 62 ++++++++++++++++---------------- source/tests/src/equality_comparison.cpp | 12 +++---- source/tests/src/hash.cpp | 6 ++-- 5 files changed, 67 insertions(+), 67 deletions(-) diff --git a/source/tests/src/arithmetic.cpp b/source/tests/src/arithmetic.cpp index 5048393..09b0c4a 100644 --- a/source/tests/src/arithmetic.cpp +++ b/source/tests/src/arithmetic.cpp @@ -23,7 +23,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("it is not addable") { - REQUIRE(!nt::impl::is_addable_v); + STATIC_REQUIRE(!nt::impl::is_addable_v); } } @@ -33,7 +33,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("it is addable") { - REQUIRE(nt::impl::is_addable_v); + STATIC_REQUIRE(nt::impl::is_addable_v); } } @@ -43,7 +43,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("it is not addable") { - REQUIRE(!nt::impl::is_addable_v == nt::impl::is_addable_v); + STATIC_REQUIRE(!nt::impl::is_addable_v == nt::impl::is_addable_v); } } @@ -53,7 +53,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("it is addable") { - REQUIRE(nt::impl::is_addable_v == nt::impl::is_addable_v); + STATIC_REQUIRE(nt::impl::is_addable_v == nt::impl::is_addable_v); } } @@ -63,7 +63,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("addition produces the same type") { - REQUIRE(std::is_same_v() + std::declval())>); + STATIC_REQUIRE(std::is_same_v() + std::declval())>); } } @@ -96,7 +96,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is not subtractable") { - REQUIRE(!nt::impl::is_subtractable_v); + STATIC_REQUIRE(!nt::impl::is_subtractable_v); } } @@ -106,7 +106,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is subtractable") { - REQUIRE(nt::impl::is_subtractable_v); + STATIC_REQUIRE(nt::impl::is_subtractable_v); } } @@ -116,7 +116,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is not addable") { - REQUIRE(!nt::impl::is_subtractable_v); + STATIC_REQUIRE(!nt::impl::is_subtractable_v); } } @@ -126,7 +126,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is subtractable") { - REQUIRE(nt::impl::is_subtractable_v); + STATIC_REQUIRE(nt::impl::is_subtractable_v); } } @@ -136,7 +136,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("subtraction produces the same type") { - REQUIRE(std::is_same_v() - std::declval())>); + STATIC_REQUIRE(std::is_same_v() - std::declval())>); } } @@ -169,7 +169,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is not multipliable") { - REQUIRE(!nt::impl::is_multipliable_v); + STATIC_REQUIRE(!nt::impl::is_multipliable_v); } } @@ -179,7 +179,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is multipliable") { - REQUIRE(nt::impl::is_multipliable_v); + STATIC_REQUIRE(nt::impl::is_multipliable_v); } } @@ -189,7 +189,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is not multipliable") { - REQUIRE(!nt::impl::is_multipliable_v); + STATIC_REQUIRE(!nt::impl::is_multipliable_v); } } @@ -199,7 +199,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is multipliable") { - REQUIRE(nt::impl::is_multipliable_v); + STATIC_REQUIRE(nt::impl::is_multipliable_v); } } @@ -209,7 +209,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("multiplication produces the same type") { - REQUIRE(std::is_same_v() * std::declval())>); + STATIC_REQUIRE(std::is_same_v() * std::declval())>); } } @@ -242,7 +242,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is not divisible") { - REQUIRE(!nt::impl::is_dividable_v); + STATIC_REQUIRE(!nt::impl::is_dividable_v); } } @@ -252,7 +252,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is divisible") { - REQUIRE(nt::impl::is_dividable_v); + STATIC_REQUIRE(nt::impl::is_dividable_v); } } @@ -262,7 +262,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is not divisible") { - REQUIRE(!nt::impl::is_dividable_v); + STATIC_REQUIRE(!nt::impl::is_dividable_v); } } @@ -272,7 +272,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is divisible") { - REQUIRE(nt::impl::is_dividable_v); + STATIC_REQUIRE(nt::impl::is_dividable_v); } } @@ -282,7 +282,7 @@ SCENARIO("Division", "[arithmetic]") THEN("division produces the same type") { - REQUIRE(std::is_same_v() / std::declval())>); + STATIC_REQUIRE(std::is_same_v() / std::declval())>); } } diff --git a/source/tests/src/conversion.cpp b/source/tests/src/conversion.cpp index 436d951..bcda06d 100644 --- a/source/tests/src/conversion.cpp +++ b/source/tests/src/conversion.cpp @@ -20,7 +20,7 @@ TEMPLATE_LIST_TEST_CASE("Scenario: Implicit Conversions", "[conversion]", test_t THEN("it is not implicitly convertible to the base type") { - REQUIRE(!std::is_convertible_v); + STATIC_REQUIRE(!std::is_convertible_v); } } @@ -30,7 +30,7 @@ TEMPLATE_LIST_TEST_CASE("Scenario: Implicit Conversions", "[conversion]", test_t THEN("it is implicitly convertible to the base type") { - REQUIRE(std::is_convertible_v); + STATIC_REQUIRE(std::is_convertible_v); } } } @@ -43,7 +43,7 @@ TEMPLATE_LIST_TEST_CASE("Scenario: Decay", "[conversion]", test_types) THEN("it's decay() member function returns a value of the base type") { - REQUIRE(std::is_same_v().decay())>); + STATIC_REQUIRE(std::is_same_v().decay())>); } } @@ -89,7 +89,7 @@ SCENARIO("Nothrow Decay") THEN("the decay member function is nothrow-invokable") { - REQUIRE(noexcept(std::declval().decay())); + STATIC_REQUIRE(noexcept(std::declval().decay())); } } @@ -99,7 +99,7 @@ SCENARIO("Nothrow Decay") THEN("the decay member function is not nothrow-invokable") { - REQUIRE(!noexcept(std::declval().decay())); + STATIC_REQUIRE(!noexcept(std::declval().decay())); } } } @@ -119,7 +119,7 @@ SCENARIO("Nothrow Conversion") THEN("the decay member function is nothrow-invokable") { - REQUIRE(noexcept(std::declval().operator int())); + STATIC_REQUIRE(noexcept(std::declval().operator int())); } } @@ -129,7 +129,7 @@ SCENARIO("Nothrow Conversion") THEN("the decay member function is not nothrow-invokable") { - REQUIRE(!noexcept(std::declval().operator strange_type())); + STATIC_REQUIRE(!noexcept(std::declval().operator strange_type())); } } } diff --git a/source/tests/src/derivation_clause.cpp b/source/tests/src/derivation_clause.cpp index dd1edb9..ddf28e7 100644 --- a/source/tests/src/derivation_clause.cpp +++ b/source/tests/src/derivation_clause.cpp @@ -13,7 +13,7 @@ SCENARIO("Derivation Clause", "[infrastructure]") THEN("it doesn't contain any derivable") { - REQUIRE_FALSE(clause(nt::Show)); + STATIC_REQUIRE_FALSE(clause(nt::Show)); } } @@ -23,42 +23,42 @@ SCENARIO("Derivation Clause", "[infrastructure]") THEN("it doesn't contain nt::EqBase") { - REQUIRE_FALSE(clause(nt::EqBase)); + STATIC_REQUIRE_FALSE(clause(nt::EqBase)); } THEN("it contains nt::Show") { - REQUIRE(clause(nt::Show)); + STATIC_REQUIRE(clause(nt::Show)); } THEN("it copares less-than one containing nt::Show and nt::EqBase") { - REQUIRE(clause < deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE(clause < deriving(nt::Show, nt::EqBase)); } THEN("it does not compare less-than one conataining only nt::EqBase") { - REQUIRE_FALSE(clause < deriving(nt::EqBase)); + STATIC_REQUIRE_FALSE(clause < deriving(nt::EqBase)); } THEN("it does not compare greater-than one conataining only nt::EqBase") { - REQUIRE_FALSE(clause > deriving(nt::EqBase)); + STATIC_REQUIRE_FALSE(clause > deriving(nt::EqBase)); } THEN("it does not compare equal-to one containiing only nt::Arithmetic") { - REQUIRE_FALSE(clause == deriving(nt::Arithmetic)); + STATIC_REQUIRE_FALSE(clause == deriving(nt::Arithmetic)); } THEN("it compares not-equal-to one containing only nt::Arithmetic") { - REQUIRE(clause != deriving(nt::Arithmetic)); + STATIC_REQUIRE(clause != deriving(nt::Arithmetic)); } THEN("it compares less-than-equal to one containing both nt::Show and nt::EqBase") { - REQUIRE(clause <= deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE(clause <= deriving(nt::Show, nt::EqBase)); } } @@ -68,112 +68,112 @@ SCENARIO("Derivation Clause", "[infrastructure]") THEN("it contains nt::EqBase") { - REQUIRE(clause(nt::EqBase)); + STATIC_REQUIRE(clause(nt::EqBase)); } THEN("it contains nt::Show") { - REQUIRE(clause(nt::Show)); + STATIC_REQUIRE(clause(nt::Show)); } THEN("it contains both nt::Show and nt::EqBase") { - REQUIRE(clause(nt::Show, nt::EqBase)); + STATIC_REQUIRE(clause(nt::Show, nt::EqBase)); } THEN("it does not contain nt::Arithmetic") { - REQUIRE_FALSE(clause(nt::Arithmetic)); + STATIC_REQUIRE_FALSE(clause(nt::Arithmetic)); } THEN("it does not contain both nt::Arithmetic and nt::Show") { - REQUIRE_FALSE(clause(nt::Arithmetic, nt::Show)); + STATIC_REQUIRE_FALSE(clause(nt::Arithmetic, nt::Show)); } THEN("it does not compare less-than one containing nt::Show and nt::EqBase") { - REQUIRE_FALSE(clause < deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE_FALSE(clause < deriving(nt::Show, nt::EqBase)); } THEN("it does not compare less-than one containing nt::EqBase and nt::Show") { - REQUIRE_FALSE(clause < deriving(nt::EqBase, nt::Show)); + STATIC_REQUIRE_FALSE(clause < deriving(nt::EqBase, nt::Show)); } THEN("it compares greater-than one containing only nt::Show") { - REQUIRE(clause > deriving(nt::Show)); + STATIC_REQUIRE(clause > deriving(nt::Show)); } THEN("it does not compare greater-than one containing both nt::Show and nt::EqBase") { - REQUIRE_FALSE(clause > deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE_FALSE(clause > deriving(nt::Show, nt::EqBase)); } THEN("it does not compare greater-than one containing both nt::EqBase and nt::Show") { - REQUIRE_FALSE(clause > deriving(nt::EqBase, nt::Show)); + STATIC_REQUIRE_FALSE(clause > deriving(nt::EqBase, nt::Show)); } THEN("it compares equal-to one containing both nt::Show and nt::EqBase") { - REQUIRE(clause == deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE(clause == deriving(nt::Show, nt::EqBase)); } THEN("it compares equal-to one containing both nt::EqBase and nt::Show") { - REQUIRE(clause == deriving(nt::EqBase, nt::Show)); + STATIC_REQUIRE(clause == deriving(nt::EqBase, nt::Show)); } THEN("it does not compare equal-to one containiing only nt::Arithmetic") { - REQUIRE_FALSE(clause == deriving(nt::Arithmetic)); + STATIC_REQUIRE_FALSE(clause == deriving(nt::Arithmetic)); } THEN("it does not compare equal-to one containiing all nt::Show, nt::EqBase, and nt::Arithmetic") { - REQUIRE_FALSE(clause == deriving(nt::Show, nt::EqBase, nt::Arithmetic)); + STATIC_REQUIRE_FALSE(clause == deriving(nt::Show, nt::EqBase, nt::Arithmetic)); } THEN("it does not compare not-equal-to one containing both nt::Show and nt::EqBase") { - REQUIRE_FALSE(clause != deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE_FALSE(clause != deriving(nt::Show, nt::EqBase)); } THEN("it does not compare not-equal-to one containing both nt::Show and nt::EqBase") { - REQUIRE_FALSE(clause != deriving(nt::EqBase, nt::Show)); + STATIC_REQUIRE_FALSE(clause != deriving(nt::EqBase, nt::Show)); } THEN("it compares not-equal-to one containing only nt::Arithmetic") { - REQUIRE(clause != deriving(nt::Arithmetic)); + STATIC_REQUIRE(clause != deriving(nt::Arithmetic)); } THEN("it compares less-than-equal to one containing both nt::Show and nt::EqBase") { - REQUIRE(clause <= deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE(clause <= deriving(nt::Show, nt::EqBase)); } THEN("a derivation clause containing only nt::Arithmetic does not compare less-than-equal to it") { - REQUIRE_FALSE(deriving(nt::Arithmetic) <= clause); + STATIC_REQUIRE_FALSE(deriving(nt::Arithmetic) <= clause); } THEN("it compares greather-than-equal to one containing only nt::Show") { - REQUIRE(clause >= deriving(nt::Show)); + STATIC_REQUIRE(clause >= deriving(nt::Show)); } THEN("it compares greather-than-equal to one containing both nt::Show and nt::EqBase") { - REQUIRE(clause >= deriving(nt::Show, nt::EqBase)); + STATIC_REQUIRE(clause >= deriving(nt::Show, nt::EqBase)); } THEN("it does not compare greather-than-eqaul to one containing only nt::Arithmetic") { - REQUIRE_FALSE(clause >= deriving(nt::Arithmetic)); + STATIC_REQUIRE_FALSE(clause >= deriving(nt::Arithmetic)); } } } diff --git a/source/tests/src/equality_comparison.cpp b/source/tests/src/equality_comparison.cpp index 0c4055c..d857d9b 100644 --- a/source/tests/src/equality_comparison.cpp +++ b/source/tests/src/equality_comparison.cpp @@ -36,12 +36,12 @@ SCENARIO("Equality Comparison", "[compare]") THEN("equality comparison returns bool") { - REQUIRE(std::is_same_v() == std::declval())>); + STATIC_REQUIRE(std::is_same_v() == std::declval())>); } THEN("inequality comparison returns bool") { - REQUIRE(std::is_same_v() != std::declval())>); + STATIC_REQUIRE(std::is_same_v() != std::declval())>); } } @@ -69,12 +69,12 @@ SCENARIO("Equality Comparison", "[compare]") THEN("it is nothrow-equality-comparable") { - REQUIRE(noexcept(std::declval() == std::declval())); + STATIC_REQUIRE(noexcept(std::declval() == std::declval())); } THEN("it is nothrow-inequality-comparable") { - REQUIRE(noexcept(std::declval() != std::declval())); + STATIC_REQUIRE(noexcept(std::declval() != std::declval())); } } @@ -93,12 +93,12 @@ SCENARIO("Equality Comparison", "[compare]") THEN("it is not nothrow-equality-comparable") { - REQUIRE_FALSE(noexcept(std::declval() == std::declval())); + STATIC_REQUIRE_FALSE(noexcept(std::declval() == std::declval())); } THEN("it is not nothrow-inequality-comparable") { - REQUIRE_FALSE(noexcept(std::declval() != std::declval())); + STATIC_REQUIRE_FALSE(noexcept(std::declval() != std::declval())); } } } diff --git a/source/tests/src/hash.cpp b/source/tests/src/hash.cpp index 173770a..e3f624f 100644 --- a/source/tests/src/hash.cpp +++ b/source/tests/src/hash.cpp @@ -15,7 +15,7 @@ SCENARIO("Hash", "[hash]") THEN("it is not hashable") { - REQUIRE_FALSE(nt::impl::is_hashable_v); + STATIC_REQUIRE_FALSE(nt::impl::is_hashable_v); } } @@ -25,7 +25,7 @@ SCENARIO("Hash", "[hash]") THEN("it is hashable") { - REQUIRE(nt::impl::is_hashable_v); + STATIC_REQUIRE(nt::impl::is_hashable_v); } } @@ -38,7 +38,7 @@ SCENARIO("Hash", "[hash]") THEN("it is not hashable") { - REQUIRE_FALSE(nt::impl::is_hashable_v); + STATIC_REQUIRE_FALSE(nt::impl::is_hashable_v); } } -- cgit v1.2.3