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 | |
13 | #include <boost/test/included/unit_test.hpp> |
14 | |
15 | #include <boost/process/exe.hpp> |
16 | #include <boost/process/args.hpp> |
17 | #include <boost/process/cmd.hpp> |
18 | #include <boost/process/io.hpp> |
19 | #include <boost/process/error.hpp> |
20 | #include <boost/process/child.hpp> |
21 | |
22 | #include <boost/algorithm/string/predicate.hpp> |
23 | |
24 | namespace bp = boost::process; |
25 | |
26 | namespace bp = boost::process; |
27 | |
28 | BOOST_AUTO_TEST_CASE(args, *boost::unit_test::timeout(2)) |
29 | { |
30 | using boost::unit_test::framework::master_test_suite; |
31 | |
32 | bp::ipstream is; |
33 | |
34 | std::error_code ec; |
35 | bp::child c( |
36 | master_test_suite().argv[1], |
37 | "test" , "--echo-argv" , |
38 | bp::args+={"hello thingy" , "\"stuff\"" }, |
39 | bp::args+=" spa ce " , |
40 | bp::std_out>is, |
41 | ec |
42 | ); |
43 | if (ec) |
44 | std::cout << "EC: " << ec.message() << std::endl; |
45 | BOOST_REQUIRE(!ec); |
46 | |
47 | std::string s; |
48 | |
49 | std::getline(is&: is, str&: s); |
50 | s.resize(n: 4); |
51 | BOOST_CHECK_EQUAL(s, "test" ); |
52 | |
53 | std::getline(is&: is, str&: s); |
54 | s.resize(n: 11); |
55 | BOOST_CHECK_EQUAL(s, "--echo-argv" ); |
56 | |
57 | std::getline(is&: is, str&: s); |
58 | s.resize(n: 12); |
59 | |
60 | BOOST_CHECK_EQUAL(s, "hello thingy" ); |
61 | |
62 | std::getline(is&: is, str&: s); |
63 | s.resize(n: 7); |
64 | |
65 | BOOST_CHECK_EQUAL(s, "\"stuff\"" ); |
66 | |
67 | std::getline(is&: is, str&: s); |
68 | s.resize(n: 10); |
69 | |
70 | BOOST_CHECK_EQUAL(s, " spa ce " ); |
71 | |
72 | } |
73 | |
74 | |
75 | BOOST_AUTO_TEST_CASE(cmd, *boost::unit_test::timeout(2)) |
76 | { |
77 | using boost::unit_test::framework::master_test_suite; |
78 | |
79 | bp::ipstream is; |
80 | |
81 | std::error_code ec; |
82 | |
83 | std::string cmd = master_test_suite().argv[1]; |
84 | cmd+= " test --echo-argv \"hello thingy\" \\\"stuff\\\" \" spa ce \"" ; |
85 | |
86 | bp::child c(cmd, |
87 | bp::std_out>is, |
88 | ec |
89 | ); |
90 | BOOST_REQUIRE(!ec); |
91 | |
92 | std::string s; |
93 | |
94 | std::getline(is&: is, str&: s); |
95 | s.resize(n: 4); |
96 | BOOST_CHECK_EQUAL(s, "test" ); |
97 | |
98 | std::getline(is&: is, str&: s); |
99 | s.resize(n: 11); |
100 | BOOST_CHECK_EQUAL(s, "--echo-argv" ); |
101 | |
102 | std::getline(is&: is, str&: s); |
103 | s.resize(n: 12); |
104 | |
105 | BOOST_CHECK_EQUAL(s, "hello thingy" ); |
106 | |
107 | std::getline(is&: is, str&: s); |
108 | s.resize(n: 7); |
109 | |
110 | BOOST_CHECK_EQUAL(s, "\"stuff\"" ); |
111 | |
112 | std::getline(is&: is, str&: s); |
113 | s.resize(n: 10); |
114 | |
115 | BOOST_CHECK_EQUAL(s, " spa ce " ); |
116 | } |
117 | |