From: Philipp Gesang Date: Wed, 3 Jan 2018 13:50:50 +0000 (+0100) Subject: add pipestream unit tests for execution failure X-Git-Tag: v2.10~1^2~12 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=7f58145bec6195057092c63dfb336854053da1b7;p=libi2ncommon add pipestream unit tests for execution failure Note that on the Intranator as of 6.4.13, the argument --catch_system_errors=no must be passed to the unit test executable on account of ancient Boost being oversensitive to child process termination. --- diff --git a/test/test_pipestream.cpp b/test/test_pipestream.cpp index 181fe23..b361906 100644 --- a/test/test_pipestream.cpp +++ b/test/test_pipestream.cpp @@ -24,6 +24,7 @@ * Copyright 2018 by Intra2net AG */ +#define BOOST_TEST_IGNORE_NON_ZERO_CHILD_CODE #define BOOST_TEST_DYN_LINK #include @@ -98,7 +99,7 @@ BOOST_AUTO_TEST_SUITE(pipestream) const char *const bad_command [] = { "/does_not_exist", NULL }; - BOOST_AUTO_TEST_CASE(abspath_zeros_shell_fail) + BOOST_AUTO_TEST_CASE(abspath_bad_shell_fail) { assert (access(bad_command [0], X_OK) != 0); @@ -109,19 +110,18 @@ BOOST_AUTO_TEST_SUITE(pipestream) BOOST_CHECK_EQUAL(result.size (), 0); } - BOOST_AUTO_TEST_CASE(abspath_zeros_noshell_fail) + BOOST_AUTO_TEST_CASE(abspath_bad_noshell_fail) { assert (access(bad_command [0], X_OK) != 0); ExecResult exres; const std::string result = capture_exec (bad_command, exres); - BOOST_CHECK(!exres.normal_exit); BOOST_CHECK(!exres.terminated_by_signal); BOOST_CHECK_EQUAL(result.size (), 0); } - BOOST_AUTO_TEST_CASE(abspath_zeros_noshell_stderr) + BOOST_AUTO_TEST_CASE(abspath_bad_noshell_stderr) { assert (access(bad_command [0], X_OK) != 0); @@ -131,6 +131,29 @@ BOOST_AUTO_TEST_SUITE(pipestream) BOOST_CHECK_NE(result.size (), 0); } + const char *const false_argv [] = { "/bin/false", NULL }; + + BOOST_AUTO_TEST_CASE(abspath_false_noshell_fail_exit) + { + ExecResult exres; + const std::string result = capture_exec (false_argv, exres, true, false); + + BOOST_CHECK(exres.normal_exit); + BOOST_CHECK_EQUAL(exres.return_code, EXIT_FAILURE); + BOOST_CHECK_EQUAL(result.size (), 0); + } + + BOOST_AUTO_TEST_CASE(abspath_false_shell_fail_exit) + { + ExecResult exres; + const std::string result = + capture_exec (std::string (false_argv [0]), exres); + + BOOST_CHECK(exres.normal_exit); + BOOST_CHECK_EQUAL(exres.return_code, EXIT_FAILURE); + BOOST_CHECK_EQUAL(result.size (), 0); + } + BOOST_AUTO_TEST_SUITE_END() /* [pipestream->read] */ BOOST_AUTO_TEST_SUITE_END() /* [pipestream] */