Skip to content

Commit

Permalink
switched to boost.test
Browse files Browse the repository at this point in the history
  • Loading branch information
klemens-morgenstern committed Oct 18, 2023
1 parent a73e60a commit a0ca8a4
Show file tree
Hide file tree
Showing 30 changed files with 680 additions and 7,719 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ else()
if (BOOST_COBALT_USE_BOOST_CONTAINER)
find_package(Boost REQUIRED container)
endif()
if (BOOST_COBALT_BUILD_TESTS)
find_package(Boost REQUIRED unit_test_framework)
endif()
include_directories(include)
endif()

Expand Down
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ target_link_libraries(boost_cobalt_static_tests Boost::cobalt)
add_executable(boost_cobalt_main main.cpp)
add_executable(boost_cobalt_main_compile main_compile.cpp)
add_executable(boost_cobalt_basic_tests
async_for.cpp doctest.cpp promise.cpp with.cpp op.cpp handler.cpp join.cpp race.cpp this_coro.cpp leaf.cpp
async_for.cpp test_main.cpp promise.cpp with.cpp op.cpp handler.cpp join.cpp race.cpp this_coro.cpp leaf.cpp
channel.cpp generator.cpp run.cpp task.cpp gather.cpp wait_group.cpp wrappers.cpp left_race.cpp
strand.cpp fork.cpp thread.cpp any_completion_handler.cpp detached.cpp monotonic_resource.cpp sbo_resource.cpp)

target_link_libraries(boost_cobalt_main Boost::cobalt)
target_link_libraries(boost_cobalt_main_compile Boost::cobalt)
target_link_libraries(boost_cobalt_basic_tests Boost::cobalt)
target_link_libraries(boost_cobalt_basic_tests Boost::cobalt Boost::unit_test_framework)

add_test(NAME boost_cobalt_main COMMAND boost_cobalt_main)
add_test(NAME boost_cobalt_basic_tests COMMAND boost_cobalt_basic_tests)
Expand Down
2 changes: 1 addition & 1 deletion test/Jamfile.jam
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ project : requirements

import testing ;

lib test_impl : doctest.cpp /boost//cobalt :
lib test_impl : test_main.cpp /boost//cobalt :
<link>static
;

Expand Down
6 changes: 3 additions & 3 deletions test/any_completion_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace cobalt = boost::cobalt;

TEST_SUITE_BEGIN("any_completion_token");
BOOST_AUTO_TEST_SUITE(any_completion_token);

void cobalt_sleep_impl(
boost::asio::any_completion_handler<void(boost::system::error_code)> handler,
Expand Down Expand Up @@ -49,9 +49,9 @@ inline auto cobalt_sleep(
}


CO_TEST_CASE("sleep_any_cpl_token")
CO_TEST_CASE(sleep_any_cpl_token)
{
co_await cobalt_sleep(co_await cobalt::this_coro::executor, std::chrono::milliseconds(1), cobalt::use_op);
}

TEST_SUITE_END();
BOOST_AUTO_TEST_SUITE_END();
19 changes: 10 additions & 9 deletions test/async_for.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <array>

#include "doctest.h"
#include <boost/test/unit_test.hpp>
#include "test.hpp"

using namespace boost;
Expand Down Expand Up @@ -41,41 +41,42 @@ cobalt::generator<int> throw_gen()
co_return 0;
}

TEST_SUITE_BEGIN("async_for");
BOOST_AUTO_TEST_SUITE(async_for);

/// If the awaitable is not empty the loop must be entered for every value exactly once
CO_TEST_CASE("empty_awaitable")
CO_TEST_CASE(empty_awaitable)
{
auto tg = once_gen();
co_await tg;

/// also[lvalue]: The iterated expression can be an lvalue
BOOST_COBALT_FOR(auto i, tg)
{
CHECK(false);
BOOST_CHECK(false);
boost::ignore_unused(i);
}
}

/// If the awaitable is not empty the loop must be entered for every value exactly once
CO_TEST_CASE("regular")
CO_TEST_CASE(regular)
{
auto itr = test_data.begin();
/// also[rvalue]: The iterated expression can be an rvalue
BOOST_COBALT_FOR(auto i, test_data_gen())
{
CHECK(i == *itr++);
BOOST_CHECK(i == *itr++);
}
}

/// Any exception thrown from the co_await must be propagated.
CO_TEST_CASE("exception")
CO_TEST_CASE(exception)
{
auto inner = []() -> cobalt::generator<int>
{
BOOST_COBALT_FOR(auto i, throw_gen()) boost::ignore_unused(i); // should throw
co_return -1;
};
try { BOOST_CHECK_THROW(co_await inner(), boost::system::system_error); } catch(...) {}
}

CHECK_THROWS(co_await inner());
}
BOOST_AUTO_TEST_SUITE_END();
Loading

0 comments on commit a0ca8a4

Please sign in to comment.