]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | // Copyright (c) 2016 Klemens D. Morgenstern |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #define BOOST_TEST_MAIN | |
7 | #define BOOST_TEST_IGNORE_SIGCHLD | |
8 | #include <boost/test/included/unit_test.hpp> | |
9 | ||
10 | #include <boost/process/error.hpp> | |
11 | #include <boost/process/io.hpp> | |
12 | #include <boost/process/async.hpp> | |
13 | #include <boost/process/child.hpp> | |
14 | #include <boost/process/async_system.hpp> | |
15 | ||
16 | #include <string> | |
17 | #include <boost/asio/io_context.hpp> | |
18 | #include <boost/asio/spawn.hpp> | |
19 | #include <boost/asio/coroutine.hpp> | |
20 | #include <boost/asio/use_future.hpp> | |
21 | #include <boost/asio/yield.hpp> | |
22 | ||
23 | #include <vector> | |
24 | #include <array> | |
25 | ||
26 | namespace bp = boost::process; | |
b32b8144 FG |
27 | BOOST_AUTO_TEST_CASE(stackless, *boost::unit_test::timeout(15)) |
28 | { | |
29 | using boost::unit_test::framework::master_test_suite; | |
30 | ||
31 | boost::asio::io_context ios; | |
32 | ||
33 | bool did_something_else = false; | |
34 | ||
35 | struct stackless_t : boost::asio::coroutine | |
36 | { | |
37 | boost::asio::io_context & ios; | |
38 | bool & did_something_else; | |
39 | ||
40 | stackless_t(boost::asio::io_context & ios_, | |
41 | bool & did_something_else) | |
42 | : ios(ios_), did_something_else(did_something_else) {} | |
43 | void operator()( | |
44 | boost::system::error_code ec = boost::system::error_code(), | |
45 | std::size_t exit_code = 0) | |
46 | { | |
47 | if (!ec) reenter (this) | |
48 | { | |
49 | yield bp::async_system( | |
50 | ios, *this, | |
51 | master_test_suite().argv[1], | |
52 | "test", "--exit-code", "42"); | |
53 | ||
54 | BOOST_CHECK_EQUAL(exit_code, 42); | |
55 | BOOST_CHECK(did_something_else); | |
56 | } | |
57 | } | |
58 | } stackless{ios, did_something_else}; | |
59 | ||
60 | ios.post([&]{stackless();}); | |
61 | ios.post([&]{did_something_else = true;}); | |
62 | ||
63 | ios.run(); | |
64 | ||
65 | BOOST_CHECK(did_something_else); | |
66 | } |