source: trunk/src/sed/testsuite/help-version.sh@ 3613

Last change on this file since 3613 was 3613, checked in by bird, 10 months ago

src/sed: Merged in changes between 4.1.5 and 4.9 from the vendor branch. (svn merge /vendor/sed/4.1.5 /vendor/sed/current .)

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