test: Adjust test_ret_code for Windows and re-enable it (#97)

This commit is contained in:
Hennadii Stepanov 2023-12-03 12:40:05 +00:00 committed by GitHub
parent d19cce111c
commit 06858e5fd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -790,7 +790,7 @@ struct input
} }
explicit input(IOTYPE typ) { explicit input(IOTYPE typ) {
assert (typ == PIPE && "STDOUT/STDERR not allowed"); assert (typ == PIPE && "STDOUT/STDERR not allowed");
#ifndef __USING_WINDOWS__ #ifndef __USING_WINDOWS__
std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec(); std::tie(rd_ch_, wr_ch_) = util::pipe_cloexec();
#endif #endif
} }
@ -1427,10 +1427,6 @@ inline int Popen::wait() noexcept(false)
inline int Popen::poll() noexcept(false) inline int Popen::poll() noexcept(false)
{ {
#ifndef _MSC_VER
if (!child_created_) return -1; // TODO: ??
#endif
#ifdef __USING_WINDOWS__ #ifdef __USING_WINDOWS__
int ret = WaitForSingleObject(process_handle_, 0); int ret = WaitForSingleObject(process_handle_, 0);
if (ret != WAIT_OBJECT_0) return -1; if (ret != WAIT_OBJECT_0) return -1;
@ -1444,6 +1440,8 @@ inline int Popen::poll() noexcept(false)
return retcode_; return retcode_;
#else #else
if (!child_created_) return -1; // TODO: ??
int status; int status;
// Returns zero if child is still running // Returns zero if child is still running

View File

@ -6,9 +6,15 @@ namespace sp = subprocess;
void test_ret_code() void test_ret_code()
{ {
std::cout << "Test::test_poll_ret_code" << std::endl; 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"}); auto p = sp::Popen({"/usr/bin/false"});
#endif
while (p.poll() == -1) { while (p.poll() == -1) {
#ifndef _MSC_VER #ifdef __USING_WINDOWS__
Sleep(100);
#else
usleep(1000 * 100); usleep(1000 * 100);
#endif #endif
} }
@ -43,7 +49,7 @@ void test_ret_code_check_output()
} }
int main() { int main() {
// test_ret_code(); test_ret_code();
#ifndef __USING_WINDOWS__ #ifndef __USING_WINDOWS__
test_ret_code_comm(); test_ret_code_comm();
test_ret_code_check_output(); test_ret_code_check_output();