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'.
24 # We still need a little hack to make ./defs work outside automake's
25 # tree 'tests' subdirectory. Not a big deal.
26 sed "s|^am_top_builddir=.*|am_top_builddir='`pwd`'|" \
27 "$am_top_builddir"/defs-static >defs-static
28 diff "$am_top_builddir"/defs-static defs-static \
29 && fatal_ "failed to edit defs-static"
30 cp "$am_top_builddir"/defs .
32 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
33 keep_testdirs=; unset keep_testdirs
35 if ln -s defs foo && test -h foo; then
40 export have_symlinks # Is used also by spawned shells.
42 # Don't let a failure poison all subsequent tests.
45 # Don't try to be smart and use find here, that has caused issues
46 # and extra ERROR results in the past. Be dumb and safe.
47 for d in t t/* t/*/* t/*/*/*; do
48 test ! -d $d || chmod u+rwx $d || :
53 # Exporting 'keep_testdirs' to "yes" in the environment should cause
54 # the cleanup code not to be run, so that the temporary directories
56 command_ok_ '"keep_testdirs=yes" causes testdir to be kept around' eval '
57 env keep_testdirs=yes \
58 $AM_TEST_RUNNER_SHELL -c ". ./defs && echo okok >foo" t/dummy.sh \
59 && test -f t/dummy.dir/foo \
60 && test okok = `cat t/dummy.dir/foo`'
64 # Check that pre-test cleanup works also with directories with
65 # "null" permissions, and containing broken symlinks.
66 mkdir t t/dummy.dir t/dummy.dir/sub
70 if test $have_symlinks = yes; then
75 chmod 000 t/dummy.dir/sub/* t/dummy.dir/file
76 test $have_symlinks = yes && chmod 000 t/dummy.dir/symlink
77 chmod 500 t/dummy.dir/sub t/dummy.dir
78 command_ok_ "pre-cleanup can deal with low-perms testdir" \
79 $AM_TEST_RUNNER_SHELL -c '. ./defs' t/dummy.sh
80 command_ok_ "pre-cleanup removed low-perms testdir" \
81 eval 'test ! -f t/dummy.dir \
82 && test ! -d t/dummy.dir \
83 && test ! -r t/dummy.dir'
87 # Check that post-test cleanup works also with directories with
88 # "null" permissions, and containing broken symlinks.
89 command_ok_ "post-cleanup can deal with low-perms testdir" \
90 $AM_TEST_RUNNER_SHELL -c '
97 if test $have_symlinks = yes; then
102 chmod 000 dir/sub/* dir/file
103 test $have_symlinks = yes && chmod 000 dir/symlink
104 chmod 500 dir/sub dir
107 command_ok_ "post-cleanup removed null-perms testdir" \
108 eval 'test ! -f t/dummy.dir \
109 && test ! -d t/dummy.dir \
110 && test ! -r t/dummy.dir'
114 # Check that pre-test cleanup does not unduly change the permissions of
115 # files to which symlinks in the temporary test directory point to.
116 if test $have_symlinks = yes; then
124 (cd t/dummy.dir && ln -s ../../dir ../../file .)
126 command_ok_ "pre-cleanup with testdir with zero-perms symlinks" \
127 $AM_TEST_RUNNER_SHELL -c '. ./defs' t/dummy.sh
128 ls -l # For debugging.
129 command_ok_ "pre-cleanup chmod doesn't follow symlinks to files" \
130 eval 'ls -l file | grep "^----------.*file"'
131 command_ok_ "pre-cleanup chmod doesn't follow symlinks to dirs" \
132 eval 'ls -ld dir | grep "^d---------.*dir"'
134 command_ok_ "post-cleanup with testdir with zero-perms symlinks" \
135 $AM_TEST_RUNNER_SHELL -c '
139 ln -s "$ocwd/dir" "$ocwd/file" .
141 ls -l # For debugging.
142 command_ok_ "post-cleanup chmod doesn't follow symlinks to files" \
143 eval 'ls -l file | grep "^----------.*file"'
144 command_ok_ "post-cleanup chmod doesn't follow symlinks to dirs" \
145 eval 'ls -ld dir | grep "^d---------.*dir"'
151 else # $have_symlinks = no
152 skip_row_ 6 "symlinks not supported"
157 # Check that the cleanup trap does not remove the temporary
158 # test directory in case of test failure, skip, hard-error,
159 # or when receiving a signal.
161 for st in 1 2 3 10 77 99 126 127 130 255; do
162 command_ok_ "exit trap doesn't clobber exit status $st" \
163 not $AM_TEST_RUNNER_SHELL -c "
169 command_ok_ "testdir not removed if exiting with status $st" \
170 test -f t/dummy.dir/foo
174 for sig in 1 2 3 9 13 15; do
175 if is_blocked_signal $sig; then
176 skip_row_ 2 -r "signal $sig seems blocked"
179 command_ok_ "exit trap doesn't clobber signal $sig" \
180 not $AM_TEST_RUNNER_SHELL -c "
186 command_ok_ "testdir not removed if getting signal $sig" \
187 test -f t/dummy.dir/foo