summaryrefslogtreecommitdiff
path: root/t/dist-formats.tap
blob: 17b9b11e0ceb6b61545c19473bbb9987ee407f6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#! /bin/sh
# Copyright (C) 2012-2014 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Check support for different compression formats used by distribution
# archives.

. test-init.sh

plan_ 18

# -------------------------------------- #
#  Auxiliary subroutines and variables.  #
# -------------------------------------- #

unset TAR

# Set variables '$compressor' and '$suffix'.
setup_vars_for_compression_format ()
{
  suffix=NONE
  case $1 in
    gzip) suffix=tar.gz  ;;
    lzip) suffix=tar.lz  ;;
      xz) suffix=tar.xz  ;;
   bzip2) suffix=tar.bz2 ;;
     zip) suffix=zip     ;;
       *) fatal_ "invalid compression format '$1'";;
  esac
  compressor=$1
}

check_tarball ()
{
  format=$1
  (
    setup_vars_for_compression_format $format \
      && tarball=$distdir.$suffix \
      && test -f $tarball \
      && mkdir check-$format \
      && cp $tarball check-$format \
      && cd check-$format \
      && $compressor -d $tarball \
      && tar xvf $distdir.tar \
      && diff ../Makefile.in $distdir/Makefile.in \
      && diff ../aclocal.m4  $distdir/aclocal.m4 \
      && diff ../configure   $distdir/configure \
      && cd .. \
      && rm -rf check-$format
   )
}


have_compressor ()
{
  test $# -eq 1 || fatal_ "have_compressor(): bad usage"
  if test $1 = gzip; then
    # Assume gzip(1) is available on every reasonable portability target.
    return 0
  fi
  needed_programs=$1
  # Assume by default the other compressors we care about support the
  # '--version' option.  We'll special-case the one which don't.
  checker_option=--version
  case $1 in
    bzip2)
      # Do not use --version, or older versions bzip2 would try to
      # compress stdin.  This would cause binary output in the test
      # logs, with potential breakage of our testsuite harness.
      checker_option=--help
      ;;
    zip)
      # OpenSolaris zip do not support the '--version' option, but
      # accepts the '-v' one with a similar meaning (if no further
      # arguments are given).
      checker_option=-v
      # Also, we need 'unzip' to decompress the created zipped archives
      # (bug#15181).
      needed_programs='zip unzip'
      ;;
  esac
  # Redirect to stderr to avoid polluting the output, in case this
  # function is used in a command substitution (as it is, later in
  # this script).
  for p in $needed_programs; do
    $p $checker_option </dev/null >&2 || return 1
  done
  return 0
}

all_compression_formats='gzip lzip xz bzip2 zip'

all_compressors=$(
  for x in $all_compression_formats; do
    setup_vars_for_compression_format $x
    echo $compressor
  done | tr "$nl" ' ')
echo All compressors: $all_compressors

missing_compressors=$(
  for c in $all_compressors; do
    have_compressor $c || echo $c
  done | tr "$nl" ' ')
echo Missing compressors: $missing_compressors

# Redefine to avoid re-running the already executed checks.
have_compressor ()
{
  case " $missing_compressors " in *\ $1\ *) false;; *) : ;; esac
}

have_all_compressors ()
{
  test -z "$missing_compressors"
}

clean_dist ()
{
  rm -rf *$distdir*
}

# ------------------------- #
#  Setup and basic checks.  #
# ------------------------- #

echo AC_OUTPUT >> configure.ac
: > Makefile.am

$ACLOCAL && $AUTOCONF && $AUTOMAKE -a || fatal_ "autotools failed"
./configure || fatal_ "./configure failed"

command_ok_ "make distcheck"  $MAKE distcheck

command_ok_ "only gzip archive is built by default" \
            test "$(ls *$distdir*)" = $distdir.tar.gz


# ------------------------------------- #
#  Test all known formats, separately.  #
# ------------------------------------- #

for format in $all_compression_formats; do
  setup_vars_for_compression_format "$format"
  desc="$format distribution format"
  command_ok_ "$desc [seems accepted]" \
              $MAKE -n dist AM_DIST_FORMATS="$format"
  if have_compressor "$compressor"; then
    command_ok_ "$desc $format distribution format [works]" \
      eval '$MAKE dist AM_DIST_FORMATS="$format" \
              && ls -l *$distdir* \
              && test -f $distdir.$suffix \
              && test "$(echo *$distdir*)" = $distdir.$suffix'
  else
    skip_ -r "'$compressor' not available" "$1"
  fi
  clean_dist
  unset desc suffix compressor format
done


# ----------------------- #
#  Parallel compression.  #
# ----------------------- #

# We only use formats requiring 'gzip', 'bzip2' and 'xz' programs,
# since there are the most likely to be all found on the great
# majority of systems.

desc='parallel compression'

if ! have_compressor xz && ! have_compressor bzip2; then
  skip_reason="both 'bzip2' and 'xz' are unavailable"
elif ! have_compressor xz; then
  skip_reason="'xz' not available"
elif ! have_compressor bzip2; then
  skip_reason="'bzip2' not available"
else
  skip_reason=
fi

if test -n "$skip_reason"; then
  skip_row_ 6 -r "$skip_reason" "$desc"
else
  command_ok_ "$desc [make -j8 distcheck]"  \
              $MAKE -j8 distcheck AM_DIST_FORMATS='gzip bzip2 xz'
  ls -l # For debugging.
  command_ok_ "$desc [check .tar.gz tarball]"  check_tarball gzip
  command_ok_ "$desc [check .tar.bz2 tarball]" check_tarball bzip2
  command_ok_ "$desc [check .tar.xz tarball]"  check_tarball xz
fi

clean_dist
unset desc skip_reason


# ------------------------------- #
#  Invalid distribution formats.  #
# ------------------------------- #

command_ok_ "invalid distribution formats [exit status]" \
            run_make -E -e FAIL dist AM_DIST_FORMATS="foobar tarZ shar"

command_ok_ "invalid distribution formats [error report]"  eval '
  sed -e "s/^/ /" -e "s/$/ /" stderr >stderr2 \
    && grep "[iI]nvalid distribution format.* foobar " stderr2 \
    && grep "[iI]nvalid distribution format.* tarZ "   stderr2 \
    && grep "[iI]nvalid distribution format.* shar "   stderr2'

: