Merge branch 'missing-not-touch-just-warn'
[platform/upstream/automake.git] / t / uninstall-fail.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2012 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
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/>.
16
17 # "make uninstall" complains and errors out on failures.
18
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...
22
23 . ./defs || Exit 1
24
25 mkdir d
26 : > d/f
27 chmod a-w d || skip "cannot make directories unwritable"
28
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").  Yikes.  We'll cater to this incompatibility
32 # by relaxing a test below if a faulty 'rm' is detected.
33 st=0; rm -f d/f 2>stderr || st=$?
34 cat stderr >&2
35 test $st -gt 0 || skip_ "can delete files from unwritable directories"
36 if grep 'rm:' stderr; then
37   rm_f_is_silent_on_error=no
38 else
39   rm_f_is_silent_on_error=yes
40 fi
41
42 cat >> configure.ac << 'END'
43 AC_OUTPUT
44 END
45
46 cat > Makefile.am << 'END'
47 data_DATA = foobar.txt
48 END
49
50 : > foobar.txt
51
52 $ACLOCAL
53 $AUTOMAKE
54 $AUTOCONF
55
56 # Make it harder to experience false postives when grepping error messages.
57 inst=__inst-dir__
58
59 ./configure --prefix="$(pwd)/$inst"
60
61 mkdir $inst $inst/share
62 : > $inst/share/foobar.txt
63
64 chmod a-w $inst/share
65 $MAKE uninstall >output 2>&1 && { cat output; Exit 1; }
66 cat output
67 if test $rm_f_is_silent_on_error = yes; then
68   : "rm -f" is silent on errors, skip the grepping of make output
69 else
70   grep "rm: .*foobar\.txt" output
71 fi
72
73 chmod a-rwx $inst/share
74 (cd $inst/share) && skip_ "cannot make directories fully unreadable"
75
76 $MAKE uninstall >output 2>&1 && { cat output; Exit 1; }
77 cat output
78 #
79 # Some shells, like Solaris 10 /bin/sh and /bin/ksh, do not report
80 # the name of the 'cd' builtin upon a chdir error:
81 #
82 #   $ /bin/sh -c 'cd /none'
83 #   /bin/sh: /none: does not exist
84 #
85 # In addition, some shells, like Solaris 10 /usr/xpg4/bin/sh, also print
86 # a line number in the error message *if the command contains newlines*:
87 #
88 #   $ /usr/xpg4/bin/sh -c 'cd unreadable'
89 #   /usr/xpg4/bin/sh: unreadable: permission denied
90 #   $ /usr/xpg4/bin/sh -c '\
91 #   > \
92 #   > cd unreadable'
93 #   /usr/xpg4/bin/sh[3]: unreadable: permission denied
94 #
95 $EGREP "(cd|sh)(\[[0-9]*[0-9]\])?: .*$inst/share" output
96
97 :