Merge branch 'minor'
[automake.git] / t / uninstall-fail.sh
blobd712f8c6f4b6a7aa047c42c4b5da2acca706fc4b
1 #! /bin/sh
2 # Copyright (C) 2011-2017 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)
7 # any later version.
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 <https://www.gnu.org/licenses/>.
17 # "make uninstall" complains and errors out on failures.
19 # FIXME: this test only deal with DATA primary; maybe we need sister
20 # tests for other primaries too? E.g., SCRIPTS, PROGRAMS, LISP, PYTHON,
21 # etc...
23 . test-init.sh
25 mkdir d
26 : > d/f
27 chmod a-w d || skip "cannot make directories unwritable"
29 # On Solaris 10, if '/bin/rm' is run with the '-f' option, it doesn't
30 # print any error message when failing to remove a file (due to e.g.,
31 # "Permission denied"). And it gets weirder. On OpenIndiana 11, the
32 # /bin/sh shell (in many respects a decent POSIX shell) seems to somehow
33 # "eat" the error message from 'rm' in some situation, although the 'rm'
34 # utility itself correctly prints it when invoked from (say) 'env' or
35 # 'bash'. Yikes.
36 # We'll cater to these incompatibilities by relaxing a test below if
37 # a faulty shell or 'rm' program is detected.
38 st=0; $SHELL -c 'rm -f d/f' 2>stderr || st=$?
39 cat stderr >&2
40 test $st -gt 0 || skip_ "can delete files from unwritable directories"
41 if grep 'rm:' stderr; then
42 rm_f_is_silent_on_error=no
43 else
44 rm_f_is_silent_on_error=yes
47 cat >> configure.ac << 'END'
48 AC_OUTPUT
49 END
51 cat > Makefile.am << 'END'
52 data_DATA = foobar.txt
53 END
55 : > foobar.txt
57 $ACLOCAL
58 $AUTOMAKE
59 $AUTOCONF
61 # Weird name, to make it harder to experience false positives when
62 # grepping error messages.
63 inst=__inst-dir__
65 ./configure --prefix="$(pwd)/$inst"
67 mkdir $inst $inst/share
68 : > $inst/share/foobar.txt
70 chmod a-w $inst/share
71 run_make -M -e FAIL uninstall
72 if test $rm_f_is_silent_on_error = yes; then
73 : "rm -f" is silent on errors, skip the grepping of make output
74 else
75 grep "rm: .*foobar\.txt" output
78 chmod a-rwx $inst/share
79 (cd $inst/share) && skip_ "cannot make directories fully unreadable"
81 run_make -M -e FAIL uninstall
83 # Some shells, like Solaris 10 /bin/ksh and /usr/xpg4/bin/sh, do not
84 # report the name of the 'cd' builtin upon a chdir error:
86 # $ /bin/ksh -c 'cd /none'
87 # /bin/ksh: /none: not found
89 # and also print a line number in the error message *if the command
90 # contains newlines*:
92 # $ /bin/ksh -c 'cd unreadable'
93 # /bin/ksh: unreadable: permission denied
94 # $ /bin/ksh -c '\
95 # > \
96 # > cd unreadable'
97 # /bin/ksh[3]: unreadable: permission denied
99 $EGREP "(cd|sh)(\[[0-9]*[0-9]\])?: .*$inst/share" output