diff --git a/CMakeLists.txt b/CMakeLists.txt index 8df9107..7d419a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,6 @@ if(EXPECTED_BUILD_TESTS) FetchContent_MakeAvailable(Catch2) file(GLOB test-sources CONFIGURE_DEPENDS tests/*.cpp) - list(FILTER test-sources EXCLUDE REGEX "tests/test.cpp") add_executable(${PROJECT_NAME}-tests "${test-sources}") target_compile_options(${PROJECT_NAME}-tests PRIVATE $<$>:-Wall -Wextra>) diff --git a/tests/assignment.cpp b/test/assignment.cpp similarity index 92% rename from tests/assignment.cpp rename to test/assignment.cpp index 2d6bf6b..cf52c57 100644 --- a/tests/assignment.cpp +++ b/test/assignment.cpp @@ -69,7 +69,7 @@ TEST_CASE("Assignment deletion", "[assignment.deletion]") { except_move(except_move &&) noexcept(false){}; except_move &operator=(const except_move &) = default; }; - tl::expected e3 = {}; - tl::expected e4 = {}; + [[maybe_unused]] tl::expected e3 = {}; + [[maybe_unused]] tl::expected e4 = {}; // e3 = e4; should not compile } diff --git a/tests/bases.cpp b/test/bases.cpp similarity index 98% rename from tests/bases.cpp rename to test/bases.cpp index 7189307..c5eb571 100644 --- a/tests/bases.cpp +++ b/test/bases.cpp @@ -39,8 +39,8 @@ TEST_CASE("Triviality", "[bases.triviality]") { struct T { T(const T&){} T(T&&) {}; - T& operator=(const T&) {} - T& operator=(T&&) {}; + T& operator=(const T&) { return *this; } + T& operator=(T&&) { return *this; }; ~T(){} }; REQUIRE(!std::is_trivially_copy_constructible>::value); diff --git a/tests/constexpr.cpp b/test/constexpr.cpp similarity index 100% rename from tests/constexpr.cpp rename to test/constexpr.cpp diff --git a/tests/constructors.cpp b/test/constructors.cpp similarity index 100% rename from tests/constructors.cpp rename to test/constructors.cpp diff --git a/tests/emplace.cpp b/test/emplace.cpp similarity index 100% rename from tests/emplace.cpp rename to test/emplace.cpp diff --git a/tests/extensions.cpp b/test/extensions.cpp similarity index 94% rename from tests/extensions.cpp rename to test/extensions.cpp index 9670f90..0fe26c1 100644 --- a/tests/extensions.cpp +++ b/test/extensions.cpp @@ -1,15 +1,17 @@ #include #include +// catch also defines this exact name +#undef STATIC_REQUIRE #define TOKENPASTE(x, y) x##y #define TOKENPASTE2(x, y) TOKENPASTE(x, y) #define STATIC_REQUIRE(e) \ - constexpr bool TOKENPASTE2(rqure, __LINE__) = e; \ + [[maybe_unused]] constexpr bool TOKENPASTE2(rqure, __LINE__) = e; \ REQUIRE(e); TEST_CASE("Map extensions", "[extensions.map]") { auto mul2 = [](int a) { return a * 2; }; - auto ret_void = [](int a) {}; + auto ret_void = [](int) {}; { tl::expected e = 21; @@ -143,7 +145,7 @@ TEST_CASE("Map extensions", "[extensions.map]") { TEST_CASE("Map error extensions", "[extensions.map_error]") { auto mul2 = [](int a) { return a * 2; }; - auto ret_void = [](int a) {}; + auto ret_void = [](int) {}; { tl::expected e = 21; @@ -252,8 +254,8 @@ TEST_CASE("Map error extensions", "[extensions.map_error]") { } TEST_CASE("And then extensions", "[extensions.and_then]") { - auto succeed = [](int a) { return tl::expected(21 * 2); }; - auto fail = [](int a) { return tl::expected(tl::unexpect, 17); }; + auto succeed = [](int) { return tl::expected(21 * 2); }; + auto fail = [](int) { return tl::expected(tl::unexpect, 17); }; { tl::expected e = 21; @@ -370,11 +372,11 @@ TEST_CASE("And then extensions", "[extensions.and_then]") { TEST_CASE("or_else", "[extensions.or_else]") { using eptr = std::unique_ptr; - auto succeed = [](int a) { return tl::expected(21 * 2); }; - auto succeedptr = [](eptr e) { return tl::expected(21*2);}; - auto fail = [](int a) { return tl::expected(tl::unexpect, 17);}; + auto succeed = [](int) { return tl::expected(21 * 2); }; + auto succeedptr = [](eptr) { return tl::expected(21*2);}; + auto fail = [](int) { return tl::expected(tl::unexpect, 17);}; auto efail = [](eptr e) { *e = 17;return tl::expected(tl::unexpect, std::move(e));}; - auto failptr = [](eptr e) { return tl::expected(tl::unexpect, std::move(e));}; + [[maybe_unused]] auto failptr = [](eptr e) { return tl::expected(tl::unexpect, std::move(e));}; auto failvoid = [](int) {}; auto failvoidptr = [](const eptr&) { /* don't consume */}; auto consumeptr = [](eptr) {}; @@ -568,7 +570,7 @@ struct F { TEST_CASE("14", "[issue.14]") { auto res = tl::expected{tl::unexpect, F{}}; - res.map_error([](F f) { + res.map_error([](F) { }); } diff --git a/tests/issues.cpp b/test/issues.cpp similarity index 91% rename from tests/issues.cpp rename to test/issues.cpp index e9f99da..129785b 100644 --- a/tests/issues.cpp +++ b/test/issues.cpp @@ -15,7 +15,7 @@ TEST_CASE("Issue 1", "[issues.1]") { getInt1(); } tl::expected operation1() { return 42; } -tl::expected operation2(int const val) { return "Bananas"; } +tl::expected operation2(int const) { return "Bananas"; } TEST_CASE("Issue 17", "[issues.17]") { auto const intermediate_result = operation1(); @@ -67,7 +67,7 @@ struct i31{ }; TEST_CASE("Issue 31", "[issues.31]") { const tl::expected a = i31{42}; - a->i; + (void)a->i; tl::expected< void, std::string > result; tl::expected< void, std::string > result2 = result; @@ -77,7 +77,7 @@ TEST_CASE("Issue 31", "[issues.31]") { TEST_CASE("Issue 33", "[issues.33]") { tl::expected res {tl::unexpect, 0}; REQUIRE(!res); - res = res.map_error([](int i) { return 42; }); + res = res.map_error([](int) { return 42; }); REQUIRE(res.error() == 42); } diff --git a/tests/main.cpp b/test/main.cpp similarity index 100% rename from tests/main.cpp rename to test/main.cpp diff --git a/tests/noexcept.cpp b/test/noexcept.cpp similarity index 100% rename from tests/noexcept.cpp rename to test/noexcept.cpp diff --git a/tests/observers.cpp b/test/observers.cpp similarity index 100% rename from tests/observers.cpp rename to test/observers.cpp diff --git a/tests/relops.cpp b/test/relops.cpp similarity index 100% rename from tests/relops.cpp rename to test/relops.cpp diff --git a/tests/swap.cpp b/test/swap.cpp similarity index 100% rename from tests/swap.cpp rename to test/swap.cpp diff --git a/tests/test.cpp b/tests/test.cpp deleted file mode 100644 index 0338ccb..0000000 --- a/tests/test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -struct no_throw { - no_throw(std::string i) : i(i) {} - std::string i; -}; -struct canthrow_move { - canthrow_move(std::string i) : i(i) {} - canthrow_move(canthrow_move const &) = default; - canthrow_move(canthrow_move &&other) noexcept(false) : i(other.i) {} - canthrow_move &operator=(canthrow_move &&) = default; - std::string i; -}; - -bool should_throw = false; -struct willthrow_move { - willthrow_move(std::string i) : i(i) {} - willthrow_move(willthrow_move const &) = default; - willthrow_move(willthrow_move &&other) : i(other.i) { - if (should_throw) - throw 0; - } - willthrow_move &operator=(willthrow_move &&) = default; - std::string i; -}; - -int main() { - std::string s1 = "abcdefghijklmnopqrstuvwxyz"; - std::string s2 = "zyxwvutsrqponmlkjihgfedcbaxxx"; - tl::expected a{s1}; - tl::expected b{tl::unexpect, s2}; - should_throw = 1; - swap(a, b); -} \ No newline at end of file