1 /* Test of opening a subcommand stream.
2 Copyright (C) 2009-2011 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. */
28 /* This test intentionally closes stderr. So, we arrange to have fd 10
29 (outside the range of interesting fd's during the test) set up to
30 duplicate the original stderr. */
32 #define BACKUP_STDERR_FILENO 10
33 #define ASSERT_STREAM myerr
39 main (int argc, char **argv)
44 /* We close fd 2 later, so save it in fd 10. */
45 if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
46 || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
49 ASSERT (fp = popen ("exit 0", "r"));
50 ASSERT (STDERR_FILENO < fileno (fp));
52 ASSERT (WIFEXITED (status));
53 ASSERT (!WEXITSTATUS (status));
55 ASSERT (fclose (stdin) == 0);
56 ASSERT (fp = popen ("exit 0", "r"));
57 ASSERT (STDERR_FILENO < fileno (fp));
59 ASSERT (WIFEXITED (status));
60 ASSERT (!WEXITSTATUS (status));
62 ASSERT (fclose (stdout) == 0);
63 ASSERT (fp = popen ("exit 0", "r"));
64 ASSERT (STDERR_FILENO < fileno (fp));
66 ASSERT (WIFEXITED (status));
67 ASSERT (!WEXITSTATUS (status));
69 ASSERT (fclose (stderr) == 0);
70 ASSERT (fp = popen ("exit 0", "r"));
71 ASSERT (STDERR_FILENO < fileno (fp));
73 ASSERT (WIFEXITED (status));
74 ASSERT (!WEXITSTATUS (status));