source: vendor/grep/2.12/tests/help-version

Last change on this file was 2595, checked in by bird, 13 years ago

gnu grep version 2.12 (grep-2.12.tar.xz, md5sum=8d2f0346d08b13c18afb81f0e8aa1e2f)

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