Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
test: test for uv_spawn with stdio_count == 3
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny authored and piscisaureus committed Jun 1, 2012
1 parent f5b5127 commit dc7a62d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/run-tests.c
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions test/test-spawn.c
Expand Up @@ -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;

Expand Down

0 comments on commit dc7a62d

Please sign in to comment.