From 1bb027c04cc1efff60290d47db0d147ea2aa09cd Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Sat, 2 Dec 2023 22:21:58 +0000 Subject: [PATCH] test: Adjust `test_ret_code` for Windows and re-enable it --- subprocess.hpp | 8 +++----- test/test_ret_code.cc | 10 ++++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/subprocess.hpp b/subprocess.hpp index 22b3903..16b1ab6 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -790,7 +790,7 @@ struct input } explicit input(IOTYPE typ) { assert (typ == PIPE && "STDOUT/STDERR not allowed"); -#ifndef __USING_WINDOWS__ +#ifndef __USING_WINDOWS__ std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec(); #endif } @@ -1427,10 +1427,6 @@ inline int Popen::wait() noexcept(false) inline int Popen::poll() noexcept(false) { -#ifndef _MSC_VER - if (!child_created_) return -1; // TODO: ?? -#endif - #ifdef __USING_WINDOWS__ int ret = WaitForSingleObject(process_handle_, 0); if (ret != WAIT_OBJECT_0) return -1; @@ -1444,6 +1440,8 @@ inline int Popen::poll() noexcept(false) return retcode_; #else + if (!child_created_) return -1; // TODO: ?? + int status; // Returns zero if child is still running diff --git a/test/test_ret_code.cc b/test/test_ret_code.cc index 06b5f75..e589653 100644 --- a/test/test_ret_code.cc +++ b/test/test_ret_code.cc @@ -6,9 +6,15 @@ namespace sp = subprocess; void test_ret_code() { std::cout << "Test::test_poll_ret_code" << std::endl; +#ifdef __USING_WINDOWS__ + auto p = sp::Popen({"cmd.exe", "/c", "exit", "1"}); +#else auto p = sp::Popen({"/usr/bin/false"}); +#endif while (p.poll() == -1) { -#ifndef _MSC_VER +#ifdef __USING_WINDOWS__ + Sleep(100); +#else usleep(1000 * 100); #endif } @@ -43,7 +49,7 @@ void test_ret_code_check_output() } int main() { - // test_ret_code(); + test_ret_code(); #ifndef __USING_WINDOWS__ test_ret_code_comm(); test_ret_code_check_output();