Change the expected behaviour of some GTest macros from expect -> assert

This commit is contained in:
Denis Blank 2017-03-04 14:10:22 +01:00
parent a2fa1c1ae2
commit 7ab7c726b6
2 changed files with 28 additions and 28 deletions

View File

@ -41,7 +41,7 @@ inline namespace abi_v1 {
/// \endcond /// \endcond
namespace detail { namespace detail {
namespace testing { namespace testing {
template <typename C> void expect_async_completion(C&& continuable) { template <typename C> void assert_async_completion(C&& continuable) {
auto called = std::make_shared<bool>(false); auto called = std::make_shared<bool>(false);
std::forward<C>(continuable).then([called](auto&&... args) { std::forward<C>(continuable).then([called](auto&&... args) {
ASSERT_FALSE(*called); ASSERT_FALSE(*called);
@ -50,10 +50,10 @@ template <typename C> void expect_async_completion(C&& continuable) {
// Workaround for our known GCC bug. // Workaround for our known GCC bug.
util::unused(std::forward<decltype(args)>(args)...); util::unused(std::forward<decltype(args)>(args)...);
}); });
EXPECT_TRUE(*called); ASSERT_TRUE(*called);
} }
template <typename C> void expect_async_incomplete(C&& continuable) { template <typename C> void assert_async_never_completed(C&& continuable) {
std::forward<C>(continuable).then([](auto&&... args) { std::forward<C>(continuable).then([](auto&&... args) {
// Workaround for our known GCC bug. // Workaround for our known GCC bug.
util::unused(std::forward<decltype(args)>(args)...); util::unused(std::forward<decltype(args)>(args)...);
@ -63,8 +63,8 @@ template <typename C> void expect_async_incomplete(C&& continuable) {
} }
template <typename C, typename V> template <typename C, typename V>
void expect_async_validation(C&& continuable, V&& validator) { void assert_async_validation(C&& continuable, V&& validator) {
expect_async_completion( assert_async_completion(
std::forward<C>(continuable) std::forward<C>(continuable)
.then([validator = .then([validator =
std::forward<V>(validator)](auto&&... args) mutable { std::forward<V>(validator)](auto&&... args) mutable {
@ -75,9 +75,9 @@ void expect_async_validation(C&& continuable, V&& validator) {
/// Expects that the continuable is finished with the given arguments /// Expects that the continuable is finished with the given arguments
template <typename V, typename C, typename... Args> template <typename V, typename C, typename... Args>
void expect_async_binary_validation(V&& validator, C&& continuable, void assert_async_binary_validation(V&& validator, C&& continuable,
Args&&... expected) { Args&&... expected) {
expect_async_validation(std::forward<C>(continuable), [ assert_async_validation(std::forward<C>(continuable), [
expected_pack = std::make_tuple(std::forward<Args>(expected)...), expected_pack = std::make_tuple(std::forward<Args>(expected)...),
validator = std::forward<V>(validator) validator = std::forward<V>(validator)
](auto&&... args) mutable { ](auto&&... args) mutable {
@ -111,7 +111,7 @@ inline auto asserting_eq_check() {
template <typename C, typename... Args> template <typename C, typename... Args>
void assert_async_types(C&& continuable, util::identity<Args...> expected) { void assert_async_types(C&& continuable, util::identity<Args...> expected) {
expect_async_validation( assert_async_validation(
std::forward<C>(continuable), [&](auto... actualPack) { std::forward<C>(continuable), [&](auto... actualPack) {
auto actual = util::identity<decltype(actualPack)...>{}; auto actual = util::identity<decltype(actualPack)...>{};
util::unused(expected, actual, util::unused(expected, actual,
@ -130,26 +130,26 @@ void assert_async_types(C&& continuable, util::identity<Args...> expected) {
/// \endcond /// \endcond
} // end namespace cti } // end namespace cti
/// Expects the final callback of the given continuable to be called /// Asserts that the final callback of the given continuable was called
/// with any result. /// with any result.
/// ///
/// \since version 1.0.0 /// \since version 1.0.0
#define EXPECT_ASYNC_COMPLETION(CONTINUABLE) \ #define ASSERT_ASYNC_COMPLETION(CONTINUABLE) \
cti::detail::testing::expect_async_completion(CONTINUABLE); cti::detail::testing::assert_async_completion(CONTINUABLE);
/// Expects the final callback of the given continuable is never called /// Asserts that the final callback of the given continuable is never called
/// with any result. /// with any result.
/// ///
/// \since version 1.0.0 /// \since version 1.0.0
#define EXPECT_ASYNC_INCOMPLETE(CONTINUABLE) \ #define ASSERT_ASYNC_NEVER_COMPLETED(CONTINUABLE) \
cti::detail::testing::expect_async_incomplete(CONTINUABLE); cti::detail::testing::assert_async_never_completed(CONTINUABLE);
/// Expects the continuation to be called and forwards it's arguments to /// Expects the continuation to be called and forwards it's arguments to
/// the given validator which can then do assertions on the result. /// the given validator which can then do assertions on the result.
#define EXPECT_ASYNC_VALIDATION(CONTINUABLE, VALIDATOR) \ #define ASSERT_ASYNC_VALIDATION(CONTINUABLE, VALIDATOR) \
cti::detail::testing::expect_async_validation(CONTINUABLE, VALIDATOR); cti::detail::testing::assert_async_validation(CONTINUABLE, VALIDATOR);
/// Expects the continuation to be called and forwards it's arguments to /// Asserts that the continuation was called and forwards it's arguments to
/// the given validator which can then do assertions on the result. /// the given validator which can then do assertions on the result.
/// ///
/// A validator consists of a binary consumer with a signature as in /// A validator consists of a binary consumer with a signature as in
@ -168,7 +168,7 @@ void assert_async_types(C&& continuable, util::identity<Args...> expected) {
/// EXPECT_EQ(expected, actual); /// EXPECT_EQ(expected, actual);
/// }; /// };
/// ///
/// EXPECT_ASYNC_BINARY_VALIDATION(validator, async_get("hello"), "hello") /// ASSERT_ASYNC_BINARY_VALIDATION(validator, async_get("hello"), "hello")
/// ``` /// ```
/// ///
/// The validator is called for every expecting and actual result. /// The validator is called for every expecting and actual result.
@ -177,8 +177,8 @@ void assert_async_types(C&& continuable, util::identity<Args...> expected) {
/// relying on custom validation logic. /// relying on custom validation logic.
/// ///
/// \since version 1.0.0 /// \since version 1.0.0
#define EXPECT_ASYNC_BINARY_VALIDATION(VALIDATOR, ...) \ #define ASSERT_ASYNC_BINARY_VALIDATION(VALIDATOR, ...) \
cti::detail::testing::expect_async_binary_validation(VALIDATOR, __VA_ARGS__); cti::detail::testing::assert_async_binary_validation(VALIDATOR, __VA_ARGS__);
/// Expects that the continuable is finished with the given result /// Expects that the continuable is finished with the given result
/// ///
@ -191,7 +191,7 @@ void assert_async_types(C&& continuable, util::identity<Args...> expected) {
/// ///
/// \since version 1.0.0 /// \since version 1.0.0
#define EXPECT_ASYNC_RESULT(...) \ #define EXPECT_ASYNC_RESULT(...) \
EXPECT_ASYNC_BINARY_VALIDATION(cti::detail::testing::expecting_eq_check(), \ ASSERT_ASYNC_BINARY_VALIDATION(cti::detail::testing::expecting_eq_check(), \
__VA_ARGS__) __VA_ARGS__)
/// Asserts that the continuable is finished with the given result /// Asserts that the continuable is finished with the given result
@ -205,7 +205,7 @@ void assert_async_types(C&& continuable, util::identity<Args...> expected) {
/// ///
/// \since version 1.0.0 /// \since version 1.0.0
#define ASSERT_ASYNC_RESULT(...) \ #define ASSERT_ASYNC_RESULT(...) \
EXPECT_ASYNC_BINARY_VALIDATION(cti::detail::testing::asserting_eq_check(), \ ASSERT_ASYNC_BINARY_VALIDATION(cti::detail::testing::asserting_eq_check(), \
__VA_ARGS__) __VA_ARGS__)
/// Asserts that the continuable is finished with the given type of arguments /// Asserts that the continuable is finished with the given type of arguments

View File

@ -35,7 +35,7 @@ TYPED_TEST(single_dimension_tests, are_called_on_destruct) {
ASSERT_FALSE(allowed); ASSERT_FALSE(allowed);
allowed = true; allowed = true;
EXPECT_ASYNC_COMPLETION(std::move(continuable)); ASSERT_ASYNC_COMPLETION(std::move(continuable));
} }
EXPECT_ASYNC_RESULT(this->supply()); EXPECT_ASYNC_RESULT(this->supply());
@ -62,31 +62,31 @@ TYPED_TEST(single_dimension_tests, are_incomplete_when_frozen) {
{ {
auto chain = this->supply(); auto chain = this->supply();
chain.freeze(); chain.freeze();
EXPECT_ASYNC_INCOMPLETE(std::move(chain)); ASSERT_ASYNC_NEVER_COMPLETED(std::move(chain));
} }
{ {
auto chain = this->supply(); auto chain = this->supply();
chain.freeze(); chain.freeze();
EXPECT_ASYNC_INCOMPLETE(std::move(chain).then(this->supply())); ASSERT_ASYNC_NEVER_COMPLETED(std::move(chain).then(this->supply()));
} }
} }
TYPED_TEST(single_dimension_tests, are_not_dispatched_when_frozen) { TYPED_TEST(single_dimension_tests, are_not_dispatched_when_frozen) {
auto chain = assert_invocation(this); auto chain = assert_invocation(this);
chain.freeze(); chain.freeze();
EXPECT_ASYNC_INCOMPLETE(std::move(chain)); ASSERT_ASYNC_NEVER_COMPLETED(std::move(chain));
} }
TYPED_TEST(single_dimension_tests, are_not_finished_when_not_continued) { TYPED_TEST(single_dimension_tests, are_not_finished_when_not_continued) {
{ {
auto chain = create_incomplete(this); auto chain = create_incomplete(this);
EXPECT_ASYNC_INCOMPLETE(std::move(chain)); ASSERT_ASYNC_NEVER_COMPLETED(std::move(chain));
} }
{ {
auto chain = create_incomplete(this); auto chain = create_incomplete(this);
EXPECT_ASYNC_INCOMPLETE(std::move(chain).then(this->supply())); ASSERT_ASYNC_NEVER_COMPLETED(std::move(chain).then(this->supply()));
} }
} }