Merge branch 'elisp-work'
[platform/upstream/automake.git] / t / add-missing.tap
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 # Test that automake complains when required auxiliary files are not
18 # found, and that 'automake --add-missing' installs the files (and only
19 # the files) it's supposed to, and that these files are symlinked by
20 # default, but copied if the '--copy' option is used.
21
22 am_create_testdir=empty
23 . ./defs || exit 1
24
25 plan_ "later"
26
27 build_aux=build-aux
28 ocwd=$(pwd) || fatal_ "cannot get current working directory"
29
30 # Try to improve readability of displayed diffs.
31 if diff -u /dev/null /dev/null; then
32   am_diff='diff -u'
33 elif diff -c /dev/null /dev/null; then
34   am_diff='diff -c'
35 else
36   am_diff=diff
37 fi
38
39 # MinGW/MSYS lacks real symlinks, so we'll have to skip some checks
40 # on that system.  More details below.
41 echo dummy > foo
42 if ln -s foo bar && test -h bar; then
43   have_true_symlinks=yes
44 else
45   have_true_symlinks=no
46 fi
47 rm -f foo bar
48
49 cat > configure.stub << END
50 AC_INIT([$me], [1.0])
51 AC_CONFIG_AUX_DIR([$build_aux])
52 AM_INIT_AUTOMAKE
53 AC_CONFIG_FILES([Makefile])
54 END
55
56 # Pre-compute aclocal.m4, in order to save several aclocal invocations.
57 cat configure.stub - > configure.ac <<'END'
58 AC_PROG_CC
59 AC_CANONICAL_BUILD
60 AC_CANONICAL_HOST
61 AC_CANONICAL_TARGET
62 AC_CANONICAL_SYSTEM
63 AM_PATH_LISPDIR
64 AM_PATH_PYTHON
65 END
66 $ACLOCAL || framework_failure_ "cannot pre-compute aclocal.m4"
67
68 rm -rf configure.ac autom4te*.cache
69 mv aclocal.m4 aclocal.stub
70
71 # For debugging.
72 cat configure.stub
73 cat aclocal.stub
74
75 check_count=0
76
77 # This is hacky and ugly and complex, but allow us to organize our tests
78 # below in a more "declarative fashion".  All in all, a good trade-off.
79 check_ ()
80 {
81   set +x # Temporary disable shell traces to remove noise from log files.
82   check_count=$(($check_count + 1))
83   echo check count: $check_count
84   override=no
85   run_aclocal=no
86   fetch_file=
87   while test $# -gt 0; do
88     case $1 in
89       --override) override=yes;;
90       --run-aclocal) run_aclocal=yes;;
91       --fetch-file) fetch_file=$2; shift;;
92       *) framework_failure_ "check_: invalid argument '$1'";;
93     esac
94     shift
95   done
96   mkdir testdir-$check_count
97   cd testdir-$check_count
98   # Directory for common data files (specific to the current test, but
99   # shared by its "subtests").
100   mkdir generic
101   cd generic
102   : > Makefile.am
103   if test $override = yes; then
104     : > configure.ac
105   else
106     cp "$ocwd"/configure.stub configure.ac
107   fi
108   test -z "$fetch_file" || cp "$ocwd/$fetch_file" .
109   # Read description of "test scenario" from standard input.
110   what= line= name= files=
111   while read line; do
112     case $line in
113       '== Name ==') what=NAME;;
114       '== Makefile.am ==') what=Makefile.am;;
115       '== configure.ac ==') what=configure.ac;;
116       '== Files ==') what=LIST;;
117       '==*') framework_failure_ "invalid input line: $line";;
118       ''|'#%'*) : Empty line or ad-hoc comment, ignore. ;;
119       *)
120         if test $what = LIST; then
121           files="$files $line"
122         elif test $what = NAME; then
123           name=$line
124         else
125           printf '%s\n' "$line" >> "$what"
126         fi
127         ;;
128     esac
129   done
130   test -n "$name" || fatal_ "name of a test case not specified"
131   if test $run_aclocal = yes; then
132     if $ACLOCAL; then
133       ok_ "[$name] aclocal.m4 rebuilt"
134       echo == aclocal.m4 ==
135       cat aclocal.m4
136     else
137       not_ok_ "[$name] aclocal failure, aclocal.m4 not rebuilt"
138     fi
139   else
140     cp "$ocwd"/aclocal.stub aclocal.m4
141   fi
142   echo == Makefile.am ==
143   cat Makefile.am
144   echo == configure.ac ==
145   cat configure.ac
146   echo Expected files: $files
147   mkdir "$build_aux"
148   cd ..
149   # End of "test scenario" setup.
150   set -x # Re-enable shell traces.
151   pwd
152   ls -l generic
153   # Test once with '--copy', once without.
154   for action in link copy; do
155     case $action in
156       link) opts='--add-missing';;
157       copy) opts='-a --copy';;
158          *) fatal_ "invalid value '$action' for \$action";;
159     esac
160     pfx="[$action $name]"
161     cp -R generic $action
162     cd $action
163     # If the required auxiliary files are missing, and automake is
164     # not told to install them, it should complain and error out,
165     # and also give a useful suggestion.
166     AUTOMAKE_fails -d "$pfx missing files, automake fails"
167     for f in $files; do
168       command_ok_ \
169         "$pfx warn about missing file $f" \
170         $FGREP "required file '$build_aux/$f' not found" stderr
171       # Suggest the user to use '--add-missing'.
172       command_ok_ \
173         "$pfx suggest --add-missing for $f" \
174         grep ".*--add-missing.* install .*'$f'" stderr
175     done
176     # No files should be automatically installed by automake if it
177     # is not told to.
178     if ls "$build_aux" | grep .; then r='not ok'; else r=ok; fi
179     result_ "$r" "$pfx no extra files installed"
180     AUTOMAKE_run -d "$pfx automake run successfully" -- $opts
181     ls -l . $build_aux
182     # The expected files should get installed correctly (e.g., no
183     # broken symlinks).
184     for f in $files; do
185       command_ok_ \
186         "$pfx file $f installed" \
187         test -f $build_aux/$f
188     done
189     # Automake should inform about which files it's installing.
190     for f in $files; do
191       command_ok_ \
192         "$pfx report installation of $f" \
193         $FGREP ": installing '$build_aux/$f'" stderr
194     done
195     # Only the expected files should be installed.  But automake always
196     # require 'missing' and 'install-sh', so account for them.
197     all_files="install-sh missing $files"
198     for f in $all_files; do echo $f; done | sort | uniq > files.exp
199     (cd $build_aux && ls) | sort > files.got
200     cat files.exp
201     cat files.got
202     command_ok_ \
203       "$pfx all and only expected files installed" \
204       $am_diff files.exp files.got
205     # The files should be copied by '--copy' and symlinked otherwise.
206     # But these checks make no sense on systems like MSYS/MinGW where
207     # there are no true symlinks ('ln -s' behaves like 'cp -p'), so be
208     # ready to skip the checks in that case.  See automake bug#10441.
209     for f in $files; do
210       if test $have_true_symlinks = no; then
211         skip_ -r "system lacks true symlinks" "$pfx $f is a symlink or not"
212       else
213         if test -h $build_aux/$f; then
214           is_symlink=yes
215         else
216           is_symlink=no
217         fi
218         case $action,$is_symlink in
219           link,yes)     ok_ "$pfx $f has been symlinked"     ;;
220            link,no) not_ok_ "$pfx $f has not been symlinked" ;;
221           copy,yes) not_ok_ "$pfx $f has been symlinked"     ;;
222            copy,no)     ok_ "$pfx $f has not been symlinked" ;;
223                  *)  fatal_ "invalid condition in case"      ;;
224         esac
225       fi
226     done
227     # Now that the required auxiliary files have been installed, automake
228     # should not complain anymore even if the '--add-missing' option is
229     # not used.
230     AUTOMAKE_run -d "$pfx automake finds all added files"
231     cd ..
232   done # for action in link copy
233   cd "$ocwd" || fatal_ "cannot chdir back to top-level test directory"
234 }
235
236 # Automake should always and unconditionally require the 'missing'
237 # and 'install-sh' scripts.
238 check_ <<'END'
239 == Name ==
240 minimal
241 == Files ==
242 install-sh missing
243 END
244
245 check_ <<'END'
246 == Name ==
247 depcomp/C
248 == Files ==
249 depcomp
250 == configure.ac ==
251 AC_PROG_CC
252 == Makefile.am ==
253 bin_PROGRAMS = foo
254 END
255
256 check_ <<'END'
257 == Name ==
258 depcomp/C++
259 == Files ==
260 depcomp
261 == configure.ac ==
262 AC_PROG_CXX
263 == Makefile.am ==
264 bin_PROGRAMS = foo
265 foo_SOURCES = foo.cc
266 END
267
268 check_ --run-aclocal <<'END'
269 == Name ==
270 compile
271 == Files ==
272 compile
273 == configure.ac ==
274 # Using AM_PROG_CC_C_O in configure.ac should be enough.  No need to
275 # use AC_PROG_CC too, nor to define xxx_PROGRAMS in Makefile.am.
276 AM_PROG_CC_C_O
277 END
278
279 # For config.guess and config.sub.
280 for mach in build host target system; do
281   MACH=$(echo "$mach" | LC_ALL=C tr '[a-z]' '[A-Z]')
282   check_ <<END
283 == Name ==
284 cfg-$mach
285 == Files ==
286 config.sub
287 config.guess
288 == configure.ac ==
289 AC_CANONICAL_$MACH
290 END
291 done
292
293 check_ <<'END'
294 == Name ==
295 ylwrap/Lex
296 == Files ==
297 ylwrap
298 == configure.ac ==
299 AC_PROG_CC
300 AC_PROG_LEX
301 == Makefile.am ==
302 AUTOMAKE_OPTIONS = no-dependencies
303 bin_PROGRAMS = foo
304 foo_SOURCES = foo.l
305 END
306
307 check_ <<'END'
308 == Name ==
309 ylwrap/Yacc
310 == Files ==
311 ylwrap
312 == configure.ac ==
313 AC_PROG_CC
314 AC_PROG_YACC
315 == Makefile.am ==
316 AUTOMAKE_OPTIONS = no-dependencies
317 bin_PROGRAMS = foo
318 foo_SOURCES = foo.y
319 END
320
321 echo '@setfilename foo.info' > foo.texi
322 check_ --fetch-file foo.texi <<'END'
323 == Name ==
324 Texinfo
325 == Files ==
326 texinfo.tex
327 == Makefile.am ==
328 info_TEXINFOS = foo.texi
329 END
330
331 echo '@include version.texi' >> foo.texi
332 check_ --fetch-file foo.texi <<'END'
333 == Name ==
334 Texinfo/mdate-sh
335 == Files ==
336 mdate-sh
337 texinfo.tex
338 == Makefile.am ==
339 info_TEXINFOS = foo.texi
340 END
341
342 rm -f foo.texi
343
344 check_ <<'END'
345 == Name ==
346 py-compile
347 == Files ==
348 py-compile
349 == configure.ac ==
350 AM_PATH_PYTHON
351 == Makefile.am ==
352 python_PYTHON = foo.py
353 END
354
355 # Try few unrelated auxiliary scripts together.
356 check_ <<'END'
357 == Name ==
358 misc
359 == Files ==
360 py-compile
361 depcomp
362 ylwrap
363 config.sub
364 config.guess
365 == configure.ac ==
366 AC_CANONICAL_BUILD
367 AC_CANONICAL_HOST
368 AC_PROG_CXX
369 == Makefile.am ==
370 PYTHON = python
371 pythondir = $(prefix)/py
372 YACC = bison -y
373 bin_PROGRAMS = foo
374 foo_SOURCES = bar.yxx baz.c++
375 python_PYTHON = zardoz.py
376 END
377
378 :