49dc8bbd81f2e3b77adc985f0a59db4793f2fdeb
[platform/upstream/automake.git] / tests / 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.in <<'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.in 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   incr_ check_count
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   # Use `echo > ...', not `: > ...', here and below, as Solaris 10 /bin/sh
103   # might not execute the latter (the Autoconf manual gives more details).
104   echo > Makefile.am
105   if test $override = yes; then
106     echo > configure.in
107   else
108     cp "$ocwd"/configure.stub configure.in
109   fi
110   test -z "$fetch_file" || cp "$ocwd/$fetch_file" .
111   # Read description of "test scenario" from standard input.
112   what= line= name= files=
113   while read line; do
114     case $line in
115       '== Name ==') what=NAME;;
116       '== Makefile.am ==') what=Makefile.am;;
117       '== configure.in ==') what=configure.in;;
118       '== Files ==') what=LIST;;
119       '==*') framework_failure_ "invalid input line: $line";;
120       ''|'#%'*) : Empty line or ad-hoc comment, ignore. ;;
121       *)
122         if test $what = LIST; then
123           files="$files $line"
124         elif test $what = NAME; then
125           name=$line
126         else
127           printf '%s\n' "$line" >> "$what"
128         fi
129         ;;
130     esac
131   done
132   test -n "$name" || fatal_ "name of a test case not specified"
133   if test $run_aclocal = yes; then
134     if $ACLOCAL; then
135       ok_ "[$name] aclocal.m4 rebuilt"
136       echo == aclocal.m4 ==
137       cat aclocal.m4
138     else
139       not_ok_ "[$name] aclocal failure, aclocal.m4 not rebuilt"
140     fi
141   else
142     cp "$ocwd"/aclocal.stub aclocal.m4
143   fi
144   echo == Makefile.am ==
145   cat Makefile.am
146   echo == configure.in ==
147   cat configure.in
148   echo Expected files: $files
149   mkdir "$build_aux"
150   cd ..
151   # End of "test scenario" setup.
152   set -x # Re-enable shell traces.
153   pwd
154   ls -l generic
155   # Test once with `--copy', once without.
156   for action in link copy; do
157     case $action in
158       link) opts='--add-missing';;
159       copy) opts='-a --copy';;
160          *) fatal_ "invalid value '$action' for \$action";;
161     esac
162     pfx="[$action $name]"
163     cp -R generic $action
164     cd $action
165     # If the required auxiliary files are missing, and automake is
166     # not told to install them, it should complain and error out,
167     # and also give a useful suggestion.
168     AUTOMAKE_fails -d "$pfx missing files, automake fails"
169     for f in $files; do
170       command_ok_ \
171         "$pfx warn about missing file $f" \
172         grep "required file ['\`]$build_aux/$f' not found" stderr
173       # Suggest the user to use `--add-missing'.
174       command_ok_ \
175         "$pfx suggest --add-missing for $f" \
176         grep ".*--add-missing.* install .*$f" stderr
177     done
178     # No files should be automatically installed by automake if it
179     # is not told to.
180     if ls "$build_aux" | grep .; then r='not ok'; else r=ok; fi
181     result_ "$r" "$pfx no extra files installed"
182     AUTOMAKE_run -d "$pfx automake run successfully" -- $opts
183     ls -l . $build_aux
184     # The expected files should get installed correctly (e.g., no
185     # broken symlinks).
186     for f in $files; do
187       command_ok_ \
188         "$pfx file $f installed" \
189         test -f $build_aux/$f
190     done
191     # Automake should inform about which files it's installing.
192     for f in $files; do
193       command_ok_ \
194         "$pfx report installation of $f" \
195         grep ": installing ['\`]$build_aux/$f'$" stderr
196     done
197     # Only the expected files should be installed.  But automake always
198     # require `missing' and `install-sh', so account for them.
199     all_files="install-sh missing $files"
200     for f in $all_files; do echo $f; done | sort | uniq > files.exp
201     (cd $build_aux && ls) | sort > files.got
202     cat files.exp
203     cat files.got
204     command_ok_ \
205       "$pfx all and only expected files installed" \
206       $am_diff files.exp files.got
207     # The files should be copied by `--copy' and symlinked otherwise.
208     # But these checks make no sense on systems like MSYS/MinGW where
209     # there are no true symlinks ('ln -s' behaves like 'cp -p'), so be
210     # ready to skip the checks in that case.  See automake bug#10441.
211     for f in $files; do
212       if test $have_true_symlinks = no; then
213         skip_ -r "system lacks true symlinks" "$pfx $f is a symlink or not"
214       else
215         if test -h $build_aux/$f; then
216           is_symlink=yes
217         else
218           is_symlink=no
219         fi
220         case $action,$is_symlink in
221           link,yes)     ok_ "$pfx $f has been symlinked"     ;;
222            link,no) not_ok_ "$pfx $f has not been symlinked" ;;
223           copy,yes) not_ok_ "$pfx $f has been symlinked"     ;;
224            copy,no)     ok_ "$pfx $f has not been symlinked" ;;
225                  *)  fatal_ "invalid condition in case"      ;;
226         esac
227       fi
228     done
229     # Now that the required auxiliary files have been installed, automake
230     # should not complain anymore even if the `--add-missing' option is
231     # not used.
232     AUTOMAKE_run -d "$pfx automake finds all added files"
233     cd ..
234   done # for action in link copy
235   cd "$ocwd" || fatal_ "cannot chdir back to top-level test directory"
236 }
237
238 # Automake should always and unconditionally require the `missing'
239 # and `install-sh' scripts.
240 check_ <<'END'
241 == Name ==
242 minimal
243 == Files ==
244 install-sh missing
245 END
246
247 check_ <<'END'
248 == Name ==
249 depcomp/C
250 == Files ==
251 depcomp
252 == configure.in ==
253 AC_PROG_CC
254 == Makefile.am ==
255 bin_PROGRAMS = foo
256 END
257
258 check_ <<'END'
259 == Name ==
260 depcomp/C++
261 == Files ==
262 depcomp
263 == configure.in ==
264 AC_PROG_CXX
265 == Makefile.am ==
266 bin_PROGRAMS = foo
267 foo_SOURCES = foo.cc
268 END
269
270 check_ --run-aclocal <<'END'
271 == Name ==
272 compile
273 == Files ==
274 compile
275 == configure.in ==
276 # Using AM_PROG_CC_C_O in configure.in should be enough.  No need to
277 # use AC_PROG_CC too, nor to define xxx_PROGRAMS in Makefile.am.
278 AM_PROG_CC_C_O
279 END
280
281 # For config.guess and config.sub.
282 for mach in build host target system; do
283   MACH=`echo "$mach" | LC_ALL=C tr '[a-z]' '[A-Z]'`
284   check_ <<END
285 == Name ==
286 cfg-$mach
287 == Files ==
288 config.sub
289 config.guess
290 == configure.in ==
291 AC_CANONICAL_$MACH
292 END
293 done
294
295 check_ <<'END'
296 == Name ==
297 ylwrap/Lex
298 == Files ==
299 ylwrap
300 == configure.in ==
301 AC_PROG_CC
302 AC_PROG_LEX
303 == Makefile.am ==
304 AUTOMAKE_OPTIONS = no-dependencies
305 bin_PROGRAMS = foo
306 foo_SOURCES = foo.l
307 END
308
309 check_ <<'END'
310 == Name ==
311 ylwrap/Yacc
312 == Files ==
313 ylwrap
314 == configure.in ==
315 AC_PROG_CC
316 AC_PROG_YACC
317 == Makefile.am ==
318 AUTOMAKE_OPTIONS = no-dependencies
319 bin_PROGRAMS = foo
320 foo_SOURCES = foo.y
321 END
322
323 echo '@setfilename foo.info' > foo.texi
324 check_ --fetch-file foo.texi <<'END'
325 == Name ==
326 Texinfo
327 == Files ==
328 texinfo.tex
329 == Makefile.am ==
330 info_TEXINFOS = foo.texi
331 END
332
333 echo '@include version.texi' >> foo.texi
334 check_ --fetch-file foo.texi <<'END'
335 == Name ==
336 Texinfo/mdate-sh
337 == Files ==
338 mdate-sh
339 texinfo.tex
340 == Makefile.am ==
341 info_TEXINFOS = foo.texi
342 END
343
344 rm -f foo.texi
345
346 check_ <<'END'
347 == Name ==
348 elisp-comp
349 == Files ==
350 elisp-comp
351 == configure.in ==
352 AM_PATH_LISPDIR
353 == Makefile.am ==
354 lisp_LISP = foo.el
355 END
356
357 check_ <<'END'
358 == Name ==
359 py-compile
360 == Files ==
361 py-compile
362 == configure.in ==
363 AM_PATH_PYTHON
364 == Makefile.am ==
365 python_PYTHON = foo.py
366 END
367
368 # Try few unrelated auxiliary scripts together.
369 check_ <<'END'
370 == Name ==
371 misc
372 == Files ==
373 py-compile
374 depcomp
375 ylwrap
376 config.sub
377 config.guess
378 == configure.in ==
379 AC_CANONICAL_BUILD
380 AC_CANONICAL_HOST
381 AC_PROG_CXX
382 == Makefile.am ==
383 PYTHON = python
384 pythondir = $(prefix)/py
385 YACC = bison -y
386 bin_PROGRAMS = foo
387 foo_SOURCES = bar.yxx baz.c++
388 python_PYTHON = zardoz.py
389 END
390
391 :