tests: pull help-version from grep
[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-2010 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=.}
27 . "$srcdir/init.sh"; path_prepend_ ..
28
29 expected_failure_status_chroot=125
30 expected_failure_status_env=125
31 expected_failure_status_nice=125
32 expected_failure_status_nohup=125
33 expected_failure_status_stdbuf=125
34 expected_failure_status_su=125
35 expected_failure_status_timeout=125
36 expected_failure_status_printenv=2
37 expected_failure_status_tty=3
38 expected_failure_status_sort=2
39 expected_failure_status_expr=3
40 expected_failure_status_lbracket=2
41 expected_failure_status_dir=2
42 expected_failure_status_ls=2
43 expected_failure_status_vdir=2
44
45 expected_failure_status_cmp=2
46 expected_failure_status_zcmp=2
47 expected_failure_status_sdiff=2
48 expected_failure_status_diff3=2
49 expected_failure_status_diff=2
50 expected_failure_status_zdiff=2
51 expected_failure_status_zgrep=2
52 expected_failure_status_zegrep=2
53 expected_failure_status_zfgrep=2
54
55 expected_failure_status_grep=2
56 expected_failure_status_egrep=2
57 expected_failure_status_fgrep=2
58
59 test "$built_programs" \
60   || { echo "$this_test: no programs built!?!" 1>&2; Exit 1; }
61
62 for lang in C fr da; do
63   for i in $built_programs; do
64
65     # Skip `test'; it doesn't accept --help or --version.
66     test $i = test && continue;
67
68     # false fails even when invoked with --help or --version.
69     if test $i = false; then
70       env LC_MESSAGES=$lang $i --help >/dev/null && fail=1
71       env LC_MESSAGES=$lang $i --version >/dev/null && fail=1
72       continue
73     fi
74
75     # The just-built install executable is always named `ginstall'.
76     test $i = install && i=ginstall
77
78     # Make sure they exit successfully, under normal conditions.
79     env $i --help    > h-$i     || fail=1
80     env $i --version >/dev/null || fail=1
81
82     # Make sure they mention the bug-reporting address in --help output.
83     grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
84     rm -f h-$i
85
86     # Make sure they fail upon `disk full' error.
87     if test -w /dev/full && test -c /dev/full; then
88       env $i --help    >/dev/full 2>/dev/null && fail=1
89       env $i --version >/dev/full 2>/dev/null && fail=1
90       status=$?
91       test $i = [ && prog=lbracket || prog=$i
92       eval "expected=\$expected_failure_status_$prog"
93       test x$expected = x && expected=1
94       if test $status = $expected; then
95         : # ok
96       else
97         fail=1
98         echo "*** $i: bad exit status \`$status' (expected $expected)," 1>&2
99         echo "  with --help or --version output redirected to /dev/full" 1>&2
100       fi
101     fi
102   done
103 done
104
105 bigZ_in=bigZ-in.Z
106 zin=zin.gz
107 zin2=zin2.gz
108
109 tmp=tmp-$$
110 tmp_in=in-$$
111 tmp_in2=in2-$$
112 tmp_dir=dir-$$
113 tmp_out=out-$$
114 mkdir $tmp || fail=1
115 cd $tmp || fail=1
116
117 comm_setup () { args="$tmp_in $tmp_in"; }
118 csplit_setup () { args="$tmp_in //"; }
119 cut_setup () { args='-f 1'; }
120 join_setup () { args="$tmp_in $tmp_in"; }
121 tr_setup () { args='a a'; }
122
123 chmod_setup () { args="a+x $tmp_in"; }
124 # Punt on these.
125 chgrp_setup () { args=--version; }
126 chown_setup () { args=--version; }
127 mkfifo_setup () { args=--version; }
128 mknod_setup () { args=--version; }
129 # Punt on uptime, since it fails (e.g., failing to get boot time)
130 # on some systems, and we shouldn't let that stop `make check'.
131 uptime_setup () { args=--version; }
132
133 # Create a file in the current directory, not in $TMPDIR.
134 mktemp_setup () { args=mktemp.XXXX; }
135
136 cmp_setup () { args="$tmp_in $tmp_in2"; }
137
138 # Tell dd not to print the line with transfer rate and total.
139 # The transfer rate would vary between runs.
140 dd_setup () { args=status=noxfer; }
141
142 zdiff_setup () { args="$zin $zin2"; }
143 zcmp_setup () { args="$zin $zin2"; }
144 zcat_setup () { args=$zin; }
145 gunzip_setup () { args=$zin; }
146 zmore_setup () { args=$zin; }
147 zless_setup () { args=$zin; }
148 znew_setup () { args=$bigZ_in; }
149 zforce_setup () { args=$zin; }
150 zgrep_setup () { args="z $zin"; }
151 zegrep_setup () { args="z $zin"; }
152 zfgrep_setup () { args="z $zin"; }
153 gzexe_setup () { args=$tmp_in; }
154
155 # We know that $tmp_in contains a "0"
156 grep_setup () { args="0 $tmp_in"; }
157 egrep_setup () { args="0 $tmp_in"; }
158 fgrep_setup () { args="0 $tmp_in"; }
159
160 diff_setup () { args="$tmp_in $tmp_in2"; }
161 sdiff_setup () { args="$tmp_in $tmp_in2"; }
162 diff3_setup () { args="$tmp_in $tmp_in2 $tmp_in2"; }
163 cp_setup () { args="$tmp_in $tmp_in2"; }
164 ln_setup () { args="$tmp_in ln-target"; }
165 ginstall_setup () { args="$tmp_in $tmp_in2"; }
166 mv_setup () { args="$tmp_in $tmp_in2"; }
167 mkdir_setup () { args=$tmp_dir/subdir; }
168 rmdir_setup () { args=$tmp_dir; }
169 rm_setup () { args=$tmp_in; }
170 shred_setup () { args=$tmp_in; }
171 touch_setup () { args=$tmp_in2; }
172 truncate_setup () { args="--reference=$tmp_in $tmp_in2"; }
173
174 basename_setup () { args=$tmp_in; }
175 dirname_setup () { args=$tmp_in; }
176 expr_setup () { args=foo; }
177
178 # Punt, in case GNU `id' hasn't been installed yet.
179 groups_setup () { args=--version; }
180
181 pathchk_setup () { args=$tmp_in; }
182 yes_setup () { args=--version; }
183 logname_setup () { args=--version; }
184 nohup_setup () { args=--version; }
185 printf_setup () { args=foo; }
186 seq_setup () { args=10; }
187 sleep_setup () { args=0; }
188 su_setup () { args=--version; }
189 stdbuf_setup () { args="-oL true"; }
190 timeout_setup () { args=--version; }
191
192 # I'd rather not run sync, since it spins up disks that I've
193 # deliberately caused to spin down (but not unmounted).
194 sync_setup () { args=--version; }
195
196 test_setup () { args=foo; }
197
198 # This is necessary in the unusual event that there is
199 # no valid entry in /etc/mtab.
200 df_setup () { args=/; }
201
202 # This is necessary in the unusual event that getpwuid (getuid ()) fails.
203 id_setup () { args=-u; }
204
205 # Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
206 kill_setup () {
207   env sleep 10m &
208   args=$!
209 }
210
211 link_setup () { args="$tmp_in link-target"; }
212 unlink_setup () { args=$tmp_in; }
213
214 readlink_setup () {
215   ln -s . slink
216   args=slink;
217 }
218
219 stat_setup () { args=$tmp_in; }
220 unlink_setup () { args=$tmp_in; }
221 lbracket_setup () { args=": ]"; }
222
223 # Ensure that each program "works" (exits successfully) when doing
224 # something more than --help or --version.
225 for i in $built_programs; do
226   # Skip these.
227   case $i in chroot|stty|tty|false|chcon|runcon) continue;; esac
228
229   rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out $bigZ_in $zin $zin2
230   echo z |gzip > $zin
231   cp $zin $zin2
232   cp $zin $bigZ_in
233
234   # This is sort of kludgey: use numbers so this is valid input for factor,
235   # and two tokens so it's valid input for tsort.
236   echo 2147483647 0 > $tmp_in
237   # Make $tmp_in2 identical. Then, using $tmp_in and $tmp_in2 as arguments
238   # to the likes of cmp and diff makes them exit successfully.
239   cp $tmp_in $tmp_in2
240   mkdir $tmp_dir
241   # echo ================== $i
242   test $i = [ && prog=lbracket || prog=$i
243   if type ${prog}_setup > /dev/null 2>&1; then
244     ${prog}_setup
245   else
246     args=
247   fi
248   if env $i $args < $tmp_in > $tmp_out; then
249     : # ok
250   else
251     echo FAIL: $i
252     fail=1
253   fi
254   rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir
255 done
256
257 Exit $fail