close_stdin.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #define BOOST_TEST_MAIN
  10. #define BOOST_TEST_IGNORE_SIGCHLD
  11. #include <boost/test/included/unit_test.hpp>
  12. #include <boost/process/error.hpp>
  13. #include <boost/process/io.hpp>
  14. #include <boost/process/child.hpp>
  15. #include <system_error>
  16. #include <boost/system/error_code.hpp>
  17. #include <cstdlib>
  18. #if defined(BOOST_POSIX_API)
  19. # include <sys/wait.h>
  20. #endif
  21. namespace bp = boost::process;
  22. BOOST_AUTO_TEST_CASE(close_stdin)
  23. {
  24. using boost::unit_test::framework::master_test_suite;
  25. std::error_code ec;
  26. bp::child c(
  27. master_test_suite().argv[1],
  28. "test", "--is-closed-stdin",
  29. bp::std_in.close(),
  30. ec
  31. );
  32. BOOST_REQUIRE(!ec);
  33. c.wait();
  34. int exit_code = c.exit_code();
  35. #if defined(BOOST_WINDOWS_API)
  36. BOOST_CHECK_EQUAL(EXIT_SUCCESS, exit_code);
  37. #elif defined(BOOST_POSIX_API)
  38. BOOST_CHECK_EQUAL(EXIT_SUCCESS, WEXITSTATUS(exit_code));
  39. #endif
  40. }