summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--modules/perror-tests12
-rw-r--r--tests/test-perror.c34
-rwxr-xr-xtests/test-perror.sh26
4 files changed, 76 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index addc68a49d..9486336c45 100644
--- 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
index 0000000000..52d30bd82c
--- /dev/null
+++ b/modules/perror-tests
@@ -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
index 0000000000..2faa8aeaf0
--- /dev/null
+++ b/tests/test-perror.c
@@ -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
index 0000000000..3ab20abfc0
--- /dev/null
+++ b/tests/test-perror.sh
@@ -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