tests: remove too-brittle test tap-realtime.sh
[platform/upstream/automake.git] / t / dist-formats.tap
1 #! /bin/sh
2 # Copyright (C) 2012-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 # Check support for different compression formats used by distribution
18 # archives.
19
20 am_create_testdir=empty
21 . test-init.sh
22
23 plan_ 66
24
25 # ---------------------------------------------------- #
26 #  Common and/or auxiliary subroutines and variables.  #
27 # ---------------------------------------------------- #
28
29 ocwd=$(pwd) || fatal_ "getting current working directory"
30
31 unset TAR
32
33 # Create common aclocal.m4 file, for later tests.
34 mkdir setup \
35   && cd setup \
36   && echo 'AC_INIT([x], [0]) AM_INIT_AUTOMAKE' > configure.ac \
37   && $ACLOCAL \
38   && mv aclocal.m4 .. \
39   && cd .. \
40   && rm -rf setup \
41   || fatal_ "creating common aclocal.m4 file"
42
43 # Some make implementations (e.g., HP-UX) don't grok '-j', some require
44 # no space between '-j' and the number of jobs (e.g., older GNU make
45 # versions), and some *do* require a space between '-j' and the number
46 # of jobs (e.g., Solaris dmake).  We need a runtime test to see what
47 # works.
48 for MAKE_j4 in "$MAKE -j4" "$MAKE -j 4" false; do
49   echo all: | $MAKE_j4 -f - && break
50   : For shells with buggy 'set -e'.
51 done
52
53 # Set variables '$compressor' and '$suffix'.
54 setup_vars_for_compression_format ()
55 {
56   suffix=NONE compressor=NONE
57   case $1 in
58     gzip) suffix=tar.gz  compressor=gzip     ;;
59     lzip) suffix=tar.lz  compressor=lzip     ;;
60       xz) suffix=tar.xz  compressor=xz       ;;
61    bzip2) suffix=tar.bz2 compressor=bzip2    ;;
62      zip) suffix=zip     compressor=zip      ;;
63        *) fatal_ "invalid compression format '$1'";;
64   esac
65 }
66
67 have_compressor ()
68 {
69   test $# -eq 1 || fatal_ "have_compressor(): bad usage"
70   if test $1 = gzip; then
71     # Assume gzip(1) is available on every reasonable portability target.
72     return 0
73   fi
74   needed_programs=$1
75   # Assume by default the other compressors we care about support the
76   # '--version' option.  We'll special-case the one which don't.
77   checker_option=--version
78   case $1 in
79     bzip2)
80       # Do not use --version, or older versions bzip2 would try to
81       # compress stdin.  This would cause binary output in the test
82       # logs, with potential breakage of our testsuite harness.
83       checker_option=--help
84       ;;
85     zip)
86       # OpenSolaris zip do not support the '--version' option, but
87       # accepts the '-v' one with a similar meaning (if no further
88       # arguments are given).
89       checker_option=-v
90       # Also, we need 'unzip' to decompress the created zipped archives
91       # (bug#15181).
92       needed_programs='zip unzip'
93       ;;
94   esac
95   # Redirect to stderr to avoid polluting the output, in case this
96   # function is used in a command substitution (as it is, later in
97   # this script).
98   for p in $needed_programs; do
99     $p $checker_option </dev/null >&2 || return 1
100   done
101   return 0
102 }
103
104 all_compression_formats='gzip lzip xz bzip2 zip'
105
106 all_compressors=$(
107   for x in $all_compression_formats; do
108     setup_vars_for_compression_format $x
109     echo $compressor
110   done | tr "$nl" ' ')
111 echo All compressors: $all_compressors
112
113 missing_compressors=$(
114   for c in $all_compressors; do
115     have_compressor $c || echo $c
116   done | tr "$nl" ' ')
117 echo Missing compressors: $missing_compressors
118
119 # Redefine to avoid re-running the already executed checks.
120 have_compressor ()
121 {
122   case " $missing_compressors " in *\ $1\ *) false;; *) : ;; esac
123 }
124
125 have_all_compressors ()
126 {
127   test -z "$missing_compressors"
128 }
129
130 start_subtest ()
131 {
132   name=$1; shift
133   test -n "$name" || fatal_ "start_subtest: no subtest name given"
134   if test $# -gt 0; then
135     eval "$@" || fatal_ "start_subtest: evaluating assignments"
136   fi
137   ac_opts=$(echo $ac_opts | tr ',' ' ')
138   am_opts=$(echo $am_opts | tr ',' ' ')
139   mkdir "$name"
140   cd "$name"
141   unindent > configure.ac <<END
142     AC_INIT([$name], [1.0])
143     AM_INIT_AUTOMAKE([$ac_opts])
144     AC_CONFIG_FILES([Makefile])
145     AC_OUTPUT
146 END
147   echo "AUTOMAKE_OPTIONS = $am_opts" > Makefile.am
148   # It is imperative that aclocal.m4 is copied after configure.ac has
149   # been created, to avoid a spurious trigger of the automatic remake
150   # rules for configure & co.
151   cp "$ocwd"/aclocal.m4 \
152      "$am_scriptdir"/missing \
153      "$am_scriptdir"/install-sh \
154      .
155 }
156
157 end_subtest ()
158 {
159   unset name; unset ac_opts; unset am_opts;
160   cd "$ocwd" || fatal_ "couldn't chdir back to '$ocwd'"
161 }
162
163 command_ok_if_have_compressor ()
164 {
165   if have_compressor "$compressor"; then
166     command_ok_ "$@"
167   else
168     skip_ -r "'$compressor' not available" "$1"
169   fi
170 }
171
172 can_compress ()
173 {
174   test $# -eq 2 || fatal_ "can_compress: bad number of arguments"
175   tarname=$1 format=$2
176   setup_vars_for_compression_format "$format"
177
178   command_ok_ "'dist-$format' target always created" $MAKE -n dist-$format
179
180   command_ok_if_have_compressor "'make dist-$format' work by default" \
181     eval '
182       rm -rf *$tarname* \
183         && $MAKE dist-$format \
184         && test -f $tarname-1.0.$suffix \
185         && ls -l *$tarname* \
186         && test "$(echo *$tarname*)" = $tarname-1.0.$suffix'
187
188   unset suffix compressor format tarname
189 }
190
191 # ---------------------------------------- #
192 #  Defaults layout of the dist-* targets.  #
193 # ---------------------------------------- #
194
195 start_subtest defaults
196
197 command_ok_ "default [automake]"        $AUTOMAKE
198 command_ok_ "default [autoconf]"        $AUTOCONF
199 command_ok_ "default [configure]"       ./configure
200 command_ok_ "default [make distcheck]"  $MAKE distcheck
201
202 command_ok_ "'make dist' only builds *.tar.gz by default" \
203             test "$(ls *defaults*)" = defaults-1.0.tar.gz
204
205 rm -rf *defaults*
206
207 for fmt in $all_compression_formats; do
208   can_compress defaults $fmt
209 done
210 unset fmt
211
212 end_subtest
213
214 # ----------------------------------------------------------- #
215 #  Check diagnostic for no-dist-gzip without another dist-*.  #
216 # ----------------------------------------------------------- #
217
218 nogzip_stderr ()
219 {
220   grep "$1:.*no-dist-gzip" stderr \
221     && grep "$1:.* at least one archive format must be enabled" stderr
222 }
223
224 nogzip_automake_failure ()
225 {
226   AUTOMAKE_fails -d "no-dist-gzip ($1) without other formats is an error"
227   command_ok_ "no-dist-gzip ($1) without other formats gives diagnostic" \
228               nogzip_stderr "$2"
229 }
230
231 start_subtest am-nogz-only am_opts=no-dist-gzip ac_opts=
232 nogzip_automake_failure 'am' 'Makefile\.am:1'
233 end_subtest
234
235 start_subtest ac-nogz-only am_opts= ac_opts=no-dist-gzip
236 nogzip_automake_failure 'ac' 'configure\.ac:2'
237 end_subtest
238
239 # ------------------------------------------------- #
240 #  Check use of no-dist-gzip with a dist-* option.  #
241 # ------------------------------------------------- #
242
243 append_to_opt ()
244 {
245   var=$1_opts val=$2
246   eval "$var=\${$var:+\"\$$var,\"}\$val" || fatal_ "evaluating \${$var}"
247   unset var val
248 }
249
250 nogzip ()
251 {
252   test $#,$1,$3,$5 = 6,in,and,in \
253     && case $2,$6 in ac,ac|ac,am|am,ac|am,am) :;; *) false;; esac \
254     || fatal_ "nogzip: invalid usage"
255   format=$4 where_dist_nogzip=$2 where_dist_format=$6
256   shift 6
257
258   am_opts= ac_opts=
259   append_to_opt $where_dist_format dist-$format
260   append_to_opt $where_dist_nogzip no-dist-gzip
261   setup_vars_for_compression_format "$format"
262   # Do these before the am_opts and ac_opts variable can be munged
263   # by 'start_subtest'.
264   desc=
265   test -n "$am_opts" && desc=${desc:+"$desc "}"am=$am_opts"
266   test -n "$ac_opts" && desc=${desc:+"$desc "}"ac=$ac_opts"
267
268   start_subtest nogzip-$format am_opts=$am_opts ac_opts=$ac_opts
269
270   unindent >> Makefile.am <<END
271     check-ark-name:
272         test \$(DIST_ARCHIVES) = \$(distdir).$suffix
273     check-ark-exists:
274         test -f \$(distdir).$suffix
275     check-no-tar-gz:
276         test ! -f \$(distdir).tar.gz
277 END
278
279   command_ok_ "$desc [automake]" $AUTOMAKE
280   command_ok_ "$desc [autoconf]" $AUTOCONF
281   command_ok_ "$desc [configure]" ./configure
282   command_ok_ "$desc [ark-name]" $MAKE check-ark-name
283   command_ok_if_have_compressor "$desc [distcheck]" $MAKE distcheck
284   command_ok_if_have_compressor "$desc [ark-exists]" $MAKE check-ark-exists
285   command_ok_ "$desc [no .tar.gz]"  $MAKE check-no-tar-gz
286
287   unset desc
288
289   end_subtest
290 }
291
292 #      $1 $2  $3   $4     $5  $6
293 nogzip in am  and  bzip2  in  am
294 nogzip in ac  and  xz     in  am
295 nogzip in am  and  lzip   in  ac
296 nogzip in ac  and  zip    in  ac
297
298
299 # ----------------------------------------------------------- #
300 #  The 'dist-gzip' target is created also with no-dist-gzip.  #
301 # ----------------------------------------------------------- #
302
303 start_subtest dist-gzip-persistence am_opts=no-dist-gzip,dist-xz
304 command_ok_ "dist-gzip persistence [automake]"  $AUTOMAKE
305 command_ok_ "dist-gzip persistence [autoconf]"  $AUTOCONF
306 command_ok_ "dist-gzip persistence [configure]" ./configure
307 can_compress dist-gzip-persistence gzip
308 end_subtest
309
310
311 # ----------------------- #
312 #  Parallel compression.  #
313 # ----------------------- #
314
315 # We only use formats requiring 'gzip', 'bzip2' and 'xz' programs,
316 # since there are the most likely to be all found on the majority
317 # of systems.
318
319 start_subtest parallel-compression ac_opts=dist-bzip2 am_opts=dist-xz
320
321 desc=gzip+bzip2+xz
322 tarname=parallel-compression-1.0
323
324 check_tarball ()
325 {
326   format=$1
327   setup_vars_for_compression_format $format
328   (
329     tarball=$tarname.$suffix \
330       && test -f $tarball \
331       && mkdir check-$format \
332       && cp $tarball check-$format \
333       && cd check-$format \
334       && $compressor -d $tarball \
335       && tar xvf $tarname.tar \
336       && diff ../Makefile.in $tarname/Makefile.in \
337       && cd .. \
338       && rm -rf check-$format
339    )
340 }
341
342 command_ok_ "$desc [automake]" $AUTOMAKE
343
344 if ! have_compressor xz && ! have_compressor bzip2; then
345   skip_reason="both 'bzip2' and 'xz' are unavailable"
346 elif ! have_compressor xz; then
347   skip_reason="'xz' not available"
348 elif ! have_compressor bzip2; then
349   skip_reason="'bzip2' not available"
350 else
351   skip_reason=
352 fi
353 if test "$MAKE_j4" = false; then
354   test -z "$skip_reason" || skip_reason="$skip_reason, and "
355   skip_reason="${skip_reason}make concurrency unavailable"
356 fi
357
358 if test -n "$skip_reason"; then
359   skip_row_ 6 -r "$skip_reason" "$desc"
360 else
361   command_ok_ "$desc [autoconf]" $AUTOCONF
362   command_ok_ "$desc [configure]" ./configure
363   command_ok_ "$desc [make -j4 dist-all]"  $MAKE_j4 dist
364   ls -l # For debugging.
365   command_ok_ "$desc [check .tar.gz tarball]"  check_tarball gzip
366   command_ok_ "$desc [check .tar.bz2 tarball]" check_tarball bzip2
367   command_ok_ "$desc [check .tar.xz tarball]"  check_tarball xz
368 fi
369
370 unset tarname desc skip_reason
371
372 end_subtest
373
374
375 # --------------------------------------------------------- #
376 #  The various 'dist-*' targets can happily work together.  #
377 # --------------------------------------------------------- #
378
379 start_subtest all-together
380
381 desc='all compressors together'
382 tarname=all-together-1.0
383
384 echo 'AM_INIT_AUTOMAKE([' > am-init.m4
385 echo 'AUTOMAKE_OPTIONS =' > Makefile.am
386
387 # Add half 'dist-*' options to AM_INIT_AUTOMAKE, half to AUTOMAKE_OPTIONS.
388 flip=:
389 for fmt in $all_compression_formats; do
390   test $fmt = gzip && continue
391   if $flip; then
392     echo "  dist-$fmt" >> am-init.m4
393     flip=false
394   else
395     echo "AUTOMAKE_OPTIONS += dist-$fmt" >> Makefile.am
396     flip=:
397   fi
398 done
399 unset flip fmt
400
401 echo '])' >> am-init.m4
402
403 sed 's/AM_INIT_AUTOMAKE.*/m4_include([am-init.m4])/' configure.ac > t
404 mv -f t configure.ac
405
406 # For debugging.
407 cat Makefile.am
408 cat configure.ac
409 cat am-init.m4
410
411 command_ok_ "$desc [aclocal]" $ACLOCAL --force
412 command_ok_ "$desc [automake]" $AUTOMAKE
413 command_ok_ "$desc [autoconf]" $AUTOCONF
414 command_ok_ "$desc [configure]" ./configure
415
416 if have_all_compressors; then
417   command_ok_ "$desc [make distcheck, real]" $MAKE distcheck
418 else
419   skip_ -r "not all compressors available" "$desc [make distcheck, real]"
420 fi
421
422 # We fake existence of all the compressors here, so that we don't have
423 # to require any of them to run the further tests.  This is especially
424 # important since it's very unlikely that a non-developer has all the
425 # compression tools installed on his machine at the same time.
426
427 mkdir bin
428 cd bin
429 cat > check-distdir <<END
430 #!/bin/sh
431 { ls -l '$tarname' && diff Makefile.am '$tarname'/Makefile.am; } >&2 \
432   || { echo "== distdir fail =="; exit 1; }
433 END
434 cat > grep-distdir-error <<'END'
435 #!/bin/sh
436 grep 'distdir fail' && exit 1
437 :
438 END
439 chmod a+x check-distdir grep-distdir-error
440 for prog in tar $all_compressors; do
441   case $prog in
442     tar|zip) cp check-distdir $prog;;
443           *) cp grep-distdir-error $prog;;
444   esac
445 done
446 unset prog
447 ls -l # For debugging.
448 cd ..
449
450 oPATH=$PATH
451 PATH=$(pwd)/bin$PATH_SEPARATOR$PATH; export PATH
452
453 command_ok_ \
454   "$desc ['make dist-all', stubbed]" \
455   $MAKE dist-all
456
457 subdesc="$desc ['make dist -j4', stubbed]"
458 if test "$MAKE_j4" = false; then
459   skip_ -r "make concurrency unavailable" "$subdesc"
460 else
461   command_ok_ "$subdesc" $MAKE_j4 dist
462 fi
463 unset subdesc
464
465 PATH=$oPATH; export PATH
466
467 end_subtest
468
469 :