• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
27 BOOST_AUTO_TEST_SUITE( async );
28 
29 BOOST_AUTO_TEST_CASE(future, *boost::unit_test::timeout(15))
30 {
31     using boost::unit_test::framework::master_test_suite;
32 
33     boost::asio::io_context ios;
34 
35     std::future<int> fut = bp::async_system(
36                               ios, boost::asio::use_future,
37                               master_test_suite().argv[1],
38                               "test", "--exit-code", "42");
39 
40     ios.run();
41 
42     int exit_code = 0;
43     BOOST_CHECK_NO_THROW(exit_code = fut.get());
44 
45     BOOST_CHECK_EQUAL(exit_code, 42);
46 }
47 
48 BOOST_AUTO_TEST_CASE(future_error, *boost::unit_test::timeout(15))
49 {
50     using boost::unit_test::framework::master_test_suite;
51 
52     boost::asio::io_context ios;
53 
54     std::future<int> fut = bp::async_system(
55                               ios, boost::asio::use_future,
56                               "invalid-command");
57 
58     ios.run();
59 
60     BOOST_CHECK_THROW(fut.get(), boost::system::system_error);
61 }
62 
63 BOOST_AUTO_TEST_SUITE_END();
64