]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/error.cpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 #define BOOST_TEST_MAIN
11 #define BOOST_TEST_IGNORE_SIGCHLD
12 #include <boost/test/included/unit_test.hpp>
14 #include <boost/process/error.hpp>
15 #include <boost/process/child.hpp>
16 #include <boost/process/extend.hpp>
17 #include <boost/algorithm/string/predicate.hpp>
18 #include <system_error>
22 namespace bp
= boost::process
;
29 template<typename Exec
>
30 void operator()(Exec
& exec
)
32 exec
.set_error(ec
, msg
);
35 template<typename Exec
>
36 void operator()(Exec
& exec
, const std::error_code
&)
38 exec
.set_error(ec
, msg
);
42 BOOST_AUTO_TEST_CASE(setup_error
)
44 using boost::unit_test::framework::master_test_suite
;
49 es
.ec
.assign(42, std::system_category());
51 bp::child
c(master_test_suite().argv
[1], ec
, bp::extend::on_setup(es
));
53 BOOST_CHECK(!c
.running());
55 BOOST_CHECK_EQUAL(ec
.value(), 42);
57 bool has_thrown
= false;
60 es
.ec
.assign(24, std::system_category());
62 bp::child
c(master_test_suite().argv
[1], bp::extend::on_setup(es
));
65 catch( bp::process_error
& se
)
68 BOOST_CHECK_EQUAL(se
.code().value(), 24);
69 BOOST_CHECK(boost::starts_with(se
.what(), "MyMessage"));
71 BOOST_CHECK(has_thrown
);
74 BOOST_AUTO_TEST_CASE(success_error
)
76 using boost::unit_test::framework::master_test_suite
;
81 es
.ec
.assign(22, std::system_category());
83 bp::child
c(master_test_suite().argv
[1], ec
, bp::extend::on_success(es
));
86 BOOST_CHECK(!c
.running());
88 BOOST_CHECK_EQUAL(ec
.value(), 22);
89 std::cout
<< "Value: " << ec
.value() << std::endl
;
91 bool has_thrown
= false;
94 es
.ec
.assign(23, std::system_category());
96 bp::child
c(master_test_suite().argv
[1], bp::extend::on_success(es
));
100 catch( bp::process_error
& se
)
103 BOOST_CHECK_EQUAL(se
.code().value(), 23);
104 BOOST_CHECK(boost::starts_with(se
.what(), "MyMessage"));
106 BOOST_CHECK(has_thrown
);
109 BOOST_AUTO_TEST_CASE(ignore_error
)
113 BOOST_CHECK_NO_THROW(bp::child
c("doesnt-exit", bp::ignore_error
));