tests: use macros.h in more places
authorEric Blake <ebb9@byu.net>
Fri, 25 Dec 2009 23:06:48 +0000 (16:06 -0700)
committerEric Blake <ebb9@byu.net>
Sat, 26 Dec 2009 18:03:54 +0000 (11:03 -0700)
Make the ASSERT macro a bit more reusable.

* tests/macros.h (ASSERT): Depend on ASSERT_STREAM.
(ASSERT_STREAM): Provide default of stderr.
* tests/test-dirent-safer.c: Include macros.h, using alternate
stream for assertions.
* tests/test-dup-safer.c: Likewise.
* tests/test-freopen-safer.c: Likewise.
* tests/test-getopt.c: Likewise.
* tests/test-openat-safer.c: Likewise.
* tests/test-pipe.c: Likewise.
* tests/test-popen-safer.c: Likewise.
* modules/dirent-safer-tests (Files): Include macros.h.
* modules/unistd-safer-tests (Files): Likewise.
* modules/freopen-safer-tests (Files): Likewise.
* modules/getopt-posix-tests (Files): Likewise.
* modules/openat-safer-tests (Files): Likewise.
* modules/pipe-tests (Files): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
15 files changed:
ChangeLog
modules/dirent-safer-tests
modules/freopen-safer-tests
modules/getopt-posix-tests
modules/openat-safer-tests
modules/pipe-tests
modules/unistd-safer-tests
tests/macros.h
tests/test-dirent-safer.c
tests/test-dup-safer.c
tests/test-freopen-safer.c
tests/test-getopt.c
tests/test-openat-safer.c
tests/test-pipe.c
tests/test-popen-safer.c

index f17fd9555ce0e51a9dcc7ee84c3a2c6cb382812f..fbf1354d8502df1239ed3f9ddf54abf45a4ab91e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2009-12-26  Eric Blake  <ebb9@byu.net>
+
+       tests: use macros.h in more places
+       * tests/macros.h (ASSERT): Depend on ASSERT_STREAM.
+       (ASSERT_STREAM): Provide default of stderr.
+       * tests/test-dirent-safer.c: Include macros.h, using alternate
+       stream for assertions.
+       * tests/test-dup-safer.c: Likewise.
+       * tests/test-freopen-safer.c: Likewise.
+       * tests/test-getopt.c: Likewise.
+       * tests/test-openat-safer.c: Likewise.
+       * tests/test-pipe.c: Likewise.
+       * tests/test-popen-safer.c: Likewise.
+       * modules/dirent-safer-tests (Files): Include macros.h.
+       * modules/unistd-safer-tests (Files): Likewise.
+       * modules/freopen-safer-tests (Files): Likewise.
+       * modules/getopt-posix-tests (Files): Likewise.
+       * modules/openat-safer-tests (Files): Likewise.
+       * modules/pipe-tests (Files): Likewise.
+
 2009-12-26  Bruno Haible  <bruno@clisp.org>
 
        javacomp: Portability fix.
index da87778917348c613fb10bbb9ebb88be86ce14b1..2bc95933fdb6293d4dae2c07d28565b77aeff3e3 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-dirent-safer.c
+tests/macros.h
 
 Depends-on:
 dup2
index 9511880a293fd3da2151fdc75bf8a9ae5024b388..048d8a2a4403d30424ca3465b2f90f8586883202 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-freopen-safer.c
+tests/macros.h
 
 Depends-on:
 
index 438b6e4c1d307fc53cac64592e90356101c55aea..9c73d08b7ba93ddd05aac1b06b7929bf24c33285 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/macros.h
 tests/signature.h
 tests/test-getopt.c
 tests/test-getopt.h
index 20bf3822d284fdf32037fc3cb7349428e8565cf8..1f0b158fc0634dc4fc91cd84347126c4a5fa0ad3 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-openat-safer.c
+tests/macros.h
 
 Depends-on:
 
index 14d1e0fef15cea27ffcde1028d6b56f431225faa..0e31a865a6c0e822e9cfee0f46372930b0d966c0 100644 (file)
@@ -1,6 +1,7 @@
 Files:
 tests/test-pipe.sh
 tests/test-pipe.c
+tests/macros.h
 
 Depends-on:
 progname
index a6da5a9bd5edf8c44a31e0c5690aadcea9e62c1c..cc4b97ab3b4d1f42c41558c6f95934af4a441a0f 100644 (file)
@@ -1,5 +1,6 @@
 Files:
 tests/test-dup-safer.c
+tests/macros.h
 
 Depends-on:
 binary-io
index dc55fbe02eb195fd387655b6bbca552c81149242..b29378e9443298a06af619d64d04b28540818854 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 
+/* Define ASSERT_STREAM before including this file if ASSERT must
+   target a stream other than stderr.  */
+#ifndef ASSERT_STREAM
+# define ASSERT_STREAM stderr
+#endif
+
 /* ASSERT (condition);
    verifies that the specified condition is fulfilled.  If not, a message
-   is printed to stderr and the program is terminated with an error code.
+   is printed to ASSERT_STREAM if defined (defaulting to stderr if
+   undefined) and the program is terminated with an error code.
 
    This macro has the following properties:
      - The programmer specifies the expected condition, not the failure
      - On Unix platforms, the tester can debug the test program with a
        debugger (provided core dumps are enabled: "ulimit -c unlimited").
      - For the sake of platforms where no debugger is available (such as
-       some mingw systems), an error message is printed on stderr that
-       includes the source location of the ASSERT invocation.
+       some mingw systems), an error message is printed on the error
+       stream that includes the source location of the ASSERT invocation.
  */
 #define ASSERT(expr) \
   do                                                                         \
     {                                                                        \
       if (!(expr))                                                           \
         {                                                                    \
-          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
-          fflush (stderr);                                                   \
+          fprintf (ASSERT_STREAM, "%s:%d: assertion failed\n",               \
+                   __FILE__, __LINE__);                                      \
+          fflush (ASSERT_STREAM);                                            \
           abort ();                                                          \
         }                                                                    \
     }                                                                        \
index 8d5d529282734075ec8345706d640fb1609834a3..045d29b44bb33e2259b176598418ea3f41652266 100644 (file)
@@ -23,7 +23,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
 
 #include "unistd-safer.h"
    duplicate the original stderr.  */
 
 #define BACKUP_STDERR_FILENO 10
-static FILE *myerr;
+#define ASSERT_STREAM myerr
+#include "macros.h"
 
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (myerr);                                                    \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+static FILE *myerr;
 
 int
 main (void)
index 24cc9e5f377f46f97403b83236cef29dcb23b0dc..6a5c69d802d9b60e8d858415a6be52a787c61130 100644 (file)
@@ -24,8 +24,6 @@
 #include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
 
 #include "binary-io.h"
 #include "cloexec.h"
@@ -49,19 +47,10 @@ static int zero (void) { return 0; }
    duplicate the original stderr.  */
 
 #define BACKUP_STDERR_FILENO 10
-static FILE *myerr;
+#define ASSERT_STREAM myerr
+#include "macros.h"
 
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (myerr);                                                    \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+static FILE *myerr;
 
 /* Return true if FD is open.  */
 static bool
index 40ba8872d448b45574f4cf4c80a0f5f3ea39c45c..41d47dad40ac4bca6c4b7ec829b33846369b821b 100644 (file)
@@ -22,7 +22,6 @@
 #include "stdio--.h"
 
 /* Helpers.  */
-#include <stdlib.h>
 #include <unistd.h>
 
 /* This test intentionally closes stderr.  So, we arrange to have fd 10
    duplicate the original stderr.  */
 
 #define BACKUP_STDERR_FILENO 10
-static FILE *myerr;
+#define ASSERT_STREAM myerr
+#include "macros.h"
 
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (myerr);                                                    \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+static FILE *myerr;
 
 int
 main (void)
index 9502a442ef31b73d2b90c1eebbd18a475449aba3..88965902587f490c2b0fcc00c07cd0227c0f8340 100644 (file)
@@ -55,19 +55,10 @@ SIGNATURE_CHECK (getopt, int, (int, char * const[], char const *));
    duplicate the original stderr.  */
 
 #define BACKUP_STDERR_FILENO 10
-static FILE *myerr;
+#define ASSERT_STREAM myerr
+#include "macros.h"
 
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (myerr);                                                    \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+static FILE *myerr;
 
 #include "test-getopt.h"
 #if GNULIB_GETOPT_GNU
index f7091807d3466820823bb3ebcdce2adc9e58d49b..7a4960056165abe1a99d5e7c1d2b02ee69e14aaa 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <errno.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
    duplicate the original stderr.  */
 
 #define BACKUP_STDERR_FILENO 10
-static FILE *myerr;
+#define ASSERT_STREAM myerr
+#include "macros.h"
 
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (myerr);                                                    \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+static FILE *myerr;
 
 #define witness "test-openat-safer.txt"
 
index 4c298a7aa2ea0fd7b6c9d04787592c0b1e31d719..ec498f46d378364bd0715baeaa1d04876604ef40 100644 (file)
    duplicate the original stderr.  */
 
 #define BACKUP_STDERR_FILENO 10
-static FILE *myerr;
+#define ASSERT_STREAM myerr
+#include "macros.h"
 
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (myerr);                                                    \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+static FILE *myerr;
 
 /* Code executed by the child process.  argv[1] = "child".  */
 static int
index 281dae9a7abfa122f7a39af655dae4be30e97964..d9ab8313313820103c60b8eb6ac7b26796b2f53d 100644 (file)
@@ -22,7 +22,6 @@
 #include "stdio--.h"
 
 /* Helpers.  */
-#include <stdlib.h>
 #include <sys/wait.h>
 #include <unistd.h>
 
    duplicate the original stderr.  */
 
 #define BACKUP_STDERR_FILENO 10
-static FILE *myerr;
+#define ASSERT_STREAM myerr
+#include "macros.h"
 
-#define ASSERT(expr) \
-  do                                                                         \
-    {                                                                        \
-      if (!(expr))                                                           \
-        {                                                                    \
-          fprintf (myerr, "%s:%d: assertion failed\n", __FILE__, __LINE__);  \
-          fflush (myerr);                                                    \
-          abort ();                                                          \
-        }                                                                    \
-    }                                                                        \
-  while (0)
+static FILE *myerr;
 
 int
 main (int argc, char **argv)