/* Test of opening a subcommand stream.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <sys/wait.h>
#include <unistd.h>
-#define ASSERT(expr) \
- do \
- { \
- if (!(expr)) \
- { \
- fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
- fflush (stderr); \
- abort (); \
- } \
- } \
- while (0)
+#include "macros.h"
int
main (int argc, char **argv)
if (argc > 1)
{
if (*argv[1] == 'r') /* Parent is reading, so we write. */
- ASSERT (putchar ('c') == 'c');
+ ASSERT (putchar ('c') == 'c');
else /* Parent is writing, so we read. */
- ASSERT (getchar () == 'p');
+ ASSERT (getchar () == 'p');
/* Test that parent can read non-zero status. */
return 42;
}
int status;
if (i)
- {
- ASSERT (fclose (stdin) == 0);
- ASSERT (fclose (stdout) == 0);
- }
+ {
+ ASSERT (fclose (stdin) == 0);
+ ASSERT (fclose (stdout) == 0);
+ }
cmd[len + 1] = 'r';
ASSERT (child = popen (cmd, "r"));
ASSERT (WIFEXITED (status));
ASSERT (WEXITSTATUS (status) == 42);
if (i)
- {
- ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1);
- ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1);
- }
+ {
+ ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1);
+ ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1);
+ }
cmd[len + 1] = 'w';
ASSERT (child = popen (cmd, "w"));
ASSERT (WIFEXITED (status));
ASSERT (WEXITSTATUS (status) == 42);
if (i)
- {
- ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1);
- ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1);
- }
+ {
+ ASSERT (dup2 (STDIN_FILENO, STDIN_FILENO) == -1);
+ ASSERT (dup2 (STDOUT_FILENO, STDOUT_FILENO) == -1);
+ }
}
free (cmd);
return 0;