tests: add test for locale decimal processing
[coreutils.git] / tests / misc / nohup.sh
blobe270c1356cc9eb774ccb91dee89d34b4aaa1f441
1 #!/bin/sh
2 # test nohup
4 # Copyright (C) 2003-2019 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ nohup
23 nohup sh -c 'echo stdout; echo stderr 1>&2' 2>err || fail=1
25 # Be careful. The results of the above nohup command
26 # change depending on whether stdin and stdout are redirected.
27 if test -t 1; then
28 test "$(cat nohup.out)" = stdout || fail=1
29 if test -t 0; then
30 echo 'nohup: ignoring input and appending output to 'nohup.out'\'
31 else
32 echo 'nohup: appending output to 'nohup.out'\'
33 fi >exp || framework_failure_
34 else
35 # Here it should not even exist.
36 test -f nohup.out && fail=1
37 if test -t 0; then
38 echo 'nohup: ignoring input' >exp
39 else
40 rm -f exp
41 fi || framework_failure_
43 echo 'stderr' >> exp || framework_failure_
45 compare exp err || fail=1
46 rm -f nohup.out err exp
47 # ----------------------
49 # Be careful. The results of the following nohup command
50 # change depending on whether stderr is redirected.
51 nohup sh -c 'echo stdout; echo stderr 1>&2' >out || fail=1
52 if test -t 2; then
53 test "$(cat out|tr '\n' -)" = stdout-stderr- || fail=1
54 else
55 test "$(cat out|tr '\n' -)" = stdout- || fail=1
57 # It must *not* exist.
58 test -f nohup.out && fail=1
59 rm -f nohup.out err
60 # ----------------------
62 # Bug present through coreutils 8.0: failure to print advisory message
63 # to stderr must be fatal. Requires stdout to be terminal.
64 if test -w /dev/full && test -c /dev/full; then
66 # POSIX shells immediately exit the subshell on exec error.
67 # So check we can write to /dev/tty before the exec, which
68 # isn't possible if we've no controlling tty for example.
69 test -c /dev/tty && >/dev/tty || exit 0
71 exec >/dev/tty
72 test -t 1 || exit 0
73 returns_ 125 nohup echo hi 2> /dev/full || fail=1
74 test -f nohup.out || fail=1
75 compare /dev/null nohup.out || fail=1
76 rm -f nohup.out
77 exit $fail
78 ) || fail=1
81 nohup no-such-command 2> err
82 errno=$?
83 if test -t 1; then
84 test $errno = 127 || fail=1
85 # It must exist.
86 test -f nohup.out || fail=1
87 # It must be empty.
88 compare /dev/null nohup.out || fail=1
91 cat <<\EOF > exp || framework_failure_
92 nohup: appending output to 'nohup.out'
93 nohup: cannot run command 'no-such-command': No such file or directory
94 EOF
95 # Disable these comparisons. Too much variation in 2nd line.
96 # compare exp err || fail=1
97 rm -f nohup.out err exp
98 # ----------------------
100 touch k; chmod 0 k
101 nohup ./k 2> err
102 errno=$?
103 test $errno = 126 || fail=1
104 if test -t 1; then
105 # It must exist.
106 test -f nohup.out || fail=1
107 # It must be empty.
108 compare /dev/null nohup.out || fail=1
111 cat <<\EOF > exp || framework_failure_
112 nohup: appending output to 'nohup.out'
113 nohup: cannot run command './k': Permission denied
115 # Disable these comparisons. Too much variation in 2nd line.
116 # compare exp err || fail=1
118 # Make sure it fails with exit status of 125 when given too few arguments,
119 # except that POSIX requires 127 in this case.
120 returns_ 125 nohup >/dev/null 2>&1 || fail=1
121 export POSIXLY_CORRECT=1
122 returns_ 127 nohup >/dev/null 2>&1 || fail=1
123 unset POSIXLY_CORRECT
125 Exit $fail