diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-06-08 09:24:15 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-06-08 09:24:21 +0200 |
| commit | 8a35d6443bfa5b36af5608c577658df21ee33e27 (patch) | |
| tree | efc6496f25ceb614d084591b47bcd14b16c84cea | |
| parent | fa17a4d3c998f00ce9102265c1d81d414e7c971c (diff) | |
| download | newtype-8a35d6443bfa5b36af5608c577658df21ee33e27.tar.xz newtype-8a35d6443bfa5b36af5608c577658df21ee33e27.zip | |
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.
| -rw-r--r-- | source/tests/src/arithmetic.cpp | 40 | ||||
| -rw-r--r-- | source/tests/src/conversion.cpp | 14 | ||||
| -rw-r--r-- | source/tests/src/derivation_clause.cpp | 62 | ||||
| -rw-r--r-- | source/tests/src/equality_comparison.cpp | 12 | ||||
| -rw-r--r-- | 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<type_alias>); + STATIC_REQUIRE(!nt::impl::is_addable_v<type_alias>); } } @@ -33,7 +33,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("it is addable") { - REQUIRE(nt::impl::is_addable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_addable_v<type_alias>); } } @@ -43,7 +43,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("it is not addable") { - REQUIRE(!nt::impl::is_addable_v<addable_type> == nt::impl::is_addable_v<type_alias>); + STATIC_REQUIRE(!nt::impl::is_addable_v<addable_type> == nt::impl::is_addable_v<type_alias>); } } @@ -53,7 +53,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("it is addable") { - REQUIRE(nt::impl::is_addable_v<addable_type> == nt::impl::is_addable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_addable_v<addable_type> == nt::impl::is_addable_v<type_alias>); } } @@ -63,7 +63,7 @@ SCENARIO("Addition", "[arithmetic]") THEN("addition produces the same type") { - REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() + std::declval<type_alias const &>())>); + STATIC_REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() + std::declval<type_alias const &>())>); } } @@ -96,7 +96,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is not subtractable") { - REQUIRE(!nt::impl::is_subtractable_v<type_alias>); + STATIC_REQUIRE(!nt::impl::is_subtractable_v<type_alias>); } } @@ -106,7 +106,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is subtractable") { - REQUIRE(nt::impl::is_subtractable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_subtractable_v<type_alias>); } } @@ -116,7 +116,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is not addable") { - REQUIRE(!nt::impl::is_subtractable_v<type_alias>); + STATIC_REQUIRE(!nt::impl::is_subtractable_v<type_alias>); } } @@ -126,7 +126,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("it is subtractable") { - REQUIRE(nt::impl::is_subtractable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_subtractable_v<type_alias>); } } @@ -136,7 +136,7 @@ SCENARIO("Subtraction", "[arithmetic]") THEN("subtraction produces the same type") { - REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() - std::declval<type_alias const &>())>); + STATIC_REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() - std::declval<type_alias const &>())>); } } @@ -169,7 +169,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is not multipliable") { - REQUIRE(!nt::impl::is_multipliable_v<type_alias>); + STATIC_REQUIRE(!nt::impl::is_multipliable_v<type_alias>); } } @@ -179,7 +179,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is multipliable") { - REQUIRE(nt::impl::is_multipliable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_multipliable_v<type_alias>); } } @@ -189,7 +189,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is not multipliable") { - REQUIRE(!nt::impl::is_multipliable_v<type_alias>); + STATIC_REQUIRE(!nt::impl::is_multipliable_v<type_alias>); } } @@ -199,7 +199,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("it is multipliable") { - REQUIRE(nt::impl::is_multipliable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_multipliable_v<type_alias>); } } @@ -209,7 +209,7 @@ SCENARIO("Multiplication", "[arithmetic]") THEN("multiplication produces the same type") { - REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() * std::declval<type_alias const &>())>); + STATIC_REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() * std::declval<type_alias const &>())>); } } @@ -242,7 +242,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is not divisible") { - REQUIRE(!nt::impl::is_dividable_v<type_alias>); + STATIC_REQUIRE(!nt::impl::is_dividable_v<type_alias>); } } @@ -252,7 +252,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is divisible") { - REQUIRE(nt::impl::is_dividable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_dividable_v<type_alias>); } } @@ -262,7 +262,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is not divisible") { - REQUIRE(!nt::impl::is_dividable_v<type_alias>); + STATIC_REQUIRE(!nt::impl::is_dividable_v<type_alias>); } } @@ -272,7 +272,7 @@ SCENARIO("Division", "[arithmetic]") THEN("it is divisible") { - REQUIRE(nt::impl::is_dividable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_dividable_v<type_alias>); } } @@ -282,7 +282,7 @@ SCENARIO("Division", "[arithmetic]") THEN("division produces the same type") { - REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() / std::declval<type_alias const &>())>); + STATIC_REQUIRE(std::is_same_v<type_alias, decltype(std::declval<type_alias const &>() / std::declval<type_alias const &>())>); } } 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<type_alias, TestType>); + STATIC_REQUIRE(!std::is_convertible_v<type_alias, TestType>); } } @@ -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<type_alias, TestType>); + STATIC_REQUIRE(std::is_convertible_v<type_alias, TestType>); } } } @@ -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<TestType, decltype(std::declval<type_alias>().decay())>); + STATIC_REQUIRE(std::is_same_v<TestType, decltype(std::declval<type_alias>().decay())>); } } @@ -89,7 +89,7 @@ SCENARIO("Nothrow Decay") THEN("the decay member function is nothrow-invokable") { - REQUIRE(noexcept(std::declval<type_alias>().decay())); + STATIC_REQUIRE(noexcept(std::declval<type_alias>().decay())); } } @@ -99,7 +99,7 @@ SCENARIO("Nothrow Decay") THEN("the decay member function is not nothrow-invokable") { - REQUIRE(!noexcept(std::declval<type_alias>().decay())); + STATIC_REQUIRE(!noexcept(std::declval<type_alias>().decay())); } } } @@ -119,7 +119,7 @@ SCENARIO("Nothrow Conversion") THEN("the decay member function is nothrow-invokable") { - REQUIRE(noexcept(std::declval<type_alias>().operator int())); + STATIC_REQUIRE(noexcept(std::declval<type_alias>().operator int())); } } @@ -129,7 +129,7 @@ SCENARIO("Nothrow Conversion") THEN("the decay member function is not nothrow-invokable") { - REQUIRE(!noexcept(std::declval<type_alias>().operator strange_type())); + STATIC_REQUIRE(!noexcept(std::declval<type_alias>().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<bool, decltype(std::declval<type_alias>() == std::declval<type_alias>())>); + STATIC_REQUIRE(std::is_same_v<bool, decltype(std::declval<type_alias>() == std::declval<type_alias>())>); } THEN("inequality comparison returns bool") { - REQUIRE(std::is_same_v<bool, decltype(std::declval<type_alias>() != std::declval<type_alias>())>); + STATIC_REQUIRE(std::is_same_v<bool, decltype(std::declval<type_alias>() != std::declval<type_alias>())>); } } @@ -69,12 +69,12 @@ SCENARIO("Equality Comparison", "[compare]") THEN("it is nothrow-equality-comparable") { - REQUIRE(noexcept(std::declval<type_alias>() == std::declval<type_alias>())); + STATIC_REQUIRE(noexcept(std::declval<type_alias>() == std::declval<type_alias>())); } THEN("it is nothrow-inequality-comparable") { - REQUIRE(noexcept(std::declval<type_alias>() != std::declval<type_alias>())); + STATIC_REQUIRE(noexcept(std::declval<type_alias>() != std::declval<type_alias>())); } } @@ -93,12 +93,12 @@ SCENARIO("Equality Comparison", "[compare]") THEN("it is not nothrow-equality-comparable") { - REQUIRE_FALSE(noexcept(std::declval<type_alias>() == std::declval<type_alias>())); + STATIC_REQUIRE_FALSE(noexcept(std::declval<type_alias>() == std::declval<type_alias>())); } THEN("it is not nothrow-inequality-comparable") { - REQUIRE_FALSE(noexcept(std::declval<type_alias>() != std::declval<type_alias>())); + STATIC_REQUIRE_FALSE(noexcept(std::declval<type_alias>() != std::declval<type_alias>())); } } } 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<type_alias>); + STATIC_REQUIRE_FALSE(nt::impl::is_hashable_v<type_alias>); } } @@ -25,7 +25,7 @@ SCENARIO("Hash", "[hash]") THEN("it is hashable") { - REQUIRE(nt::impl::is_hashable_v<type_alias>); + STATIC_REQUIRE(nt::impl::is_hashable_v<type_alias>); } } @@ -38,7 +38,7 @@ SCENARIO("Hash", "[hash]") THEN("it is not hashable") { - REQUIRE_FALSE(nt::impl::is_hashable_v<type_alias>); + STATIC_REQUIRE_FALSE(nt::impl::is_hashable_v<type_alias>); } } |
