mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Simplify some tests in order to reduce heap usage while building
This commit is contained in:
parent
b8ff4c4c18
commit
457a9dca00
@ -8,7 +8,7 @@ if (PLATFORM EQUAL 64)
|
|||||||
add_definitions("-D_WIN64")
|
add_definitions("-D_WIN64")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP1 /bigobj")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /MP2 /bigobj")
|
||||||
|
|
||||||
if (TESTS_NO_EXCEPTIONS)
|
if (TESTS_NO_EXCEPTIONS)
|
||||||
add_definitions(-D_HAS_EXCEPTIONS=0)
|
add_definitions(-D_HAS_EXCEPTIONS=0)
|
||||||
|
|||||||
@ -31,98 +31,9 @@
|
|||||||
#ifndef CONTINUABLE_TESTING_HPP_INCLUDED__
|
#ifndef CONTINUABLE_TESTING_HPP_INCLUDED__
|
||||||
#define CONTINUABLE_TESTING_HPP_INCLUDED__
|
#define CONTINUABLE_TESTING_HPP_INCLUDED__
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include <continuable/detail/api.hpp>
|
||||||
|
#include <continuable/detail/testing.hpp>
|
||||||
#include <continuable/continuable-base.hpp>
|
#include <continuable/detail/traits.hpp>
|
||||||
|
|
||||||
namespace cti {
|
|
||||||
namespace detail {
|
|
||||||
namespace testing {
|
|
||||||
template <typename C> void assert_async_completion(C&& continuable) {
|
|
||||||
auto called = std::make_shared<bool>(false);
|
|
||||||
std::forward<C>(continuable).then([called](auto&&... args) {
|
|
||||||
ASSERT_FALSE(*called);
|
|
||||||
*called = true;
|
|
||||||
|
|
||||||
// Workaround for our known GCC bug.
|
|
||||||
util::unused(std::forward<decltype(args)>(args)...);
|
|
||||||
});
|
|
||||||
ASSERT_TRUE(*called);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename C> void assert_async_never_completed(C&& continuable) {
|
|
||||||
std::forward<C>(continuable).then([](auto&&... args) {
|
|
||||||
// Workaround for our known GCC bug.
|
|
||||||
util::unused(std::forward<decltype(args)>(args)...);
|
|
||||||
|
|
||||||
FAIL();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename C, typename V>
|
|
||||||
void assert_async_validation(C&& continuable, V&& validator) {
|
|
||||||
assert_async_completion(
|
|
||||||
std::forward<C>(continuable)
|
|
||||||
.then([validator =
|
|
||||||
std::forward<V>(validator)](auto&&... args) mutable {
|
|
||||||
|
|
||||||
validator(std::forward<decltype(args)>(args)...);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Expects that the continuable is finished with the given arguments
|
|
||||||
template <typename V, typename C, typename... Args>
|
|
||||||
void assert_async_binary_validation(V&& validator, C&& continuable,
|
|
||||||
Args&&... expected) {
|
|
||||||
assert_async_validation(std::forward<C>(continuable), [
|
|
||||||
expected_pack = std::make_tuple(std::forward<Args>(expected)...),
|
|
||||||
validator = std::forward<V>(validator)
|
|
||||||
](auto&&... args) mutable {
|
|
||||||
|
|
||||||
auto actual_pack = std::make_tuple(std::forward<decltype(args)>(args)...);
|
|
||||||
|
|
||||||
auto size = traits::pack_size_of(traits::identity_of(expected_pack));
|
|
||||||
|
|
||||||
static_assert(size.value == std::tuple_size<decltype(actual_pack)>::value,
|
|
||||||
"Async completion handler called with a different count "
|
|
||||||
"of arguments!");
|
|
||||||
|
|
||||||
traits::static_for_each_in(
|
|
||||||
std::make_index_sequence<size.value>{}, [&](auto current) mutable {
|
|
||||||
auto expected = std::get<current.value>(std::move(expected_pack));
|
|
||||||
auto actual = std::get<current.value>(std::move(actual_pack));
|
|
||||||
(void)current;
|
|
||||||
|
|
||||||
validator(expected, actual);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto expecting_eq_check() {
|
|
||||||
return [](auto expected, auto actual) { EXPECT_EQ(expected, actual); };
|
|
||||||
}
|
|
||||||
|
|
||||||
inline auto asserting_eq_check() {
|
|
||||||
return [](auto expected, auto actual) { ASSERT_EQ(expected, actual); };
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename C, typename... Args>
|
|
||||||
void assert_async_types(C&& continuable, traits::identity<Args...> expected) {
|
|
||||||
assert_async_validation(
|
|
||||||
std::forward<C>(continuable), [&](auto... actualPack) {
|
|
||||||
auto actual = traits::identity<decltype(actualPack)...>{};
|
|
||||||
util::unused(expected, actual,
|
|
||||||
std::forward<decltype(actualPack)>(actualPack)...);
|
|
||||||
|
|
||||||
static_assert(
|
|
||||||
std::is_same<std::decay_t<decltype(expected)>,
|
|
||||||
std::decay_t<decltype(actual)>>::value,
|
|
||||||
"The called arguments don't match with the expected ones!");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} // namespace testing
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace cti
|
|
||||||
|
|
||||||
/// Asserts that the final callback of the given continuable was called
|
/// Asserts that the final callback of the given continuable was called
|
||||||
/// with any result.
|
/// with any result.
|
||||||
|
|||||||
129
include/continuable/detail/testing.hpp
Normal file
129
include/continuable/detail/testing.hpp
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
/~` _ _ _|_. _ _ |_ | _
|
||||||
|
\_,(_)| | | || ||_|(_||_)|(/_
|
||||||
|
|
||||||
|
https://github.com/Naios/continuable
|
||||||
|
v2.0.0
|
||||||
|
|
||||||
|
Copyright(c) 2015 - 2017 Denis Blank <denis.blank at outlook dot com>
|
||||||
|
|
||||||
|
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.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef CONTINUABLE_DETAIL_TESTING_HPP_INCLUDED__
|
||||||
|
#define CONTINUABLE_DETAIL_TESTING_HPP_INCLUDED__
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <continuable/continuable-base.hpp>
|
||||||
|
|
||||||
|
namespace cti {
|
||||||
|
namespace detail {
|
||||||
|
namespace testing {
|
||||||
|
template <typename C>
|
||||||
|
void assert_async_completion(C&& continuable) {
|
||||||
|
auto called = std::make_shared<bool>(false);
|
||||||
|
std::forward<C>(continuable).then([called](auto&&... args) {
|
||||||
|
ASSERT_FALSE(*called);
|
||||||
|
*called = true;
|
||||||
|
|
||||||
|
// Workaround for our known GCC bug.
|
||||||
|
util::unused(std::forward<decltype(args)>(args)...);
|
||||||
|
});
|
||||||
|
ASSERT_TRUE(*called);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename C>
|
||||||
|
void assert_async_never_completed(C&& continuable) {
|
||||||
|
std::forward<C>(continuable).then([](auto&&... args) {
|
||||||
|
// Workaround for our known GCC bug.
|
||||||
|
util::unused(std::forward<decltype(args)>(args)...);
|
||||||
|
|
||||||
|
FAIL();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename C, typename V>
|
||||||
|
void assert_async_validation(C&& continuable, V&& validator) {
|
||||||
|
assert_async_completion(
|
||||||
|
std::forward<C>(continuable)
|
||||||
|
.then([validator =
|
||||||
|
std::forward<V>(validator)](auto&&... args) mutable {
|
||||||
|
|
||||||
|
validator(std::forward<decltype(args)>(args)...);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Expects that the continuable is finished with the given arguments
|
||||||
|
template <typename V, typename C, typename... Args>
|
||||||
|
void assert_async_binary_validation(V&& validator, C&& continuable,
|
||||||
|
Args&&... expected) {
|
||||||
|
assert_async_validation(std::forward<C>(continuable), [
|
||||||
|
expected_pack = std::make_tuple(std::forward<Args>(expected)...),
|
||||||
|
validator = std::forward<V>(validator)
|
||||||
|
](auto&&... args) mutable {
|
||||||
|
|
||||||
|
auto actual_pack = std::make_tuple(std::forward<decltype(args)>(args)...);
|
||||||
|
|
||||||
|
auto size = traits::pack_size_of(traits::identity_of(expected_pack));
|
||||||
|
|
||||||
|
static_assert(size.value == std::tuple_size<decltype(actual_pack)>::value,
|
||||||
|
"Async completion handler called with a different count "
|
||||||
|
"of arguments!");
|
||||||
|
|
||||||
|
traits::static_for_each_in(
|
||||||
|
std::make_index_sequence<size.value>{}, [&](auto current) mutable {
|
||||||
|
auto expected = std::get<current.value>(std::move(expected_pack));
|
||||||
|
auto actual = std::get<current.value>(std::move(actual_pack));
|
||||||
|
(void)current;
|
||||||
|
|
||||||
|
validator(expected, actual);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto expecting_eq_check() {
|
||||||
|
return [](auto expected, auto actual) { EXPECT_EQ(expected, actual); };
|
||||||
|
}
|
||||||
|
|
||||||
|
inline auto asserting_eq_check() {
|
||||||
|
return [](auto expected, auto actual) { ASSERT_EQ(expected, actual); };
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename C, typename... Args>
|
||||||
|
void assert_async_types(C&& continuable, traits::identity<Args...> expected) {
|
||||||
|
assert_async_validation(
|
||||||
|
std::forward<C>(continuable), [&](auto... actualPack) {
|
||||||
|
auto actual = traits::identity<decltype(actualPack)...>{};
|
||||||
|
util::unused(expected, actual,
|
||||||
|
std::forward<decltype(actualPack)>(actualPack)...);
|
||||||
|
|
||||||
|
static_assert(
|
||||||
|
std::is_same<std::decay_t<decltype(expected)>,
|
||||||
|
std::decay_t<decltype(actual)>>::value,
|
||||||
|
"The called arguments don't match with the expected ones!");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace detail
|
||||||
|
} // namespace cti
|
||||||
|
|
||||||
|
#endif // CONTINUABLE_DETAIL_TESTING_HPP_INCLUDED__
|
||||||
@ -13,6 +13,7 @@ set(LIB_SOURCES_DETAIL
|
|||||||
${CMAKE_SOURCE_DIR}/include/continuable/detail/traits.hpp
|
${CMAKE_SOURCE_DIR}/include/continuable/detail/traits.hpp
|
||||||
${CMAKE_SOURCE_DIR}/include/continuable/detail/transforms.hpp
|
${CMAKE_SOURCE_DIR}/include/continuable/detail/transforms.hpp
|
||||||
${CMAKE_SOURCE_DIR}/include/continuable/detail/types.hpp
|
${CMAKE_SOURCE_DIR}/include/continuable/detail/types.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/include/continuable/detail/testing.hpp
|
||||||
${CMAKE_SOURCE_DIR}/include/continuable/detail/util.hpp)
|
${CMAKE_SOURCE_DIR}/include/continuable/detail/util.hpp)
|
||||||
set(TEST
|
set(TEST
|
||||||
${CMAKE_CURRENT_LIST_DIR}/test-playground.cpp)
|
${CMAKE_CURRENT_LIST_DIR}/test-playground.cpp)
|
||||||
@ -28,6 +29,7 @@ source_group(test FILES ${TEST})
|
|||||||
|
|
||||||
target_link_libraries(test-playground
|
target_link_libraries(test-playground
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
gtest
|
||||||
continuable)
|
continuable)
|
||||||
|
|
||||||
target_compile_definitions(test-playground
|
target_compile_definitions(test-playground
|
||||||
|
|||||||
@ -23,13 +23,12 @@
|
|||||||
|
|
||||||
#include "test-continuable.hpp"
|
#include "test-continuable.hpp"
|
||||||
|
|
||||||
using namespace cti;
|
|
||||||
using namespace cti::detail;
|
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_chainable) {
|
TYPED_TEST(single_dimension_tests, are_chainable) {
|
||||||
EXPECT_ASYNC_RESULT(this->supply().then([] {
|
auto chain = this->supply().then([] {
|
||||||
return; // void
|
return; // void
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
ASSERT_ASYNC_TYPES(std::move(chain));
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_type_chainable) {
|
TYPED_TEST(single_dimension_tests, are_type_chainable) {
|
||||||
|
|||||||
@ -38,7 +38,6 @@ TYPED_TEST(single_dimension_tests, are_partial_callable) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST(single_dimension_tests, are_dispatchable) {
|
TYPED_TEST(single_dimension_tests, are_dispatchable) {
|
||||||
{
|
|
||||||
bool invoked = false;
|
bool invoked = false;
|
||||||
auto executor = [&](auto&& work) {
|
auto executor = [&](auto&& work) {
|
||||||
// We can move the worker object
|
// We can move the worker object
|
||||||
@ -57,5 +56,4 @@ TYPED_TEST(single_dimension_tests, are_dispatchable) {
|
|||||||
executor);
|
executor);
|
||||||
|
|
||||||
ASSERT_ASYNC_COMPLETION(std::move(chain));
|
ASSERT_ASYNC_COMPLETION(std::move(chain));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user