tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / install-info-dir.sh
1 #! /bin/sh
2 # Copyright (C) 2011-2013 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 # Checks on the 'install-info' target.
18 # Details about the individual checks' purposes and motivations are
19 # inlined, below.
20
21 # FIXME: this test is a good candidate for a conversion to TAP,
22 # FIXME: and could be merged with 'txinfo27.sh'.
23
24 required=makeinfo
25 . test-init.sh
26
27 cwd=$(pwd) || fatal_ "cannot get current working directory"
28
29 mkdir bin
30 saved_PATH=$PATH; export saved_PATH
31 PATH=$cwd/bin$PATH_SEPARATOR$PATH; export PATH
32
33 cat >> configure.ac <<'END'
34 AC_OUTPUT
35 END
36
37 cat > Makefile.am << 'END'
38 info_TEXINFOS = foo.texi
39 END
40
41 cat > foo.texi << 'END'
42 \input texinfo
43 @setfilename foo.info
44 @c All the following directives might be required to allow older
45 @c versions of the 'install-info' program (e.g., version 4.8) to
46 @c create the 'dir' index file in ${infodir}.  Don't remove them.
47 @settitle foo
48 @dircategory Dummy utilities
49 @direntry
50 * Foo: (foo).  Does nothing at all, but has a nice name.
51 @end direntry
52 @node Top
53 Hello world!
54 @bye
55 END
56
57 $ACLOCAL
58 $AUTOMAKE -a
59 $AUTOCONF
60
61 instdir=_inst
62 destdir=_dest
63
64 ./configure --prefix="$cwd/$instdir" --infodir="$cwd/$instdir/info"
65
66 $MAKE info
67 test -f foo.info
68
69 if install-info --version; then
70   # Skip some checks even if 'install-info' is the one from dpkg, not
71   # the one from GNU info, as the former might try to create files in
72   # '/var/backups/', causing spurious failures like this for non-root
73   # users.
74   if install-info --version | $EGREP -i '(dpkg|debian) install-info'; then
75     have_installinfo=no
76   else
77     have_installinfo=yes
78   fi
79 else
80   have_installinfo=no
81 fi
82
83 # The 'install-info' target updates the '${infodir}/dir' file
84 # by default (if the 'install-info' program is available).
85 # This should happen in a normal as well as in a DESTDIR installation.
86 if test $have_installinfo = yes; then
87
88   $MAKE install-info
89   test -f $instdir/info/foo.info
90   test -f $instdir/info/dir
91   $FGREP 'Does nothing at all, but has a nice name' $instdir/info/dir
92
93   $MAKE uninstall
94   test ! -e $instdir/info/foo.info
95   $FGREP 'but has a nice name' $instdir/info/dir && exit 1
96
97   dir="$destdir/$cwd/$instdir/info"
98
99   $MAKE DESTDIR="$cwd/$destdir" install-info
100   test -f "$dir"/foo.info
101   test -f "$dir"/dir
102   $FGREP 'Does nothing at all, but has a nice name' "$dir"/dir
103   $MAKE DESTDIR="$cwd/$destdir" uninstall
104   test ! -e "$dir"/foo.info
105   $FGREP 'but has a nice name' "$dir"/dir && exit 1
106
107   unset dir
108
109 fi
110
111 rm -rf $instdir $destdir
112
113 # The 'install-info' target doesn't fail if the 'install-info'
114 # program is not available.
115 cat > bin/install-info <<'END'
116 #!/bin/sh
117 echo error from install-info >&2
118 exit 127
119 END
120 chmod a+x bin/install-info
121 run_make -M install-info
122 test -f $instdir/info/foo.info
123 test ! -e $instdir/info/dir
124 grep 'error from install-info' output && exit 1
125
126 rm -rf $instdir output
127
128 if test $have_installinfo = yes; then
129   # The 'install-info' target doesn't try to guess whether the 'install-info'
130   # is the GNU or debian version.
131   unindent > bin/install-info <<'END'
132     #!/bin/sh
133     set -e; set -u;
134     for fd in 1 2; do
135       for str in dpkg debian Debian; do
136         eval "echo This is $str install-info >&$fd"
137       done
138     done
139     PATH=$saved_PATH; export PATH
140     exec install-info ${1+"$@"}
141 END
142   $MAKE install-info
143   test -f $instdir/info/foo.info
144   test -f $instdir/info/dir
145   $MAKE uninstall
146   test ! -e $instdir/info/foo.info
147   test -f $instdir/info/dir
148   $FGREP 'but has a nice name' $instdir/info/dir && exit 1
149   : For shells with busted 'set -e'.
150 fi
151
152 rm -rf $instdir bin/install-info
153
154 # The 'AM_UPDATE_INFO_DIR' environment variable can be used to
155 # prevent the creation or update of the '${infodir}/dir' file,
156 # if set to a "no" value.
157 for val in no NO n; do
158   rm -rf $instdir
159   env AM_UPDATE_INFO_DIR="$val" $MAKE install-info
160   test -f $instdir/info/foo.info
161   test ! -e $instdir/info/dir
162 done
163
164 $MAKE install-info
165 if test $have_installinfo != yes; then
166   echo 'Does nothing at all, but has a nice name' > $instdir/info/dir
167 fi
168
169 chmod a-w $instdir/info/dir
170 for val in no NO n; do
171   env AM_UPDATE_INFO_DIR="$val" $MAKE uninstall
172   $FGREP 'Does nothing at all, but has a nice name' $instdir/info/dir
173 done
174
175 if test $have_installinfo = yes; then
176   for val in 'yes' 'who cares!'; do
177     rm -rf $instdir
178     env AM_UPDATE_INFO_DIR="$val" $MAKE install-info
179     test -f $instdir/info/foo.info
180     test -f $instdir/info/dir
181     env AM_UPDATE_INFO_DIR="$val" $MAKE uninstall
182     test ! -e $instdir/info/foo.info
183     $FGREP 'but has a nice name' $instdir/info/dir && exit 1
184     : For shells with busted 'set -e'.
185   done
186 fi
187
188 :