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