tests: add the help-version sanity tests from coreutils
[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 test "$VERBOSE" = yes && set -x
21
22 # Ensure that $SHELL is set to *some* value and exported.
23 # This is required for dircolors, which would fail e.g., when
24 # invoked via debuild (which removes SHELL from the environment).
25 test "x$SHELL" = x && SHELL=/bin/sh
26 export SHELL
27
28 : ${srcdir=.}
29 . "$srcdir/tests/init.sh"
30
31 expected_failure_status_chroot=125
32 expected_failure_status_env=125
33 expected_failure_status_nice=125
34 expected_failure_status_nohup=125
35 expected_failure_status_stdbuf=125
36 expected_failure_status_su=125
37 expected_failure_status_timeout=125
38 expected_failure_status_printenv=2
39 expected_failure_status_tty=3
40 expected_failure_status_sort=2
41 expected_failure_status_expr=3
42 expected_failure_status_lbracket=2
43 expected_failure_status_dir=2
44 expected_failure_status_ls=2
45 expected_failure_status_vdir=2
46
47 expected_failure_status_cmp=2
48 expected_failure_status_zcmp=2
49 expected_failure_status_sdiff=2
50 expected_failure_status_diff3=2
51 expected_failure_status_diff=2
52 expected_failure_status_zdiff=2
53 expected_failure_status_zgrep=2
54 expected_failure_status_zegrep=2
55 expected_failure_status_zfgrep=2
56
57 test "$built_programs" \
58   || { echo "$this_test: no programs built!?!" 1>&2; Exit 1; }
59
60 for lang in C fr da; do
61   for i in $built_programs; do
62
63     # Skip `test'; it doesn't accept --help or --version.
64     test $i = test && continue;
65
66     # false fails even when invoked with --help or --version.
67     if test $i = false; then
68       env LC_MESSAGES=$lang $i --help >/dev/null && fail=1
69       env LC_MESSAGES=$lang $i --version >/dev/null && fail=1
70       continue
71     fi
72
73     # The just-built install executable is always named `ginstall'.
74     test $i = install && i=ginstall
75
76     # Make sure they exit successfully, under normal conditions.
77     env $i --help    > h-$i     || fail=1
78     env $i --version >/dev/null || fail=1
79
80     # Make sure they mention the bug-reporting address in --help output.
81     grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
82     rm -f h-$i
83
84     # Make sure they fail upon `disk full' error.
85     if test -w /dev/full && test -c /dev/full; then
86       env $i --help    >/dev/full 2>/dev/null && fail=1
87       env $i --version >/dev/full 2>/dev/null && fail=1
88       status=$?
89       test $i = [ && prog=lbracket || prog=$i
90       eval "expected=\$expected_failure_status_$prog"
91       test x$expected = x && expected=1
92       if test $status = $expected; then
93         : # ok
94       else
95         fail=1
96         echo "*** $i: bad exit status \`$status' (expected $expected)," 1>&2
97         echo "  with --help or --version output redirected to /dev/full" 1>&2
98       fi
99     fi
100   done
101 done
102
103 bigZ_in=bigZ-in.Z
104 zin=zin.gz
105 zin2=zin2.gz
106
107 tmp=tmp-$$
108 tmp_in=in-$$
109 tmp_in2=in2-$$
110 tmp_dir=dir-$$
111 tmp_out=out-$$
112 mkdir $tmp || fail=1
113 cd $tmp || fail=1
114
115 comm_args="$tmp_in $tmp_in"
116 csplit_args="$tmp_in //"
117 cut_args='-f 1'
118 join_args="$tmp_in $tmp_in"
119 tr_args='a a'
120
121 chmod_args="a+x $tmp_in"
122 # Punt on these.
123 chgrp_args=--version
124 chown_args=--version
125 mkfifo_args=--version
126 mknod_args=--version
127 # Punt on uptime, since it fails (e.g., failing to get boot time)
128 # on some systems, and we shouldn't let that stop `make check'.
129 uptime_args=--version
130
131 # Create a file in the current directory, not in $TMPDIR.
132 mktemp_args=mktemp.XXXX
133
134 cmp_args="$tmp_in $tmp_in2"
135
136 # Tell dd not to print the line with transfer rate and total.
137 # The transfer rate would vary between runs.
138 dd_args=status=noxfer
139
140 zdiff_args="$zin $zin2"
141 zcmp_args="$zin $zin2"
142 zcat_args=$zin
143 gunzip_args=$zin
144 zmore_args=$zin
145 zless_args=$zin
146 znew_args=$bigZ_in
147 zforce_args=$zin
148 zgrep_args="z $zin"
149 zegrep_args="z $zin"
150 zfgrep_args="z $zin"
151 gzexe_args=$tmp_in
152
153 diff_args="$tmp_in $tmp_in2"
154 sdiff_args="$tmp_in $tmp_in2"
155 diff3_args="$tmp_in $tmp_in2 $tmp_in2"
156 cp_args="$tmp_in $tmp_in2"
157 ln_args="$tmp_in ln-target"
158 ginstall_args="$tmp_in $tmp_in2"
159 mv_args="$tmp_in $tmp_in2"
160 mkdir_args=$tmp_dir/subdir
161 rmdir_args=$tmp_dir
162 rm_args=$tmp_in
163 shred_args=$tmp_in
164 touch_args=$tmp_in2
165 truncate_args="--reference=$tmp_in $tmp_in2"
166
167 basename_args=$tmp_in
168 dirname_args=$tmp_in
169 expr_args=foo
170
171 # Punt, in case GNU `id' hasn't been installed yet.
172 groups_args=--version
173
174 pathchk_args=$tmp_in
175 yes_args=--version
176 logname_args=--version
177 nohup_args=--version
178 printf_args=foo
179 seq_args=10
180 sleep_args=0
181 su_args=--version
182 stdbuf_args="-oL true"
183 timeout_args=--version
184
185 # I'd rather not run sync, since it spins up disks that I've
186 # deliberately caused to spin down (but not unmounted).
187 sync_args=--version
188
189 test_args=foo
190
191 # This is necessary in the unusual event that there is
192 # no valid entry in /etc/mtab.
193 df_args=/
194
195 # This is necessary in the unusual event that getpwuid (getuid ()) fails.
196 id_args=-u
197
198 # Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
199 env sleep 10m &
200 kill_args=$!
201
202 link_args="$tmp_in link-target"
203 unlink_args=$tmp_in
204
205 ln -s . slink
206 readlink_args=slink
207
208 stat_args=$tmp_in
209 unlink_args=$tmp_in
210 lbracket_args=": ]"
211
212 # Ensure that each program "works" (exits successfully) when doing
213 # something more than --help or --version.
214 for i in $built_programs; do
215   # Skip these.
216   case $i in chroot|stty|tty|false|chcon|runcon) continue;; esac
217
218   rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out $bigZ_in $zin $zin2
219   echo z |gzip > $zin
220   cp $zin $zin2
221   cp $zin $bigZ_in
222   echo > $tmp_in
223   echo > $tmp_in2
224   mkdir $tmp_dir
225   # echo ================== $i
226   test $i = [ && prog=lbracket || prog=$i
227   eval "args=\$${prog}_args"
228   if env $i $args < $tmp_in > $tmp_out; then
229     : # ok
230   else
231     echo FAIL: $i
232     fail=1
233   fi
234   rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir
235 done
236
237 Exit $fail