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