From 17017b2d0c6679ca81452ce96dac91f0de9a1646 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 14 Sep 2008 13:53:02 +0200 Subject: [PATCH] Tests for module 'perror'. --- ChangeLog | 4 ++++ modules/perror-tests | 12 ++++++++++++ tests/test-perror.c | 34 ++++++++++++++++++++++++++++++++++ tests/test-perror.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 modules/perror-tests create mode 100644 tests/test-perror.c create mode 100755 tests/test-perror.sh diff --git a/ChangeLog b/ChangeLog index addc68a49d..9486336c45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2008-09-14 Bruno Haible + * 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 + +#include + +#include + +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 -- 2.30.2