]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/start_dir.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / test / start_dir.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 #include <boost/process.hpp>
14 #include <boost/system/error_code.hpp>
15 #include <boost/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::filesystem::create_directory(s)); }
28 ~test_dir() { boost::filesystem::remove(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::filesystem::absolute(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, s);
52 auto path_read = boost::filesystem::absolute(boost::filesystem::path(s)).string();
53 auto path_set = boost::filesystem::absolute(dir.s_).string();
54
55 if (path_read.size() > path_set.size())
56 path_read.resize(path_set.size());
57 else if (path_read.size() < path_set.size())
58 path_set.resize(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 }