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