Tests for module 'perror'.
authorBruno Haible <bruno@clisp.org>
Sun, 14 Sep 2008 11:53:02 +0000 (13:53 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 14 Sep 2008 11:53:02 +0000 (13:53 +0200)
ChangeLog
modules/perror-tests [new file with mode: 0644]
tests/test-perror.c [new file with mode: 0644]
tests/test-perror.sh [new file with mode: 0755]

index addc68a49de96ca74f23f78160e01d4a9e35d4d3..9486336c45137a940c43e97f20608fcfadad1a1a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2008-09-14  Bruno Haible  <bruno@clisp.org>
 
+       * modules/perror-tests: New file.
+       * tests/test-perror.sh: New file.
+       * tests/test-perror.c: New file.
+
        New module 'perror'.
        * lib/stdio.in.h (perror): New declaration.
        * lib/perror.c: New file.
diff --git a/modules/perror-tests b/modules/perror-tests
new file mode 100644 (file)
index 0000000..52d30bd
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-perror.c
+tests/test-perror.sh
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-perror.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
+check_PROGRAMS += test-perror
diff --git a/tests/test-perror.c b/tests/test-perror.c
new file mode 100644 (file)
index 0000000..2faa8ae
--- /dev/null
@@ -0,0 +1,34 @@
+/* Test of perror() function.
+   Copyright (C) 2008 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
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+  const char *prefix = (argc > 1 ? argv[1] : NULL);
+
+  errno = EACCES;    perror (prefix);
+  errno = ETIMEDOUT; perror (prefix);
+  errno = EOVERFLOW; perror (prefix);
+
+  return 0;
+}
diff --git a/tests/test-perror.sh b/tests/test-perror.sh
new file mode 100755 (executable)
index 0000000..3ab20ab
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+# Test NULL prefix. Result should not contain a number.
+tmpfiles="$tmpfiles t-perror.tmp"
+./test-perror${EXEEXT} 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror.tmp
+if grep '[0-9]' t-perror.tmp > /dev/null; then
+  rm -fr $tmpfiles; exit 1
+fi
+
+# Test empty prefix. Result should be the same.
+tmpfiles="$tmpfiles t-perror1.tmp"
+./test-perror${EXEEXT} '' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror1.tmp
+diff t-perror.tmp t-perror1.tmp
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+# Test non-empty prefix.
+tmpfiles="$tmpfiles t-perror2.tmp t-perror3.tmp"
+./test-perror${EXEEXT} 'foo' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror3.tmp
+sed -e 's/^/foo: /' < t-perror.tmp > t-perror2.tmp
+diff t-perror2.tmp t-perror3.tmp
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+exit 0