Tests for module 'atexit'.
authorBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2007 00:53:00 +0000 (00:53 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Mar 2007 00:53:00 +0000 (00:53 +0000)
ChangeLog
modules/atexit-tests [new file with mode: 0644]
tests/test-atexit.c [new file with mode: 0644]
tests/test-atexit.sh [new file with mode: 0755]

index 79d7e66..423e463 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 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
        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 (file)
index 0000000..29c2314
--- /dev/null
@@ -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 (file)
index 0000000..2bf4822
--- /dev/null
@@ -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;
+}
diff --git a/tests/test-atexit.sh b/tests/test-atexit.sh
new file mode 100755 (executable)
index 0000000..49c7729
--- /dev/null
@@ -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