From 20229ba96d971f97ff03ab74eeb4e7de1acccf98 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 11 Mar 2007 00:53:00 +0000 Subject: [PATCH] Tests for module 'atexit'. --- ChangeLog | 6 ++++++ modules/atexit-tests | 14 ++++++++++++++ tests/test-atexit.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ tests/test-atexit.sh | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 modules/atexit-tests create mode 100644 tests/test-atexit.c create mode 100755 tests/test-atexit.sh diff --git a/ChangeLog b/ChangeLog index 79d7e6683..423e46350 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-03-10 Bruno Haible + * modules/atexit-tests: New file. + * tests/test-atexit.sh: New file. + * tests/test-atexit.c: New file. + +2007-03-10 Bruno Haible + * tests/test-binary-io.sh: Use temporary filenames that are not so likely to clash with those of other tests (in a parallel make). * tests/test-binary-io.c: Likewise. diff --git a/modules/atexit-tests b/modules/atexit-tests new file mode 100644 index 000000000..29c231452 --- /dev/null +++ b/modules/atexit-tests @@ -0,0 +1,14 @@ +Files: +tests/test-atexit.sh +tests/test-atexit.c + +Depends-on: +unistd + +configure.ac: + +Makefile.am: +TESTS += test-atexit.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' +check_PROGRAMS += test-atexit +EXTRA_DIST += test-atexit.sh diff --git a/tests/test-atexit.c b/tests/test-atexit.c new file mode 100644 index 000000000..2bf482254 --- /dev/null +++ b/tests/test-atexit.c @@ -0,0 +1,44 @@ +/* Test of execution of program termination handlers. + Copyright (C) 2007 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 2, 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. */ + +/* Written by Bruno Haible , 2007. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#define TEMPFILE "t-atexit.tmp" + +static void +clear_temp_file () +{ + unlink (TEMPFILE); +} + +int +main (int argc, char *argv[]) +{ + atexit (clear_temp_file); + + if (argc > 1) + exit (atoi (argv[1])); + else + return 0; +} diff --git a/tests/test-atexit.sh b/tests/test-atexit.sh new file mode 100755 index 000000000..49c772917 --- /dev/null +++ b/tests/test-atexit.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles t-atexit.tmp" +# Check that an atexit handler is called when main() returns normally. +echo > t-atexit.tmp +./test-atexit${EXEEXT} +if test -f t-atexit.tmp; then + exit 1 +fi + +# Check that an atexit handler is called when the program is left +# through exit(0). +echo > t-atexit.tmp +./test-atexit${EXEEXT} 0 +if test -f t-atexit.tmp; then + exit 1 +fi + +# Check that an atexit handler is called when the program is left +# through exit(1). +echo > t-atexit.tmp +./test-atexit${EXEEXT} 1 +if test -f t-atexit.tmp; then + exit 1 +fi + +rm -fr $tmpfiles + +exit 0 -- 2.11.0