tests: rename 'tests/' => 't/', '*.test' => '*.sh'
[platform/upstream/automake.git] / t / install-info-dir.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 # 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.test'.
23
24 required=makeinfo
25 . ./defs || Exit 1
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   have_installinfo=yes
71 else
72   have_installinfo=no
73 fi
74
75 # The 'install-info' target updates the '${infodir}/dir' file
76 # by default (if the 'install-info' program is available).
77 # This should happen in a normal as well as in a DESTDIR installation.
78 if test $have_installinfo = yes; then
79
80   $MAKE install-info
81   test -f $instdir/info/foo.info
82   test -f $instdir/info/dir
83   $FGREP 'Does nothing at all, but has a nice name' $instdir/info/dir
84
85   $MAKE uninstall
86   test ! -f $instdir/info/foo.info
87   $FGREP 'but has a nice name' $instdir/info/dir && Exit 1
88
89   dir="$destdir/$cwd/$instdir/info"
90
91   $MAKE DESTDIR="$cwd/$destdir" install-info
92   test -f "$dir"/foo.info
93   test -f "$dir"/dir
94   $FGREP 'Does nothing at all, but has a nice name' "$dir"/dir
95   $MAKE DESTDIR="$cwd/$destdir" uninstall
96   test ! -f "$dir"/foo.info
97   $FGREP 'but has a nice name' "$dir"/dir && Exit 1
98
99   unset dir
100
101 fi
102
103 rm -rf $instdir $destdir
104
105 # The 'install-info' target doesn't fail if the 'install-info'
106 # program is not available.
107 cat > bin/install-info <<'END'
108 #!/bin/sh
109 echo error from install-info >&2
110 exit 127
111 END
112 chmod a+x bin/install-info
113 $MAKE install-info >output 2>&1 || { cat output; Exit 1; }
114 cat output
115 test -f $instdir/info/foo.info
116 test ! -f $instdir/info/dir
117 grep 'error from install-info' output && Exit 1
118
119 rm -rf $instdir output
120
121 if test $have_installinfo = yes; then
122   # The 'install-info' target doesn't try to guess whether the 'install-info'
123   # is the GNU or debian version.
124   unindent > bin/install-info <<'END'
125     #!/bin/sh
126     set -e; set -u;
127     for fd in 1 2; do
128       for str in dpkg debian Debian; do
129         eval "echo This is $str install-info >&$fd"
130       done
131     done
132     PATH=$saved_PATH; export PATH
133     exec install-info ${1+"$@"}
134 END
135   $MAKE install-info
136   test -f $instdir/info/foo.info
137   test -f $instdir/info/dir
138   $MAKE uninstall
139   test ! -f $instdir/info/foo.info
140   test -f $instdir/info/dir
141   $FGREP 'but has a nice name' $instdir/info/dir && Exit 1
142   : For shells with busted 'set -e'.
143 fi
144
145 rm -rf $instdir bin/install-info
146
147 # The 'AM_UPDATE_INFO_DIR' environment variable can be used to
148 # prevent the creation or update of the '${infodir}/dir' file,
149 # if set to a "no" value.
150 for val in no NO n; do
151   rm -rf $instdir
152   env AM_UPDATE_INFO_DIR="$val" $MAKE install-info
153   test -f $instdir/info/foo.info
154   test ! -f $instdir/info/dir
155 done
156
157 $MAKE install-info
158 chmod a-w $instdir/info/dir
159 for val in no NO n; do
160   env AM_UPDATE_INFO_DIR="$val" $MAKE uninstall
161   $FGREP 'Does nothing at all, but has a nice name' $instdir/info/dir
162 done
163
164 if test $have_installinfo = yes; then
165   for val in 'yes' 'who cares!'; do
166     rm -rf $instdir
167     env AM_UPDATE_INFO_DIR="$val" $MAKE install-info
168     test -f $instdir/info/foo.info
169     test -f $instdir/info/dir
170     env AM_UPDATE_INFO_DIR="$val" $MAKE uninstall
171     test ! -f $instdir/info/foo.info
172     $FGREP 'but has a nice name' $instdir/info/dir && Exit 1
173   done
174 fi
175
176 :