From 180380cfbcae00c37cad5b7e16aeae7caf821239 Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Mon, 12 Mar 2018 09:36:50 +0100 Subject: [PATCH] Move some experimental compilation tests to its own unit test --- test/playground/test-playground.cpp | 156 +----------------- test/unit-test/CMakeLists.txt | 1 + .../test-continuable-connection-noinst.cpp | 141 ++++++++++++++++ test/unit-test/test-continuable.hpp | 1 + 4 files changed, 144 insertions(+), 155 deletions(-) create mode 100644 test/unit-test/single/test-continuable-connection-noinst.cpp diff --git a/test/playground/test-playground.cpp b/test/playground/test-playground.cpp index 3ab7417..cdd60e4 100644 --- a/test/playground/test-playground.cpp +++ b/test/playground/test-playground.cpp @@ -20,162 +20,8 @@ SOFTWARE. **/ -#include -#include -#include -#include - #include -#include - -/* -static cti::continuable http_request(std::string url) { - return [url = std::move(url)](cti::promise promise) { - if (false) { - promise.set_value(""); - std::forward(promise)(""); - } - promise.set_exception(std::error_condition{}); - }; -} - -static auto http_request2(std::string url) { - return cti::make_continuable( - // ... - [url = std::move(url)](auto&& promise) { - if (false) { - promise.set_value(""); - std::forward(promise)(""); - } - promise.set_exception(std::error_condition{}); - }); -} - -static cti::continuable http_request3(std::string url) { - return [url = std::move(url)](auto&& promise) { - if (false) { - promise.set_value(""); - std::forward(promise)(""); - } - promise.set_exception(std::error_condition{}); - }; -} - -struct my_callable { - void operator()(std::string) && { - // ... - } - void operator()(cti::dispatch_error_tag, cti::error_type) && { - // ... - } -}; - -void old() { - http_request("github.com").next(my_callable{}); - - http_request("github.com") | [](std::string) { - // ... - return 0; - } | [] { - // ... - }; - - http_request2("github.com") - .then([](std::string) { - // ... - return 0; - }) - .then([](int) { - // ... - }) - .fail([](std::error_condition) { - // ... - }); - - (http_request("github.com") && http_request3("github.com")) - .then([](std::string, std::string) { - // ... - }) - .fail([](std::error_condition) { - // ... - }) - .apply([](auto&& me) { - // ... - return std::forward(me); - }); - - (http_request("github.com") || http_request("github.com")) - .then([](std::string) { - // ... - }) - .fail([](std::error_condition) { - // ... - }); - - (http_request("github.com") >> http_request("github.com")) - .then([](std::string, std::string) { - // ... - }) - .fail([](std::error_condition) { - // ... - }); -} -*/ - int main(int, char**) { - using namespace cti::detail; - - { - cti::when_seq( - cti::make_ready_continuable(0, 1), 2, //< See this plain value - cti::populate(cti::make_ready_continuable(3), - cti::make_ready_continuable(4)), - std::make_tuple(std::make_tuple(cti::make_ready_continuable(5)))) - .then([](int r0, int r1, int r2, std::vector r34, - std::tuple> r5) { - // ... - util::unused(r0, r1, r2, r34, r5); - }); - } - - auto v = cti::populate(cti::make_ready_continuable(8), - cti::make_ready_continuable(9)); - - cti::when_seq(v.begin(), v.end()).then([](auto o2) { - // ... - util::unused(o2); - }); - - cti::when_seq(cti::make_ready_continuable()) // ... - .then([] { - // ... - }); - - cti::when_seq() // ... - .then([] { - // ... - }); - - cti::when_seq(cti::make_exceptional_continuable(std::error_condition{})) - .fail([](auto) { - // ... - }); - - cti::when_all( - cti::make_ready_continuable(0, 1), 2, //< See this plain value - cti::populate(cti::make_ready_continuable(3), - cti::make_ready_continuable(4)), - std::make_tuple(std::make_tuple(cti::make_ready_continuable(5)))) - .then([](int r0, int r1, int r2, std::vector r34, - std::tuple> r5) { - // ... - util::unused(r0, r1, r2, r34, r5); - }); - - cti::when_any(cti::make_ready_continuable(22), - cti::make_ready_continuable(44)) - .then([](int) { - - }); + // ... } diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index c4f7908..192ca83 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -16,6 +16,7 @@ target_link_libraries(test-continuable-base continuable-features-noexcept) add_executable(test-continuable-single + ${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-connection-noinst ${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-flat-variant.cpp ${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-expected.cpp ${CMAKE_CURRENT_LIST_DIR}/single/test-continuable-traverse.cpp diff --git a/test/unit-test/single/test-continuable-connection-noinst.cpp b/test/unit-test/single/test-continuable-connection-noinst.cpp new file mode 100644 index 0000000..79b6c25 --- /dev/null +++ b/test/unit-test/single/test-continuable-connection-noinst.cpp @@ -0,0 +1,141 @@ + +/* + Copyright(c) 2015 - 2018 Denis Blank + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files(the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and / or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions : + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +**/ + +#include + +static cti::continuable http_request(std::string) { + return cti::make_ready_continuable(""); +} + +struct my_callable { + void operator()(std::string) && { + // ... + } + void operator()(cti::dispatch_error_tag, cti::error_type) && { + // ... + } +}; + +TEST(simple_compilation_tests, error_compile_tests) { + http_request("github.com").next(my_callable{}); + + http_request("github.com") | [](std::string) { + // ... + return 0; + } | [] { + // ... + }; + + http_request("github.com") + .then([](std::string) { + // ... + return 0; + }) + .then([](int) { + // ... + }) + .fail([](cti::error_type) { + // ... + }); + + (http_request("github.com") && http_request("github.com")) + .then([](std::string, std::string) { + // ... + }) + .fail([](cti::error_type) { + // ... + }) + .apply([](auto&& me) { + // ... + return std::forward(me); + }); + + (http_request("github.com") || http_request("github.com")) + .then([](std::string) { + // ... + }) + .fail([](cti::error_type) { + // ... + }); + + (http_request("github.com") >> http_request("github.com")) + .then([](std::string, std::string) { + // ... + }) + .fail([](cti::error_type) { + // ... + }); +} + +TEST(simple_compilation_tests, connection_compile_tests) { + + cti::when_seq( + cti::make_ready_continuable(0, 1), 2, //< See this plain value + cti::populate(cti::make_ready_continuable(3), + cti::make_ready_continuable(4)), + std::make_tuple(std::make_tuple(cti::make_ready_continuable(5)))) + .then([](int r0, int r1, int r2, std::vector r34, + std::tuple> r5) { + // ... + unused(r0, r1, r2, r34, r5); + }); + + auto v = cti::populate(cti::make_ready_continuable(8), + cti::make_ready_continuable(9)); + + cti::when_seq(v.begin(), v.end()).then([](auto) { + // ... + }); + + cti::when_seq(cti::make_ready_continuable()) // ... + .then([] { + // ... + }); + + cti::when_seq() // ... + .then([] { + // ... + }); + + cti::when_seq(cti::make_exceptional_continuable(cti::error_type{})) + .fail([](auto) { + // ... + }); + + cti::when_all( + cti::make_ready_continuable(0, 1), 2, //< See this plain value + cti::populate(cti::make_ready_continuable(3), + cti::make_ready_continuable(4)), + std::make_tuple(std::make_tuple(cti::make_ready_continuable(5)))) + .then([](int r0, int r1, int r2, std::vector r34, + std::tuple> r5) { + // ... + unused(r0, r1, r2, r34, r5); + }); + + cti::when_any(cti::make_ready_continuable(22), + cti::make_ready_continuable(44)) + .then([](int) { + // ... + }); +} diff --git a/test/unit-test/test-continuable.hpp b/test/unit-test/test-continuable.hpp index 768d343..92fcc69 100644 --- a/test/unit-test/test-continuable.hpp +++ b/test/unit-test/test-continuable.hpp @@ -35,6 +35,7 @@ #include using cti::detail::traits::identity; +using cti::detail::util::unused; inline auto to_hint(identity<> /*hint*/) { return identity{};