VirtualBox

source: kBuild/vendor/grep/3.7/tests/help-version

Last change on this file was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:executable set to *
File size: 8.2 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-2021 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. "${srcdir=.}/init.sh"; path_prepend_ ../src
21
22# Terminate any background processes
23cleanup_() { kill $pid 2>/dev/null && wait $pid; }
24
25expected_failure_status_chroot=125
26expected_failure_status_env=125
27expected_failure_status_nice=125
28expected_failure_status_nohup=125
29expected_failure_status_stdbuf=125
30expected_failure_status_timeout=125
31expected_failure_status_printenv=2
32expected_failure_status_tty=3
33expected_failure_status_sort=2
34expected_failure_status_expr=3
35expected_failure_status_lbracket=2
36expected_failure_status_dir=2
37expected_failure_status_ls=2
38expected_failure_status_vdir=2
39
40expected_failure_status_cmp=2
41expected_failure_status_zcmp=2
42expected_failure_status_sdiff=2
43expected_failure_status_diff3=2
44expected_failure_status_diff=2
45expected_failure_status_zdiff=2
46expected_failure_status_zgrep=2
47expected_failure_status_zegrep=2
48expected_failure_status_zfgrep=2
49
50expected_failure_status_grep=2
51expected_failure_status_egrep=2
52expected_failure_status_fgrep=2
53
54test "$built_programs" \
55 || fail_ "built_programs not specified!?!"
56
57test "$VERSION" \
58 || fail_ "set envvar VERSION; it is required for a PATH sanity-check"
59
60# Extract version from --version output of the first program
61for i in $built_programs; do
62 v=$(env $i --version | sed -n '1s/.* //p;q')
63 break
64done
65
66# Ensure that it matches $VERSION.
67test "x$v" = "x$VERSION" \
68 || fail_ "--version-\$VERSION mismatch"
69
70for lang in C fr da; do
71 for i in $built_programs; do
72
73 # Skip 'test'; it doesn't accept --help or --version.
74 test $i = test && continue
75
76 # false fails even when invoked with --help or --version.
77 # true and false are tested with these options separately.
78 test $i = false || test $i = true && continue
79
80 # The just-built install executable is always named 'ginstall'.
81 test $i = install && i=ginstall
82
83 # Make sure they exit successfully, under normal conditions.
84 env $i --help > h-$i || fail=1
85 env $i --version >/dev/null || fail=1
86
87 # Make sure they mention the bug-reporting address in --help output.
88 grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
89 rm -f h-$i
90
91 # Make sure they fail upon 'disk full' error.
92 if test -w /dev/full && test -c /dev/full; then
93 test $i = [ && prog=lbracket || prog=$(echo $i|sed "s/$EXEEXT$//")
94 eval "expected=\$expected_failure_status_$prog"
95 test x$expected = x && expected=1
96
97 returns_ $expected env $i --help >/dev/full 2>/dev/null &&
98 returns_ $expected env $i --version >/dev/full 2>/dev/null ||
99 {
100 fail=1
101 env $i --help >/dev/full 2>/dev/null
102 status=$?
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 }
106 fi
107 done
108done
109
110bigZ_in=bigZ-in.Z
111zin=zin.gz
112zin2=zin2.gz
113
114tmp=tmp-$$
115tmp_in=in-$$
116tmp_in2=in2-$$
117tmp_dir=dir-$$
118tmp_out=out-$$
119mkdir $tmp || fail=1
120cd $tmp || fail=1
121
122comm_setup () { args="$tmp_in $tmp_in"; }
123csplit_setup () { args="$tmp_in //"; }
124cut_setup () { args='-f 1'; }
125join_setup () { args="$tmp_in $tmp_in"; }
126tr_setup () { args='a a'; }
127
128chmod_setup () { args="a+x $tmp_in"; }
129# Punt on these.
130chgrp_setup () { args=--version; }
131chown_setup () { args=--version; }
132mkfifo_setup () { args=--version; }
133mknod_setup () { args=--version; }
134# Punt on uptime, since it fails (e.g., failing to get boot time)
135# on some systems, and we shouldn't let that stop 'make check'.
136uptime_setup () { args=--version; }
137
138# Create a file in the current directory, not in $TMPDIR.
139mktemp_setup () { args=mktemp.XXXX; }
140
141cmp_setup () { args="$tmp_in $tmp_in2"; }
142
143# Tell dd not to print the line with transfer rate and total.
144# The transfer rate would vary between runs.
145dd_setup () { args=status=noxfer; }
146
147zdiff_setup () { args="$zin $zin2"; }
148zcmp_setup () { args="$zin $zin2"; }
149zcat_setup () { args=$zin; }
150gunzip_setup () { args=$zin; }
151zmore_setup () { args=$zin; }
152zless_setup () { args=$zin; }
153znew_setup () { args=$bigZ_in; }
154zforce_setup () { args=$zin; }
155zgrep_setup () { args="z $zin"; }
156zegrep_setup () { args="z $zin"; }
157zfgrep_setup () { args="z $zin"; }
158gzexe_setup () { args=$tmp_in; }
159
160# We know that $tmp_in contains a "0"
161grep_setup () { args="0 $tmp_in"; }
162egrep_setup () { args="0 $tmp_in"; }
163fgrep_setup () { args="0 $tmp_in"; }
164
165diff_setup () { args="$tmp_in $tmp_in2"; }
166sdiff_setup () { args="$tmp_in $tmp_in2"; }
167diff3_setup () { args="$tmp_in $tmp_in2 $tmp_in2"; }
168cp_setup () { args="$tmp_in $tmp_in2"; }
169ln_setup () { args="$tmp_in ln-target"; }
170ginstall_setup () { args="$tmp_in $tmp_in2"; }
171mv_setup () { args="$tmp_in $tmp_in2"; }
172mkdir_setup () { args=$tmp_dir/subdir; }
173realpath_setup () { args=$tmp_in; }
174rmdir_setup () { args=$tmp_dir; }
175rm_setup () { args=$tmp_in; }
176shred_setup () { args=$tmp_in; }
177touch_setup () { args=$tmp_in2; }
178truncate_setup () { args="--reference=$tmp_in $tmp_in2"; }
179
180mkid_setup () { printf 'f(){}\ntypedef int t;\n' > f.c; args=. ; }
181lid_setup () { args=; }
182fid_setup () { args=f.c; }
183fnid_setup () { args=; }
184xtokid_setup () { args=; }
185aid_setup () { args=f; }
186eid_setup () { args=--version; }
187gid_setup () { args=f; }
188defid_setup () { args=t; }
189
190basename_setup () { args=$tmp_in; }
191dirname_setup () { args=$tmp_in; }
192expr_setup () { args=foo; }
193
194# Punt, in case GNU 'id' hasn't been installed yet.
195groups_setup () { args=--version; }
196
197pathchk_setup () { args=$tmp_in; }
198yes_setup () { args=--version; }
199logname_setup () { args=--version; }
200nohup_setup () { args=--version; }
201printf_setup () { args=foo; }
202seq_setup () { args=10; }
203sleep_setup () { args=0; }
204stdbuf_setup () { args="-oL true"; }
205timeout_setup () { args=--version; }
206
207# I'd rather not run sync, since it spins up disks that I've
208# deliberately caused to spin down (but not unmounted).
209sync_setup () { args=--version; }
210
211test_setup () { args=foo; }
212
213# This is necessary in the unusual event that there is
214# no valid entry in /etc/mtab.
215df_setup () { args=/; }
216
217# This is necessary in the unusual event that getpwuid (getuid ()) fails.
218id_setup () { args=-u; }
219
220# Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
221kill_setup () {
222 external=env
223 $external sleep 10m & pid=$!
224 args=$pid
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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette