Imported Upstream version 1.6
[debian/gzip] / tests / help-version
1 #! /bin/sh
2 # Make sure all these programs work properly
3 # when invoked with --help or --version.
4
5 # Copyright (C) 2000-2013 Free Software Foundation, Inc.
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 # Ensure that $SHELL is set to *some* value and exported.
21 # This is required for dircolors, which would fail e.g., when
22 # invoked via debuild (which removes SHELL from the environment).
23 test "x$SHELL" = x && SHELL=/bin/sh
24 export SHELL
25
26 . "${srcdir=.}/init.sh"; path_prepend_ ..
27
28 expected_failure_status_chroot=125
29 expected_failure_status_env=125
30 expected_failure_status_nice=125
31 expected_failure_status_nohup=125
32 expected_failure_status_stdbuf=125
33 expected_failure_status_su=125
34 expected_failure_status_timeout=125
35 expected_failure_status_printenv=2
36 expected_failure_status_tty=3
37 expected_failure_status_sort=2
38 expected_failure_status_expr=3
39 expected_failure_status_lbracket=2
40 expected_failure_status_dir=2
41 expected_failure_status_ls=2
42 expected_failure_status_vdir=2
43
44 expected_failure_status_cmp=2
45 expected_failure_status_zcmp=2
46 expected_failure_status_sdiff=2
47 expected_failure_status_diff3=2
48 expected_failure_status_diff=2
49 expected_failure_status_zdiff=2
50 expected_failure_status_zgrep=2
51 expected_failure_status_zegrep=2
52 expected_failure_status_zfgrep=2
53
54 expected_failure_status_grep=2
55 expected_failure_status_egrep=2
56 expected_failure_status_fgrep=2
57
58 gunzip_setuphelp () { args="--__bindir '$abs_top_builddir'"; }
59 gzexe_setuphelp () { gunzip_setuphelp; }
60 zcat_setuphelp () { gunzip_setuphelp; }
61 zcmp_setuphelp () { gunzip_setuphelp; }
62 zdiff_setuphelp () { gunzip_setuphelp; }
63 zegrep_setuphelp () { gunzip_setuphelp; }
64 zfgrep_setuphelp () { gunzip_setuphelp; }
65 zforce_setuphelp () { gunzip_setuphelp; }
66 zgrep_setuphelp () { gunzip_setuphelp; }
67 zless_setuphelp () { gunzip_setuphelp; }
68 zmore_setuphelp () { gunzip_setuphelp; }
69 znew_setuphelp () { gunzip_setuphelp; }
70
71 test "$built_programs" \
72   || fail_ "built_programs not specified!?!"
73
74 test "$VERSION" \
75   || fail_ "set envvar VERSION; it is required for a PATH sanity-check"
76
77 # Extract version from --version output of the first program
78 for i in $built_programs; do
79   v=$(env $i --version | sed -n '1s/.* //p;q')
80   break
81 done
82
83 # Ensure that it matches $VERSION.
84 test "x$v" = "x$VERSION" \
85   || fail_ "--version-\$VERSION mismatch"
86
87 for lang in C fr da; do
88   for i in $built_programs; do
89
90     # Skip `test'; it doesn't accept --help or --version.
91     test $i = test && continue;
92
93     # false fails even when invoked with --help or --version.
94     if test $i = false; then
95       env LC_MESSAGES=$lang $i --help >/dev/null && fail=1
96       env LC_MESSAGES=$lang $i --version >/dev/null && fail=1
97       continue
98     fi
99
100     if type ${i}_setuphelp > /dev/null 2>&1; then
101       ${i}_setuphelp
102     else
103       args=
104     fi
105
106     # The just-built install executable is always named `ginstall'.
107     test $i = install && i=ginstall
108
109     # Make sure they exit successfully, under normal conditions.
110     eval "env \$i $args --help    > h-\$i   " || fail=1
111     eval "env \$i $args --version >/dev/null" || fail=1
112
113     # Make sure they mention the bug-reporting address in --help output.
114     grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
115     rm -f h-$i
116
117     # Make sure they fail upon `disk full' error.
118     if test -w /dev/full && test -c /dev/full; then
119       eval "env \$i $args --help    >/dev/full 2>/dev/null" && fail=1
120       eval "env \$i $args --version >/dev/full 2>/dev/null" && fail=1
121       status=$?
122       test $i = [ && prog=lbracket || prog=$i
123       eval "expected=\$expected_failure_status_$prog"
124       test x$expected = x && expected=1
125       if test $status = $expected; then
126         : # ok
127       else
128         fail=1
129         echo "*** $i: bad exit status \`$status' (expected $expected)," 1>&2
130         echo "  with --help or --version output redirected to /dev/full" 1>&2
131       fi
132     fi
133   done
134 done
135
136 bigZ_in=bigZ-in.Z
137 zin=zin.gz
138 zin2=zin2.gz
139
140 tmp=tmp-$$
141 tmp_in=in-$$
142 tmp_in2=in2-$$
143 tmp_dir=dir-$$
144 tmp_out=out-$$
145 mkdir $tmp || fail=1
146 cd $tmp || fail=1
147
148 comm_setup () { args="$tmp_in $tmp_in"; }
149 csplit_setup () { args="$tmp_in //"; }
150 cut_setup () { args='-f 1'; }
151 join_setup () { args="$tmp_in $tmp_in"; }
152 tr_setup () { args='a a'; }
153
154 chmod_setup () { args="a+x $tmp_in"; }
155 # Punt on these.
156 chgrp_setup () { args=--version; }
157 chown_setup () { args=--version; }
158 mkfifo_setup () { args=--version; }
159 mknod_setup () { args=--version; }
160 # Punt on uptime, since it fails (e.g., failing to get boot time)
161 # on some systems, and we shouldn't let that stop `make check'.
162 uptime_setup () { args=--version; }
163
164 # Create a file in the current directory, not in $TMPDIR.
165 mktemp_setup () { args=mktemp.XXXX; }
166
167 cmp_setup () { args="$tmp_in $tmp_in2"; }
168
169 # Tell dd not to print the line with transfer rate and total.
170 # The transfer rate would vary between runs.
171 dd_setup () { args=status=noxfer; }
172
173 zdiff_setup () { gunzip_setuphelp; args="$args $zin $zin2"; }
174 zcmp_setup () { zdiff_setup; }
175 zcat_setup () { gunzip_setuphelp; args="$args $zin"; }
176 gunzip_setup () { zcat_setup; }
177 zmore_setup () { zcat_setup; }
178 zless_setup () { zcat_setup; }
179 znew_setup () { gunzip_setuphelp; args="$args $bigZ_in"; }
180 zforce_setup () { zcat_setup; }
181 zgrep_setup () { gunzip_setuphelp; args="$args z $zin"; }
182 zegrep_setup () { zgrep_setup; }
183 zfgrep_setup () { zgrep_setup; }
184 gzexe_setup () { gunzip_setuphelp; args="$args $tmp_in"; }
185
186 # We know that $tmp_in contains a "0"
187 grep_setup () { args="0 $tmp_in"; }
188 egrep_setup () { args="0 $tmp_in"; }
189 fgrep_setup () { args="0 $tmp_in"; }
190
191 diff_setup () { args="$tmp_in $tmp_in2"; }
192 sdiff_setup () { args="$tmp_in $tmp_in2"; }
193 diff3_setup () { args="$tmp_in $tmp_in2 $tmp_in2"; }
194 cp_setup () { args="$tmp_in $tmp_in2"; }
195 ln_setup () { args="$tmp_in ln-target"; }
196 ginstall_setup () { args="$tmp_in $tmp_in2"; }
197 mv_setup () { args="$tmp_in $tmp_in2"; }
198 mkdir_setup () { args=$tmp_dir/subdir; }
199 rmdir_setup () { args=$tmp_dir; }
200 rm_setup () { args=$tmp_in; }
201 shred_setup () { args=$tmp_in; }
202 touch_setup () { args=$tmp_in2; }
203 truncate_setup () { args="--reference=$tmp_in $tmp_in2"; }
204
205 basename_setup () { args=$tmp_in; }
206 dirname_setup () { args=$tmp_in; }
207 expr_setup () { args=foo; }
208
209 # Punt, in case GNU `id' hasn't been installed yet.
210 groups_setup () { args=--version; }
211
212 pathchk_setup () { args=$tmp_in; }
213 yes_setup () { args=--version; }
214 logname_setup () { args=--version; }
215 nohup_setup () { args=--version; }
216 printf_setup () { args=foo; }
217 seq_setup () { args=10; }
218 sleep_setup () { args=0; }
219 su_setup () { args=--version; }
220 stdbuf_setup () { args="-oL true"; }
221 timeout_setup () { args=--version; }
222
223 # I'd rather not run sync, since it spins up disks that I've
224 # deliberately caused to spin down (but not unmounted).
225 sync_setup () { args=--version; }
226
227 test_setup () { args=foo; }
228
229 # This is necessary in the unusual event that there is
230 # no valid entry in /etc/mtab.
231 df_setup () { args=/; }
232
233 # This is necessary in the unusual event that getpwuid (getuid ()) fails.
234 id_setup () { args=-u; }
235
236 # Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
237 kill_setup () {
238   env sleep 10m &
239   args=$!
240 }
241
242 link_setup () { args="$tmp_in link-target"; }
243 unlink_setup () { args=$tmp_in; }
244
245 readlink_setup () {
246   ln -s . slink
247   args=slink;
248 }
249
250 stat_setup () { args=$tmp_in; }
251 unlink_setup () { args=$tmp_in; }
252 lbracket_setup () { args=": ]"; }
253
254 # Ensure that each program "works" (exits successfully) when doing
255 # something more than --help or --version.
256 for i in $built_programs; do
257   # Skip these.
258   case $i in chroot|stty|tty|false|chcon|runcon) continue;; esac
259
260   rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out $bigZ_in $zin $zin2
261   echo z |gzip > $zin
262   cp $zin $zin2
263   cp $zin $bigZ_in
264
265   # This is sort of kludgey: use numbers so this is valid input for factor,
266   # and two tokens so it's valid input for tsort.
267   echo 2147483647 0 > $tmp_in
268   # Make $tmp_in2 identical. Then, using $tmp_in and $tmp_in2 as arguments
269   # to the likes of cmp and diff makes them exit successfully.
270   cp $tmp_in $tmp_in2
271   mkdir $tmp_dir
272   # echo ================== $i
273   test $i = [ && prog=lbracket || prog=$i
274   if type ${prog}_setup > /dev/null 2>&1; then
275     ${prog}_setup
276   else
277     args=
278   fi
279   if eval "env \$i $args < \$tmp_in > \$tmp_out"; then
280     : # ok
281   else
282     echo FAIL: $i
283     fail=1
284   fi
285   rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir
286 done
287
288 Exit $fail