mirror of
https://github.com/boostorg/process.git
synced 2026-01-21 17:12:19 +00:00
Compare commits
1 Commits
develop
...
issue/491-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11faf28fed |
@@ -97,7 +97,7 @@ inline void invoke_on_error(Launcher & /*launcher*/, const filesystem::path &/*e
|
|||||||
template<typename Launcher, typename Init>
|
template<typename Launcher, typename Init>
|
||||||
inline auto invoke_on_error(Launcher & launcher, const filesystem::path &executable, std::wstring &cmd_line,
|
inline auto invoke_on_error(Launcher & launcher, const filesystem::path &executable, std::wstring &cmd_line,
|
||||||
const error_code & ec, Init && init, derived && )
|
const error_code & ec, Init && init, derived && )
|
||||||
-> decltype(init.on_error(launcher, executable, cmd_line, ec))
|
-> decltype(init.on_error(launcher, executable, cmd_line, ec))
|
||||||
{
|
{
|
||||||
init.on_error(launcher, executable, cmd_line, ec);
|
init.on_error(launcher, executable, cmd_line, ec);
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ inline std::false_type probe_on_error(
|
|||||||
|
|
||||||
template<typename Launcher, typename Init>
|
template<typename Launcher, typename Init>
|
||||||
inline auto probe_on_error(Launcher & launcher, Init && init, derived && )
|
inline auto probe_on_error(Launcher & launcher, Init && init, derived && )
|
||||||
-> std::is_same<error_code, decltype(init.on_error(launcher, std::declval<const filesystem::path &>(), std::declval<std::wstring &>(), std::declval<error_code&>()))>;
|
-> std::is_same<void, decltype(init.on_error(launcher, std::declval<const filesystem::path &>(), std::declval<std::wstring &>(), std::declval<error_code&>()))>;
|
||||||
|
|
||||||
template<typename Launcher, typename Init>
|
template<typename Launcher, typename Init>
|
||||||
using has_on_error = decltype(probe_on_error(std::declval<Launcher&>(), std::declval<Init>(), derived{}));
|
using has_on_error = decltype(probe_on_error(std::declval<Launcher&>(), std::declval<Init>(), derived{}));
|
||||||
|
|||||||
@@ -933,5 +933,56 @@ BOOST_AUTO_TEST_CASE(print_args_combined)
|
|||||||
BOOST_CHECK_EQUAL(proc.exit_code(), 0);
|
BOOST_CHECK_EQUAL(proc.exit_code(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct my_handler
|
||||||
|
{
|
||||||
|
boost::process::filesystem::path pt;
|
||||||
|
bpv::error_code ec;
|
||||||
|
|
||||||
|
template<typename Launcher, typename CmdLine>
|
||||||
|
bpv::error_code on_setup(Launcher &launcher, const bpv::filesystem::path& executable,
|
||||||
|
CmdLine (&/*cmd_line*/))
|
||||||
|
{
|
||||||
|
pt = executable;
|
||||||
|
if (executable == "/send/more/cops")
|
||||||
|
return asio::error::no_recovery;
|
||||||
|
else
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Launcher, typename CmdLine>
|
||||||
|
void on_error(Launcher &launcher, const bpv::filesystem::path& executable,
|
||||||
|
CmdLine (&/*cmd_line*/), const bpv::error_code & ec)
|
||||||
|
{
|
||||||
|
this->ec = ec;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Launcher, typename CmdLine>
|
||||||
|
void on_success(Launcher &launcher, const bpv::filesystem::path& executable,
|
||||||
|
CmdLine (&/*cmd_line*/))
|
||||||
|
{
|
||||||
|
ec.clear();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(custom_handlers)
|
||||||
|
{
|
||||||
|
my_handler mh;
|
||||||
|
|
||||||
|
asio::io_context ctx;
|
||||||
|
|
||||||
|
BOOST_CHECK_THROW(bpv::process(ctx, "/send/more/cops", {}, mh), bpv::system_error);
|
||||||
|
BOOST_CHECK_EQUAL(mh.ec, asio::error::no_recovery);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(mh.pt, "/send/more/cops");
|
||||||
|
|
||||||
|
using boost::unit_test::framework::master_test_suite;
|
||||||
|
const auto pth = bpv::filesystem::absolute(master_test_suite().argv[1]);
|
||||||
|
|
||||||
|
bpv::process proc(ctx, pth, {}, mh);
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(mh.pt, pth);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END();
|
BOOST_AUTO_TEST_SUITE_END();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user