diff --git a/test/run-tests.c b/test/run-tests.c index db7ea70b..45e95290 100644 --- a/test/run-tests.c +++ b/test/run-tests.c @@ -104,5 +104,17 @@ static int maybe_run_test(int argc, char **argv) { while (1) uv_sleep(10000); } + if (strcmp(argv[1], "spawn_helper5") == 0) { + const char* out = "fourth stdio!\n\0"; +#ifdef _WIN32 + DWORD bytes; + WriteFile((HANDLE) _get_osfhandle(3), out, strlen(out), &bytes, NULL); +#else + write(3, out, strlen(out)); + fsync(3); +#endif + return 1; + } + return run_test(argv[1], TEST_TIMEOUT, 0); } diff --git a/test/test-list.h b/test/test-list.h index 40e7dd52..9a5ba695 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -119,6 +119,7 @@ TEST_DECLARE (pass_always) TEST_DECLARE (spawn_exit_code) TEST_DECLARE (spawn_stdout) TEST_DECLARE (spawn_stdin) +TEST_DECLARE (spawn_stdio_greater_than_3) TEST_DECLARE (spawn_and_kill) TEST_DECLARE (spawn_detached) TEST_DECLARE (spawn_and_kill_with_std) @@ -333,6 +334,7 @@ TASK_LIST_START TEST_ENTRY (spawn_exit_code) TEST_ENTRY (spawn_stdout) TEST_ENTRY (spawn_stdin) + TEST_ENTRY (spawn_stdio_greater_than_3) TEST_ENTRY (spawn_and_kill) TEST_ENTRY (spawn_detached) TEST_ENTRY (spawn_and_kill_with_std) diff --git a/test/test-spawn.c b/test/test-spawn.c index 81de381e..60430438 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -295,6 +295,40 @@ TEST_IMPL(spawn_stdin) { } +TEST_IMPL(spawn_stdio_greater_than_3) { + int r; + uv_pipe_t pipe; + uv_stdio_container_t stdio[4]; + + init_process_options("spawn_helper5", exit_cb); + + uv_pipe_init(uv_default_loop(), &pipe, 0); + options.stdio = stdio; + options.stdio[0].flags = UV_IGNORE; + options.stdio[1].flags = UV_IGNORE; + options.stdio[2].flags = UV_IGNORE; + options.stdio[3].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE; + options.stdio[3].data.stream = (uv_stream_t*)&pipe; + options.stdio_count = 4; + + r = uv_spawn(uv_default_loop(), &process, options); + ASSERT(r == 0); + + r = uv_read_start((uv_stream_t*) &pipe, on_alloc, on_read); + ASSERT(r == 0); + + r = uv_run(uv_default_loop()); + ASSERT(r == 0); + + ASSERT(exit_cb_called == 1); + ASSERT(close_cb_called == 2); /* Once for process once for the pipe. */ + printf("output from stdio[3] is: %s", output); + ASSERT(strcmp("fourth stdio!\n", output) == 0); + + return 0; +} + + TEST_IMPL(spawn_and_kill) { int r;