Use newer trap and tmpdir-creation framework.
[coreutils.git] / tests / help-version
blob409d2e86c0a43ac23160b9af169bcaa77d0bf501
1 #! /bin/sh
2 # Make sure all these programs work properly
3 # when invoked with --help or --version.
5 test "$VERBOSE" = yes && set -x
7 expected_failure_status_nohup=127
8 expected_failure_status_printenv=2
9 expected_failure_status_tty=3
10 expected_failure_status_sort=2
11 expected_failure_status_expr=3
12 expected_failure_status_lbracket=2
13 expected_failure_status_dir=2
14 expected_failure_status_ls=2
15 expected_failure_status_vdir=2
17 case "$all_programs" in
18 *groups*)
19 if test -w /dev/full && test -c /dev/full && echo > /dev/full; then
20 cat 1>&2 <<\EOF
21 ************************************************
22 WARNING: On this system, the built-in echo function of /bin/sh
23 does not report failure when writing to a full device.
24 To demonstrate, run this command:
26 /bin/sh -c 'echo hello > /dev/full; echo status=$?'
28 Notice that the failing echo leaves its exit status set to zero
29 and does not produce a diagnostic.
31 That bug in /bin/sh would cause the test of the groups
32 scripts to fail, so it is being removed from the list of
33 programs checked by this test.
34 ************************************************
35 EOF
36 all_programs=`echo $all_programs|sed 's/\<groups\> *//'`
39 esac
41 fail=0
43 for lang in C fr da; do
44 for i in $all_programs; do
46 # Skip `test'; it doesn't accept --help or --version.
47 test $i = test && continue;
49 # false fails even when invoked with --help or --version.
50 if test $i = false; then
51 env LC_MESSAGES=$lang ../src/$i --help >/dev/null && fail=1
52 env LC_MESSAGES=$lang ../src/$i --version >/dev/null && fail=1
53 continue
56 # The just-built install executable is always named `ginstall'.
57 test $i = install && i=ginstall
59 # Make sure they exit successfully, under normal conditions.
60 ../src/$i --help > h-$i || fail=1
61 ../src/$i --version >/dev/null || fail=1
63 # Make sure they mention the bug-reporting address in --help output.
64 grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
65 rm -f h-$i
67 # Make sure they fail upon `disk full' error.
68 if test -w /dev/full && test -c /dev/full; then
69 ../src/$i --help >/dev/full 2>/dev/null && fail=1
70 ../src/$i --version >/dev/full 2>/dev/null && fail=1
71 status=$?
72 test $i = [ && prog=lbracket || prog=$i
73 eval "expected=\$expected_failure_status_$prog"
74 test x$expected = x && expected=1
75 if test $status = $expected; then
76 : # ok
77 else
78 fail=1
79 echo "*** $i: bad exit status \`$status' (expected $expected)," 1>&2
80 echo " with --help or --version output redirected to /dev/full" 1>&2
83 done
84 done
86 tmp=tmp-$$
87 tmp_in=in-$$
88 tmp_in2=in2-$$
89 tmp_dir=dir-$$
90 tmp_out=out-$$
91 mkdir $tmp || fail=1
92 cd $tmp || fail=1
94 comm_args="$tmp_in $tmp_in"
95 csplit_args="$tmp_in //"
96 cut_args='-f 1'
97 join_args="$tmp_in $tmp_in"
98 tr_args='a a'
100 chmod_args="a+x $tmp_in"
101 # Punt on these.
102 chgrp_args=--version
103 chown_args=--version
104 mkfifo_args=--version
105 mknod_args=--version
106 # Punt on uptime, since it fails (e.g., failing to get boot time)
107 # on some systems, and we shouldn't let that stop `make check'.
108 uptime_args=--version
110 cmp_args="$tmp_in $tmp_in2"
111 diff_args="$tmp_in $tmp_in2"
112 sdiff_args="$tmp_in $tmp_in2"
113 diff3_args="$tmp_in $tmp_in2 $tmp_in2"
114 cp_args="$tmp_in $tmp_in2"
115 ln_args="$tmp_in ln-target"
116 ginstall_args="$tmp_in $tmp_in2"
117 mv_args="$tmp_in $tmp_in2"
118 mkdir_args=$tmp_dir/subdir
119 rmdir_args=$tmp_dir
120 rm_args=$tmp_in
121 shred_args=$tmp_in
122 touch_args=$tmp_in2
124 basename_args=$tmp_in
125 dirname_args=$tmp_in
126 expr_args=foo
128 # Punt, in case GNU `id' hasn't been installed yet.
129 groups_args=--version
131 pathchk_args=$tmp_in
132 yes_args=--version
133 logname_args=--version
134 nohup_args=--version
135 printf_args=foo
136 seq_args=10
137 sleep_args=0
138 su_args=--version
139 test_args=foo
141 # This is necessary in the unusual event that there is
142 # no valid entry in /etc/mtab.
143 df_args=/
145 # This is necessary in the unusual event that getpwuid (getuid ()) fails.
146 id_args=-u
148 sleep 10m &
149 kill_args=$!
151 link_args="$tmp_in link-target"
152 unlink_args=$tmp_in
154 ln -s . slink
155 readlink_args=slink
157 stat_args=$tmp_in
158 unlink_args=$tmp_in
159 lbracket_args=": ]"
161 for i in $all_programs; do
162 # Skip these.
163 case $i in chroot|stty|tty|false) continue;; esac
165 rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out
166 echo > $tmp_in
167 echo > $tmp_in2
168 mkdir $tmp_dir
169 # echo ================== $i
170 test $i = [ && prog=lbracket || prog=$i
171 eval "args=\$${prog}_args"
172 if ../../src/$i $args < $tmp_in > $tmp_out; then
173 : # ok
174 else
175 echo FAIL: $i
176 fail=1
178 rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir
179 done
181 # FIXME: trap
182 cd ..
183 rm -rf $tmp
185 exit $fail