Mercurial > hg > octave-nkf > gnulib-hg
changeset 8413:e227efdfe162
Tests for module 'atexit'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 11 Mar 2007 00:53:00 +0000 |
parents | 6db7303a6033 |
children | da8cfeefc405 |
files | ChangeLog modules/atexit-tests tests/test-atexit.c tests/test-atexit.sh |
diffstat | 4 files changed, 96 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-03-10 Bruno Haible <bruno@clisp.org> + + * modules/atexit-tests: New file. + * tests/test-atexit.sh: New file. + * tests/test-atexit.c: New file. + 2007-03-10 Bruno Haible <bruno@clisp.org> * tests/test-binary-io.sh: Use temporary filenames that are not so
new file mode 100644 --- /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
new file mode 100644 --- /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 <bruno@clisp.org>, 2007. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdlib.h> +#include <unistd.h> + +#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; +}
new file mode 100755 --- /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