From 11faf28fed65e0714adb1331d15e38cbb8e27b21 Mon Sep 17 00:00:00 2001 From: Klemens Morgenstern Date: Sun, 11 Jan 2026 07:08:46 +0800 Subject: [PATCH] Added test for #491 --- .../process/v2/windows/default_launcher.hpp | 4 +- test/v2/process.cpp | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/boost/process/v2/windows/default_launcher.hpp b/include/boost/process/v2/windows/default_launcher.hpp index 16ff12d46..763681250 100644 --- a/include/boost/process/v2/windows/default_launcher.hpp +++ b/include/boost/process/v2/windows/default_launcher.hpp @@ -97,7 +97,7 @@ inline void invoke_on_error(Launcher & /*launcher*/, const filesystem::path &/*e template inline auto invoke_on_error(Launcher & launcher, const filesystem::path &executable, std::wstring &cmd_line, 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); } @@ -109,7 +109,7 @@ inline std::false_type probe_on_error( template inline auto probe_on_error(Launcher & launcher, Init && init, derived && ) - -> std::is_same(), std::declval(), std::declval()))>; + -> std::is_same(), std::declval(), std::declval()))>; template using has_on_error = decltype(probe_on_error(std::declval(), std::declval(), derived{})); diff --git a/test/v2/process.cpp b/test/v2/process.cpp index 14d3ec801..161981ae6 100644 --- a/test/v2/process.cpp +++ b/test/v2/process.cpp @@ -933,5 +933,56 @@ BOOST_AUTO_TEST_CASE(print_args_combined) BOOST_CHECK_EQUAL(proc.exit_code(), 0); } + +struct my_handler +{ + boost::process::filesystem::path pt; + bpv::error_code ec; + + template + 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 + void on_error(Launcher &launcher, const bpv::filesystem::path& executable, + CmdLine (&/*cmd_line*/), const bpv::error_code & ec) + { + this->ec = ec; + } + + template + 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();