]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/cmd_test.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / test / cmd_test.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
6 //
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)
9
10 #define BOOST_TEST_MAIN
11 #define BOOST_TEST_IGNORE_SIGCHLD
12 #include <boost/test/included/unit_test.hpp>
13
14 #include <boost/process/error.hpp>
15 #include <boost/process/system.hpp>
16 #include <boost/process/env.hpp>
17 #include <boost/process/cmd.hpp>
18
19 #include <boost/filesystem/path.hpp>
20 #include <boost/filesystem/operations.hpp>
21
22 #include <system_error>
23
24 #include <boost/algorithm/string/case_conv.hpp>
25
26 #include <boost/system/error_code.hpp>
27 #include <cstdlib>
28
29 namespace bp = boost::process;
30 namespace fs = boost::filesystem;
31
32
33 BOOST_AUTO_TEST_CASE(excplicit)
34 {
35 using boost::unit_test::framework::master_test_suite;
36
37 std::error_code ec;
38
39 fs::path pth = master_test_suite().argv[1];
40 auto env = boost::this_process::environment();
41
42 auto itr = std::find_if(env.begin(), env.end(),
43 [](const bp::native_environment::entry_type & e){return boost::to_upper_copy(e.get_name()) == "PATH";});
44
45 BOOST_REQUIRE(itr != env.end());
46
47 (*itr) += fs::canonical(fs::absolute(pth.parent_path())).string();
48
49 int ret = bp::system(
50 bp::cmd="sparring_partner --exit-code 42",
51 ec
52 );
53
54 BOOST_CHECK(!ec);
55 if (ec)
56 BOOST_TEST_MESSAGE(ec.message());
57 BOOST_CHECK_EQUAL(ret, 42);
58 }
59
60 BOOST_AUTO_TEST_CASE(implicit)
61 {
62 using boost::unit_test::framework::master_test_suite;
63
64 std::error_code ec;
65
66 fs::path pth = master_test_suite().argv[1];
67 auto env = boost::this_process::environment();
68
69 auto itr = std::find_if(env.begin(), env.end(),
70 [](const bp::native_environment::entry_type & e){return boost::to_upper_copy(e.get_name()) == "PATH";});
71
72 BOOST_REQUIRE(itr != env.end());
73
74 (*itr) += fs::canonical(fs::absolute(pth.parent_path())).string();
75
76 int ret = bp::system(
77 "sparring_partner --exit-code 21",
78 ec
79 );
80
81 BOOST_CHECK(!ec);
82 if (ec)
83 BOOST_TEST_MESSAGE(ec.message());
84 BOOST_CHECK_EQUAL(ret, 21);
85 }