args_handling.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. // Copyright (c) 2018 Oxford Nanopore Technologies
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. #define BOOST_TEST_MAIN
  11. #define BOOST_TEST_IGNORE_SIGCHLD
  12. #include <boost/test/included/unit_test.hpp>
  13. #include <system_error>
  14. #include <boost/filesystem.hpp>
  15. #include <boost/process/cmd.hpp>
  16. #include <boost/process/error.hpp>
  17. #include <boost/process/child.hpp>
  18. namespace bp = boost::process;
  19. BOOST_AUTO_TEST_CASE(implicit_args_fs_path)
  20. {
  21. using boost::unit_test::framework::master_test_suite;
  22. boost::filesystem::path exe = master_test_suite().argv[1];
  23. std::error_code ec;
  24. bp::child c(
  25. exe,
  26. ec
  27. );
  28. BOOST_REQUIRE(!ec);
  29. c.wait(ec);
  30. BOOST_REQUIRE(!ec);
  31. BOOST_CHECK(c.exit_code() == 1); // should pass at least exe!
  32. }
  33. BOOST_AUTO_TEST_CASE(implicit_args_cmd)
  34. {
  35. using boost::unit_test::framework::master_test_suite;
  36. std::error_code ec;
  37. bp::child c(
  38. master_test_suite().argv[1],
  39. ec
  40. );
  41. BOOST_REQUIRE(!ec);
  42. c.wait(ec);
  43. BOOST_REQUIRE(!ec);
  44. BOOST_CHECK(c.exit_code() == 1); // should pass at least exe!
  45. }
  46. BOOST_AUTO_TEST_CASE(explicit_args_fs_path)
  47. {
  48. using boost::unit_test::framework::master_test_suite;
  49. boost::filesystem::path exe = master_test_suite().argv[1];
  50. std::error_code ec;
  51. bp::child c(
  52. exe,
  53. "hello",
  54. ec
  55. );
  56. BOOST_REQUIRE(!ec);
  57. c.wait(ec);
  58. BOOST_REQUIRE(!ec);
  59. BOOST_CHECK(c.exit_code() == 2); // exe + "hello"
  60. }