Skip to content

Commit 11faf28

Browse files
Added test for #491
1 parent 2a41d0a commit 11faf28

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

include/boost/process/v2/windows/default_launcher.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ inline void invoke_on_error(Launcher & /*launcher*/, const filesystem::path &/*e
9797
template<typename Launcher, typename Init>
9898
inline auto invoke_on_error(Launcher & launcher, const filesystem::path &executable, std::wstring &cmd_line,
9999
const error_code & ec, Init && init, derived && )
100-
-> decltype(init.on_error(launcher, executable, cmd_line, ec))
100+
-> decltype(init.on_error(launcher, executable, cmd_line, ec))
101101
{
102102
init.on_error(launcher, executable, cmd_line, ec);
103103
}
@@ -109,7 +109,7 @@ inline std::false_type probe_on_error(
109109

110110
template<typename Launcher, typename Init>
111111
inline auto probe_on_error(Launcher & launcher, Init && init, derived && )
112-
-> std::is_same<error_code, decltype(init.on_error(launcher, std::declval<const filesystem::path &>(), std::declval<std::wstring &>(), std::declval<error_code&>()))>;
112+
-> std::is_same<void, decltype(init.on_error(launcher, std::declval<const filesystem::path &>(), std::declval<std::wstring &>(), std::declval<error_code&>()))>;
113113

114114
template<typename Launcher, typename Init>
115115
using has_on_error = decltype(probe_on_error(std::declval<Launcher&>(), std::declval<Init>(), derived{}));

test/v2/process.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,5 +933,56 @@ BOOST_AUTO_TEST_CASE(print_args_combined)
933933
BOOST_CHECK_EQUAL(proc.exit_code(), 0);
934934
}
935935

936+
937+
struct my_handler
938+
{
939+
boost::process::filesystem::path pt;
940+
bpv::error_code ec;
941+
942+
template<typename Launcher, typename CmdLine>
943+
bpv::error_code on_setup(Launcher &launcher, const bpv::filesystem::path& executable,
944+
CmdLine (&/*cmd_line*/))
945+
{
946+
pt = executable;
947+
if (executable == "/send/more/cops")
948+
return asio::error::no_recovery;
949+
else
950+
return {};
951+
}
952+
953+
template<typename Launcher, typename CmdLine>
954+
void on_error(Launcher &launcher, const bpv::filesystem::path& executable,
955+
CmdLine (&/*cmd_line*/), const bpv::error_code & ec)
956+
{
957+
this->ec = ec;
958+
}
959+
960+
template<typename Launcher, typename CmdLine>
961+
void on_success(Launcher &launcher, const bpv::filesystem::path& executable,
962+
CmdLine (&/*cmd_line*/))
963+
{
964+
ec.clear();
965+
}
966+
};
967+
968+
BOOST_AUTO_TEST_CASE(custom_handlers)
969+
{
970+
my_handler mh;
971+
972+
asio::io_context ctx;
973+
974+
BOOST_CHECK_THROW(bpv::process(ctx, "/send/more/cops", {}, mh), bpv::system_error);
975+
BOOST_CHECK_EQUAL(mh.ec, asio::error::no_recovery);
976+
977+
BOOST_CHECK_EQUAL(mh.pt, "/send/more/cops");
978+
979+
using boost::unit_test::framework::master_test_suite;
980+
const auto pth = bpv::filesystem::absolute(master_test_suite().argv[1]);
981+
982+
bpv::process proc(ctx, pth, {}, mh);
983+
984+
BOOST_CHECK_EQUAL(mh.pt, pth);
985+
}
986+
936987
BOOST_AUTO_TEST_SUITE_END();
937988

0 commit comments

Comments
 (0)