test: Adjust test_ret_code for Windows and re-enable it

This commit is contained in:
Hennadii Stepanov 2023-12-02 22:21:58 +00:00
parent d19cce111c
commit 1bb027c04c
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
2 changed files with 11 additions and 7 deletions

View File

@ -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

View File

@ -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();