tests: avoid a spurious failure on MSYS
[platform/upstream/automake.git] / t / instmany-mans.sh
1 #! /bin/sh
2 # Copyright (C) 2008-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 # Installing many files should not exceed the command line length limit.
18
19 # This is the mans sister test of 'instmany.sh', see there for details.
20
21 . test-init.sh
22
23 # In order to have a useful test on modern systems (which have a high
24 # limit, if any), use a fake install program that errors out for more
25 # than 2K characters in a command line.  The POSIX limit is 4096, but
26 # that may include space taken up by the environment.
27
28 limit=2500
29 subdir=long_subdir_name_with_many_characters
30 nfiles=81
31 list=$(seq_ 1 $nfiles)
32
33 oPATH=$PATH; export oPATH
34 nPATH=$(pwd)/x-bin$PATH_SEPARATOR$PATH; export nPATH
35
36 mkdir x-bin
37
38 sed "s|@limit@|$limit|g" >x-bin/my-install <<'END'
39 #! /bin/sh
40 # Fake install script.  This doesn't really install
41 # (the INSTALL path below would be wrong outside this directory).
42 limit=@limit@
43 PATH=$oPATH; export PATH
44 if test -z "$orig_INSTALL"; then
45   echo "$0: \$orig_INSTALL variable not set" >&2
46   exit 1
47 fi
48 len=`expr "$orig_INSTALL $*" : ".*" 2>/dev/null || echo $limit`
49 if test $len -ge $limit; then
50   echo "$0: safe command line limit of $limit characters exceeded" >&2
51   exit 1
52 fi
53 exec $orig_INSTALL "$@"
54 exit 1
55 END
56
57 # Creative quoting in the next line to please maintainer-check.
58 sed "s|@limit@|$limit|g" >x-bin/'rm' <<'END'
59 #! /bin/sh
60 limit=@limit@
61 PATH=$oPATH; export PATH
62 RM='rm -f'
63 len=`expr "$RM $*" : ".*" 2>/dev/null || echo $limit`
64 if test $len -ge $limit; then
65   echo "$0: safe command line limit of $limit characters exceeded" >&2
66   exit 1
67 fi
68 exec $RM "$@"
69 exit 1
70 END
71
72 # Creative quoting in the next line to please maintainer-check.
73 chmod +x x-bin/'rm' x-bin/my-install
74
75 cat > setenv.in <<'END'
76 orig_INSTALL='@INSTALL@'; export orig_INSTALL
77 END
78
79 cat >>configure.ac <<END
80 AC_CONFIG_FILES([setenv.sh:setenv.in])
81 AC_CONFIG_FILES([$subdir/Makefile])
82 AC_OUTPUT
83 END
84
85 cat >Makefile.am <<END
86 SUBDIRS = $subdir
87 END
88
89 mkdir $subdir
90 cd $subdir
91
92 cat >Makefile.am <<'END'
93 man_MANS =
94 man3_MANS =
95 notrans_man_MANS =
96 notrans_man3_MANS =
97 END
98
99 for n in $list; do
100   unindent >>Makefile.am <<END
101     man_MANS += page$n.1
102     man3_MANS += page$n.man
103     notrans_man_MANS += npage$n.1
104     notrans_man3_MANS += npage$n.man
105 END
106   echo >page$n.1
107   echo >page$n.man
108   echo >npage$n.1
109   echo >npage$n.man
110 done
111
112 cd ..
113 $ACLOCAL
114 $AUTOCONF
115 $AUTOMAKE --add-missing
116
117 instdir=$(pwd)/inst
118 mkdir build
119 cd build
120 ../configure --prefix="$instdir"
121 . ./setenv.sh
122 test -n "$orig_INSTALL"
123 $MAKE
124 # Try whether native install (or install-sh) works.
125 $MAKE install
126 test -f "$instdir/share/man/man1/page1.1"
127 # Multiple uninstall should work, too.
128 $MAKE uninstall
129 $MAKE uninstall
130 test $(find "$instdir" -type f -print | wc -l) -eq 0
131
132 # Try whether we don't exceed the low limit.
133 PATH=$nPATH; export PATH
134 run_make INSTALL=my-install install
135 test -f "$instdir/share/man/man1/page1.1"
136 run_make INSTALL=my-install uninstall
137 test $(find "$instdir" -type f -print | wc -l) -eq 0
138 PATH=$oPATH; export PATH
139
140 cd $subdir
141 srcdir=../../$subdir
142
143 # Ensure 'make install' fails when 'install' fails.
144
145 # We cheat here, for efficiency, knowing the internal rule names.
146 # For correctness, one should '$MAKE install' here always, or at
147 # least use install-exec or install-data.
148
149 for file in page3.1 page$nfiles.1 npage3.1 npage$nfiles.1; do
150   chmod a-r $srcdir/$file
151   test ! -r $srcdir/$file || skip_ "cannot drop file read permissions"
152   $MAKE install-man1 && exit 1
153   chmod u+r $srcdir/$file
154 done
155
156 for file in page3.man page$nfiles.man npage3.man npage$nfiles.man; do
157   chmod a-r $srcdir/$file
158   $MAKE install-man3 && exit 1
159   chmod u+r $srcdir/$file
160 done
161
162 :