2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Sanity check for the automake testsuite.
18 # Check creation/removal of temporary test working directory by './defs'.
22 if test x"$sh_errexit_works" != x"yes"; then
23 skip_all_ "$me: no working exit trap with 'set -e'"
28 # We still need a little hack to make ./defs work outside automake's
29 # tree 'tests' subdirectory. Not a big deal.
30 sed "s|^am_top_builddir=.*|am_top_builddir='`pwd`'|" \
31 "$am_top_builddir"/defs-static >defs-static
32 diff "$am_top_builddir"/defs-static defs-static \
33 && fatal_ "failed to edit defs-static"
34 cp "$am_top_builddir"/defs .
36 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
37 keep_testdirs=; unset keep_testdirs
39 if ln -s defs foo && test -h foo; then
44 export have_symlinks # Is used also by spawned shells.
46 # Don't let a failure poison all subsequent tests.
49 # Don't try to be smart and use find here, that has caused issues
50 # and extra ERROR results in the past. Be dumb and safe.
51 for d in t t/* t/*/* t/*/*/*; do
52 test ! -d $d || chmod u+rwx $d || :
57 # Exporting 'keep_testdirs' to "yes" in the environment should cause
58 # the cleanup code not to be run, so that the temporary directories
60 command_ok_ '"keep_testdirs=yes" causes testdir to be kept around' eval '
61 keep_testdirs=yes $SHELL -c ". ./defs && echo okok >foo" t/dummy.sh \
62 && test -f t/dummy.dir/foo \
63 && test okok = `cat t/dummy.dir/foo`'
67 # Check that pre-test cleanup works also with directories with
68 # "null" permissions, and containing broken symlinks.
69 mkdir t t/dummy.dir t/dummy.dir/sub
73 if test $have_symlinks = yes; then
78 chmod 000 t/dummy.dir/sub/* t/dummy.dir/file
79 test $have_symlinks = yes && chmod 000 t/dummy.dir/symlink
80 chmod 500 t/dummy.dir/sub t/dummy.dir
81 command_ok_ "pre-cleanup can deal with low-perms testdir" \
82 $SHELL -c '. ./defs' t/dummy.sh
83 command_ok_ "pre-cleanup removed low-perms testdir" \
84 eval 'test ! -f t/dummy.dir \
85 && test ! -d t/dummy.dir \
86 && test ! -r t/dummy.dir'
90 # Check that post-test cleanup works also with directories with
91 # "null" permissions, and containing broken symlinks.
92 command_ok_ "post-cleanup can deal with low-perms testdir" \
100 if test $have_symlinks = yes; then
102 ln -s none brokenlink
105 chmod 000 dir/sub/* dir/file
106 test $have_symlinks = yes && chmod 000 dir/symlink
107 chmod 500 dir/sub dir
110 command_ok_ "post-cleanup removed null-perms testdir" \
111 eval 'test ! -f t/dummy.dir \
112 && test ! -d t/dummy.dir \
113 && test ! -r t/dummy.dir'
117 # Check that pre-test cleanup does not unduly change the permissions of
118 # files to which symlinks in the temporary test directory point to.
119 if test $have_symlinks = yes; then
127 (cd t/dummy.dir && ln -s ../../dir ../../file .)
129 command_ok_ "pre-cleanup with testdir with zero-perms symlinks" \
130 $SHELL -c '. ./defs' t/dummy.sh
131 ls -l # For debugging.
132 command_ok_ "pre-cleanup chmod doesn't follow symlinks to files" \
133 eval 'ls -l file | grep "^----------.*file"'
134 command_ok_ "pre-cleanup chmod doesn't follow symlinks to dirs" \
135 eval 'ls -ld dir | grep "^d---------.*dir"'
137 command_ok_ "post-cleanup with testdir with zero-perms symlinks" \
142 ln -s "$ocwd/dir" "$ocwd/file" .
144 ls -l # For debugging.
145 command_ok_ "post-cleanup chmod doesn't follow symlinks to files" \
146 eval 'ls -l file | grep "^----------.*file"'
147 command_ok_ "post-cleanup chmod doesn't follow symlinks to dirs" \
148 eval 'ls -ld dir | grep "^d---------.*dir"'
154 else # $have_symlinks = no
155 skip_row_ 6 "symlinks not supported"
160 # Check that the cleanup trap does not remove the temporary
161 # test directory in case of test failure, skip, hard-error,
162 # or when receiving a signal.
164 for st in 1 2 3 10 77 99 126 127 130 255; do
165 command_ok_ "exit trap doesn't clobber exit status $st" not $SHELL -c "
171 command_ok_ "testdir not removed if exiting with status $st" \
172 test -f t/dummy.dir/foo
176 for sig in 1 2 3 9 13 15; do
177 if is_blocked_signal $sig; then
178 skip_row_ 2 -r "signal $sig seems blocked"
181 command_ok_ "exit trap doesn't clobber signal $sig" not $SHELL -c "
187 command_ok_ "testdir not removed if getting signal $sig" \
188 test -f t/dummy.dir/foo