1 /* Check execvpe script argument handling.
2 Copyright (C) 2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 #include <sys/param.h>
30 static void do_prepare (void);
31 #define PREPARE(argc, argv) do_prepare ()
32 static int do_test (void);
33 #define TEST_FUNCTION do_test ()
35 #include "../test-skeleton.c"
40 int logfd
= create_temp_file ("logfile", &logname
);
43 int fd1
= create_temp_file ("testscript", &fname1
);
44 dprintf (fd1
, "echo foo $1 $2 $3 > %s\n", logname
);
48 int fd2
= create_temp_file ("testscript", &fname2
);
49 dprintf (fd2
, "echo foo > %s\n", logname
);
55 run_script (const char *fname
, char *args
[])
57 /* We want to test the `execvpe' function. To do this we restart the
58 program with an additional parameter. */
63 execvpe (fname
, args
, NULL
);
68 else if (pid
== (pid_t
) -1)
74 /* Wait for the child. */
75 if (waitpid (pid
, &status
, 0) != pid
)
81 if (WTERMSIG (status
) != 0)
83 puts ("Child terminated incorrectly");
91 check_output (const char *expected
)
93 /* Check log output. */
94 FILE *arq
= fopen (logname
, "r");
97 puts ("Error opening output file");
102 if (fgets (line
, sizeof (line
), arq
) == NULL
)
104 puts ("Error reading output file");
109 if (strcmp (line
, expected
) != 0)
111 puts ("Output file different than expected");
121 if (setenv ("PATH", test_dir
, 1) != 0)
123 puts ("setenv failed");
127 /* First check resulting script run with some arguments results in correct
129 char *args1
[] = { fname1
, (char*) "1", (char *) "2", (char *) "3", NULL
};
130 if (run_script (fname1
,args1
))
132 if (check_output ("foo 1 2 3\n"))
135 /* Same as before but with an expected empty argument list. */
136 char *args2
[] = { fname2
, NULL
};
137 if (run_script (fname2
, args2
))
139 if (check_output ("foo\n"))
142 /* Same as before but with an empty argument list. */
143 char *args3
[] = { NULL
};
144 if (run_script (fname2
, args3
))
146 if (check_output ("foo\n"))