Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / 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, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
6 # Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 test "$VERBOSE" = yes && set -x
24
25 # Ensure that $SHELL is set to *some* value.
26 # This is required for dircolors, which would fail e.g., when
27 # invoked via debuild (which removes SHELL from the environment).
28 if test "x$SHELL" = x; then
29   SHELL=/bin/sh
30   export SHELL
31 fi
32
33 expected_failure_status_nohup=127
34 expected_failure_status_printenv=2
35 expected_failure_status_tty=3
36 expected_failure_status_sort=2
37 expected_failure_status_expr=3
38 expected_failure_status_lbracket=2
39 expected_failure_status_dir=2
40 expected_failure_status_ls=2
41 expected_failure_status_vdir=2
42
43 case "$all_programs" in
44   *groups*)
45     if test -w /dev/full && test -c /dev/full \
46         && echo > /dev/full 2>/dev/null; then
47       cat 1>&2 <<\EOF
48 ************************************************
49 WARNING: On this system, the built-in echo function of /bin/sh
50 does not report failure when writing to a full device.
51 To demonstrate, run this command:
52
53   /bin/sh -c 'echo hello > /dev/full; echo status=$?'
54
55 Notice that the failing echo leaves its exit status set to zero
56 and does not produce a diagnostic.
57
58 That bug in /bin/sh would cause the test of the groups
59 scripts to fail, so it is being removed from the list of
60 programs checked by this test.
61 ************************************************
62 EOF
63       all_programs=`echo $all_programs | tr ' ' '\n' | grep -v '^groups$'`
64     fi
65   ;;
66 esac
67
68 fail=0
69
70 for lang in C fr da; do
71   for i in $all_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     if test $i = false; then
78       env LC_MESSAGES=$lang ../src/$i --help    >/dev/null && fail=1
79       env LC_MESSAGES=$lang ../src/$i --version >/dev/null && fail=1
80       continue
81     fi
82
83     # The just-built install executable is always named `ginstall'.
84     test $i = install && i=ginstall
85
86     # Make sure they exit successfully, under normal conditions.
87     ../src/$i --help    > h-$i     || fail=1
88     ../src/$i --version >/dev/null || fail=1
89
90     # Make sure they mention the bug-reporting address in --help output.
91     grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
92     rm -f h-$i
93
94     # Make sure they fail upon `disk full' error.
95     if test -w /dev/full && test -c /dev/full; then
96       ../src/$i --help    >/dev/full 2>/dev/null && fail=1
97       ../src/$i --version >/dev/full 2>/dev/null && fail=1
98       status=$?
99       test $i = [ && prog=lbracket || prog=$i
100       eval "expected=\$expected_failure_status_$prog"
101       test x$expected = x && expected=1
102       if test $status = $expected; then
103         : # ok
104       else
105         fail=1
106         echo "*** $i: bad exit status \`$status' (expected $expected)," 1>&2
107         echo "  with --help or --version output redirected to /dev/full" 1>&2
108       fi
109     fi
110   done
111 done
112
113 tmp=tmp-$$
114 tmp_in=in-$$
115 tmp_in2=in2-$$
116 tmp_dir=dir-$$
117 tmp_out=out-$$
118 mkdir $tmp || fail=1
119 cd $tmp || fail=1
120
121 comm_args="$tmp_in $tmp_in"
122 csplit_args="$tmp_in //"
123 cut_args='-f 1'
124 join_args="$tmp_in $tmp_in"
125 tr_args='a a'
126
127 chmod_args="a+x $tmp_in"
128 # Punt on these.
129 chgrp_args=--version
130 chown_args=--version
131 mkfifo_args=--version
132 mknod_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'.
135 uptime_args=--version
136
137 cmp_args="$tmp_in $tmp_in2"
138 diff_args="$tmp_in $tmp_in2"
139 sdiff_args="$tmp_in $tmp_in2"
140 diff3_args="$tmp_in $tmp_in2 $tmp_in2"
141 cp_args="$tmp_in $tmp_in2"
142 ln_args="$tmp_in ln-target"
143 ginstall_args="$tmp_in $tmp_in2"
144 mv_args="$tmp_in $tmp_in2"
145 mkdir_args=$tmp_dir/subdir
146 rmdir_args=$tmp_dir
147 rm_args=$tmp_in
148 shred_args=$tmp_in
149 touch_args=$tmp_in2
150
151 basename_args=$tmp_in
152 dirname_args=$tmp_in
153 expr_args=foo
154
155 # Punt, in case GNU `id' hasn't been installed yet.
156 groups_args=--version
157
158 pathchk_args=$tmp_in
159 yes_args=--version
160 logname_args=--version
161 nohup_args=--version
162 printf_args=foo
163 seq_args=10
164 sleep_args=0
165 su_args=--version
166 test_args=foo
167
168 # This is necessary in the unusual event that there is
169 # no valid entry in /etc/mtab.
170 df_args=/
171
172 # This is necessary in the unusual event that getpwuid (getuid ()) fails.
173 id_args=-u
174
175 sleep 10m &
176 kill_args=$!
177
178 link_args="$tmp_in link-target"
179 unlink_args=$tmp_in
180
181 ln -s . slink
182 readlink_args=slink
183
184 stat_args=$tmp_in
185 unlink_args=$tmp_in
186 lbracket_args=": ]"
187
188 for i in $all_programs; do
189   # Skip these.
190   case $i in chroot|stty|tty|false) continue;; esac
191
192   rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out
193   echo > $tmp_in
194   echo > $tmp_in2
195   mkdir $tmp_dir
196   # echo ================== $i
197   test $i = [ && prog=lbracket || prog=$i
198   eval "args=\$${prog}_args"
199   if ../../src/$i $args < $tmp_in > $tmp_out; then
200     : # ok
201   else
202     echo FAIL: $i
203     fail=1
204   fi
205   rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir
206 done
207
208 # FIXME: trap
209 cd ..
210 rm -rf $tmp
211
212 exit $fail