2 * Copyright (C) 2010, 2012 Colin Watson.
4 * This file is part of libpipeline.
6 * libpipeline is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * libpipeline is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with libpipeline; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
29 #include <sys/types.h>
33 #include "xvasprintf.h"
37 const char *program_name = "exec";
39 START_TEST (test_exec_process)
43 for (i = 0; i < 3; ++i) {
51 cmd = pipecmd_new_args (SHELL, "-c", (void *) 0);
52 arg = xasprintf ("exit %d", i);
53 pipecmd_arg (cmd, arg);
56 cmd = pipecmd_new ("nonexistent command");
57 pipecmd_discard_err (cmd, 1);
62 ck_abort_msg ("fork failed: %s", strerror (errno));
68 while (waitpid (pid, &status, 0) < 0) {
71 ck_abort_msg ("waitpid failed: %s", strerror (errno));
75 ck_assert_int_ne (WIFEXITED (status), 0);
77 ck_assert_int_eq (WEXITSTATUS (status), i);
79 ck_assert_int_ne (WEXITSTATUS (status), 0);
86 static void exit_helper (void *data)
91 START_TEST (test_exec_function)
95 for (i = 0; i < 2; ++i) {
100 cmd = pipecmd_new_function ("exit_helper", exit_helper, NULL,
105 ck_abort_msg ("fork failed: %s", strerror (errno));
111 while (waitpid (pid, &status, 0) < 0) {
114 ck_abort_msg ("waitpid failed: %s", strerror (errno));
118 ck_assert_int_ne (WIFEXITED (status), 0);
119 ck_assert_int_eq (WEXITSTATUS (status), i);
126 static Suite *exec_suite (void)
128 Suite *s = suite_create ("Exec");
130 TEST_CASE (s, exec, process);
131 TEST_CASE (s, exec, function);