1 /* Test of opening a subcommand stream.
2 Copyright (C) 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Eric Blake <ebb9@byu.net>, 2009. */
29 /* This test intentionally closes stderr. So, we arrange to have fd 10
30 (outside the range of interesting fd's during the test) set up to
31 duplicate the original stderr. */
33 #define BACKUP_STDERR_FILENO 10
36 #define ASSERT(expr) \
41 fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
49 main (int argc, char **argv)
54 /* We close fd 2 later, so save it in fd 10. */
55 if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
56 || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
59 ASSERT (fp = popen ("exit 0", "r"));
60 ASSERT (STDERR_FILENO < fileno (fp));
62 ASSERT (WIFEXITED (status));
63 ASSERT (!WEXITSTATUS (status));
65 ASSERT (fclose (stdin) == 0);
66 ASSERT (fp = popen ("exit 0", "r"));
67 ASSERT (STDERR_FILENO < fileno (fp));
69 ASSERT (WIFEXITED (status));
70 ASSERT (!WEXITSTATUS (status));
72 ASSERT (fclose (stdout) == 0);
73 ASSERT (fp = popen ("exit 0", "r"));
74 ASSERT (STDERR_FILENO < fileno (fp));
76 ASSERT (WIFEXITED (status));
77 ASSERT (!WEXITSTATUS (status));
79 ASSERT (fclose (stderr) == 0);
80 ASSERT (fp = popen ("exit 0", "r"));
81 ASSERT (STDERR_FILENO < fileno (fp));
83 ASSERT (WIFEXITED (status));
84 ASSERT (!WEXITSTATUS (status));