| 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 | #include <boost/process.hpp> |
| 14 | #include <boost/system/error_code.hpp> |
| 15 | #include <boost/process/filesystem.hpp> |
| 16 | #include <boost/algorithm/string/compare.hpp> |
| 17 | #include <string> |
| 18 | #include <iostream> |
| 19 | |
| 20 | namespace bp = boost::process; |
| 21 | |
| 22 | |
| 23 | struct test_dir |
| 24 | { |
| 25 | std::string s_; |
| 26 | test_dir(const std::string &s) : s_(s) |
| 27 | { BOOST_REQUIRE_NO_THROW(boost::process::filesystem::create_directory(s)); } |
| 28 | ~test_dir() { boost::process::filesystem::remove(p: s_); } |
| 29 | }; |
| 30 | |
| 31 | BOOST_AUTO_TEST_CASE(start_in_dir) |
| 32 | { |
| 33 | using boost::unit_test::framework::master_test_suite; |
| 34 | |
| 35 | test_dir dir("start_in_dir_test" ); |
| 36 | |
| 37 | bp::ipstream is; |
| 38 | |
| 39 | std::error_code ec; |
| 40 | bp::child c( |
| 41 | bp::exe=boost::process::filesystem::absolute(p: master_test_suite().argv[1]).string(), |
| 42 | bp::args +={"test" , "--pwd" }, |
| 43 | bp::start_dir = dir.s_, |
| 44 | bp::std_out>is, |
| 45 | ec |
| 46 | ); |
| 47 | BOOST_REQUIRE(!ec); |
| 48 | |
| 49 | |
| 50 | std::string s; |
| 51 | std::getline(is&: is, str&: s); |
| 52 | auto path_read = boost::process::filesystem::absolute(p: boost::process::filesystem::path(s)).string(); |
| 53 | auto path_set = boost::process::filesystem::absolute(p: dir.s_).string(); |
| 54 | |
| 55 | if (path_read.size() > path_set.size()) |
| 56 | path_read.resize(n: path_set.size()); |
| 57 | else if (path_read.size() < path_set.size()) |
| 58 | path_set.resize(n: path_read.size()); |
| 59 | |
| 60 | BOOST_CHECK_EQUAL_COLLECTIONS(path_read.begin(), path_read.end(), |
| 61 | path_set.begin(), path_set.end()); |
| 62 | |
| 63 | BOOST_REQUIRE_NO_THROW(c.wait()); |
| 64 | } |
| 65 | |