xalloc-die-tests: avoid printing null pointer
authorEric Blake <ebb9@byu.net>
Tue, 17 Nov 2009 04:21:10 +0000 (21:21 -0700)
committerEric Blake <ebb9@byu.net>
Tue, 17 Nov 2009 04:33:36 +0000 (21:33 -0700)
The test leaked "(null): memory exhausted" to stderr, or crashed
for less capable printf.

* modules/xalloc-die-tests (Files, Makefile.am): Wrap execution in
shell script.
* tests/test-xalloc-die.c (program_name): Declare.
* tests/test-xalloc-die.sh (tmpfiles): New file.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
modules/xalloc-die-tests
tests/test-xalloc-die.c
tests/test-xalloc-die.sh [new file with mode: 0755]

index 0c56777..68b11aa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-11-16  Eric Blake  <ebb9@byu.net>
 
+       xalloc-die-tests: avoid printing null pointer
+       * modules/xalloc-die-tests (Files, Makefile.am): Wrap execution in
+       shell script.
+       * tests/test-xalloc-die.c (program_name): Declare.
+       * tests/test-xalloc-die.sh (tmpfiles): New file.
+
        setenv, unsetenv: work around various bugs
        * lib/setenv.c (setenv) [!HAVE_SETENV]: Resync from glibc.
        (setenv) [HAVE_SETENV]: Work around bugs.
index 03ee303..97b25e7 100644 (file)
@@ -1,9 +1,11 @@
 Files:
 tests/test-xalloc-die.c
+tests/test-xalloc-die.sh
 
 Depends-on:
 
 Makefile.am:
-TESTS += test-xalloc-die
+TESTS += test-xalloc-die.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
 XFAIL_TESTS += test-xalloc-die
 check_PROGRAMS += test-xalloc-die
index e281767..88461e8 100644 (file)
@@ -20,6 +20,8 @@
 
 #include "xalloc.h"
 
+char *program_name = "test-xalloc-die";
+
 int
 main (void)
 {
diff --git a/tests/test-xalloc-die.sh b/tests/test-xalloc-die.sh
new file mode 100755 (executable)
index 0000000..340a500
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+tmpfiles=""
+trap '__st=$?; rm -fr $tmpfiles; exit $__st' 0
+trap '__st=$?; (exit $__st); exit $__st' 1 2 3 15
+
+if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare() { diff -u "$@"; }
+elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare() { cmp -s "$@"; }
+else
+  compare() { cmp "$@"; }
+fi
+
+tmpfiles="t-xalloc-die.tmp"
+./test-xalloc-die${EXEEXT} 2> t-xalloc-die.tmp
+case $? in
+  1) ;;
+  *) (exit 1); exit 1 ;;
+esac
+
+compare - t-xalloc-die.tmp <<\EOF || { (exit 1); exit 1; }
+test-xalloc-die: memory exhausted
+EOF
+
+rm -fr $tmpfiles
+
+exit 0