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