~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/misc/nohup

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# test nohup
3
 
 
4
 
# Copyright (C) 2003, 2006-2011 Free Software Foundation, Inc.
5
 
 
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.
10
 
 
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.
15
 
 
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
. "${srcdir=.}/init.sh"; path_prepend_ ../src
20
 
print_ver_ nohup
21
 
 
22
 
 
23
 
nohup sh -c 'echo stdout; echo stderr 1>&2' 2>err || fail=1
24
 
 
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 || fail=1
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 || fail=1
42
 
fi
43
 
echo 'stderr' >> exp || fail=1
44
 
 
45
 
compare exp err || fail=1
46
 
rm -f nohup.out err exp
47
 
# ----------------------
48
 
 
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
56
 
fi
57
 
# It must *not* exist.
58
 
test -f nohup.out && fail=1
59
 
rm -f nohup.out err
60
 
# ----------------------
61
 
 
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
65
 
(
66
 
  exec >/dev/tty
67
 
  test -t 1 || exit 0
68
 
  nohup echo hi 2> /dev/full
69
 
  test $? = 125 || fail=1
70
 
  test -f nohup.out || fail=1
71
 
  test -s nohup.out && fail=1
72
 
  rm -f nohup.out
73
 
  exit $fail
74
 
) || fail=1
75
 
fi
76
 
 
77
 
nohup no-such-command 2> err
78
 
errno=$?
79
 
if test -t 1; then
80
 
  test $errno = 127 || fail=1
81
 
  # It must exist.
82
 
  test -f nohup.out || fail=1
83
 
  # It must be empty.
84
 
  test -s nohup.out && fail=1
85
 
fi
86
 
 
87
 
cat <<\EOF > exp || fail=1
88
 
nohup: appending output to `nohup.out'
89
 
nohup: cannot run command `no-such-command': No such file or directory
90
 
EOF
91
 
# Disable these comparisons.  Too much variation in 2nd line.
92
 
# compare exp err || fail=1
93
 
rm -f nohup.out err exp
94
 
# ----------------------
95
 
 
96
 
touch k; chmod 0 k
97
 
nohup ./k 2> err
98
 
errno=$?
99
 
test $errno = 126 || fail=1
100
 
if test -t 1; then
101
 
  # It must exist.
102
 
  test -f nohup.out || fail=1
103
 
  # It must be empty.
104
 
  test -s nohup.out && fail=1
105
 
fi
106
 
 
107
 
cat <<\EOF > exp || fail=1
108
 
nohup: appending output to `nohup.out'
109
 
nohup: cannot run command `./k': Permission denied
110
 
EOF
111
 
# Disable these comparisons.  Too much variation in 2nd line.
112
 
# compare exp err || fail=1
113
 
 
114
 
# Make sure it fails with exit status of 125 when given too few arguments,
115
 
# except that POSIX requires 127 in this case.
116
 
nohup >/dev/null 2>&1
117
 
test $? = 125 || fail=1
118
 
POSIXLY_CORRECT=1 nohup >/dev/null 2>&1
119
 
test $? = 127 || fail=1
120
 
 
121
 
Exit $fail