Skip to content

Commit 0d5f117

Browse files
Added test for combined stdout/stderr
Addresses #522.
1 parent 322f581 commit 0d5f117

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/v2/process.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,5 +852,70 @@ BOOST_AUTO_TEST_CASE(async_terminate_code)
852852
#endif
853853

854854

855+
BOOST_AUTO_TEST_CASE(print_args_combined)
856+
{
857+
using boost::unit_test::framework::master_test_suite;
858+
const auto pth = master_test_suite().argv[1];
859+
860+
asio::io_context ctx;
861+
862+
asio::readable_pipe rp{ctx};
863+
asio::writable_pipe wp{ctx};
864+
asio::connect_pipe(rp, wp);
865+
866+
bpv::process proc(ctx, pth, {"print-args", "bar", "foo"}, bpv::process_stdio{/*in*/{}, /*.out= */ wp, /* .err=*/ wp});
867+
868+
wp.close();
869+
asio::streambuf st;
870+
std::istream is{&st};
871+
bpv::error_code ec;
872+
873+
auto sz = asio::read(rp, st, ec);
874+
while (ec == asio::error::interrupted)
875+
sz += asio::read(rp, st, ec);
876+
877+
BOOST_CHECK_NE(sz , 0u);
878+
BOOST_CHECK_MESSAGE((ec == asio::error::broken_pipe) || (ec == asio::error::eof), ec.message());
879+
880+
std::string line;
881+
BOOST_CHECK(std::getline(is, line));
882+
trim_end(line);
883+
BOOST_CHECK_EQUAL(pth, line );
884+
885+
BOOST_CHECK(std::getline(is, line));
886+
trim_end(line);
887+
BOOST_CHECK_EQUAL(pth, line );
888+
889+
890+
BOOST_CHECK(std::getline(is, line));
891+
trim_end(line);
892+
BOOST_CHECK_EQUAL("print-args", line);
893+
894+
BOOST_CHECK(std::getline(is, line));
895+
trim_end(line);
896+
BOOST_CHECK_EQUAL("print-args", line);
897+
898+
899+
BOOST_CHECK(std::getline(is, line));
900+
trim_end(line);
901+
BOOST_CHECK_EQUAL("bar", line);
902+
903+
BOOST_CHECK(std::getline(is, line));
904+
trim_end(line);
905+
BOOST_CHECK_EQUAL("bar", line);
906+
907+
BOOST_CHECK(std::getline(is, line));
908+
trim_end(line);
909+
BOOST_CHECK_EQUAL("foo", line);
910+
911+
BOOST_CHECK(std::getline(is, line));
912+
trim_end(line);
913+
BOOST_CHECK_EQUAL("foo", line);
914+
915+
916+
proc.wait();
917+
BOOST_CHECK_EQUAL(proc.exit_code(), 0);
918+
}
919+
855920
BOOST_AUTO_TEST_SUITE_END();
856921

0 commit comments

Comments
 (0)