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, s); 50 s.resize(4); 51 BOOST_CHECK_EQUAL(s, "test"); 52 53 std::getline(is, s); 54 s.resize(11); 55 BOOST_CHECK_EQUAL(s, "--echo-argv"); 56 57 std::getline(is, s); 58 s.resize(12); 59 60 BOOST_CHECK_EQUAL(s, "hello thingy"); 61 62 std::getline(is, s); 63 s.resize(7); 64 65 BOOST_CHECK_EQUAL(s, "\"stuff\""); 66 67 std::getline(is, s); 68 s.resize(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, s); 95 s.resize(4); 96 BOOST_CHECK_EQUAL(s, "test"); 97 98 std::getline(is, s); 99 s.resize(11); 100 BOOST_CHECK_EQUAL(s, "--echo-argv"); 101 102 std::getline(is, s); 103 s.resize(12); 104 105 BOOST_CHECK_EQUAL(s, "hello thingy"); 106 107 std::getline(is, s); 108 s.resize(7); 109 110 BOOST_CHECK_EQUAL(s, "\"stuff\""); 111 112 std::getline(is, s); 113 s.resize(10); 114 115 BOOST_CHECK_EQUAL(s, " spa ce "); 116 } 117