tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / rm / rm3
1 #!/bin/sh
2 # exercise another small part of remove.c
3
4 # Copyright (C) 2002-2004, 2006-2009 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 if test "$VERBOSE" = yes; then
20   set -x
21   rm --version
22 fi
23
24 . $srcdir/test-lib.sh
25 skip_if_root_
26
27 mkdir -p z || framework_failure
28 cd z || framework_failure
29 touch empty empty-u || framework_failure
30 echo not-empty > fu
31 ln -s empty-f slink
32 ln -s . slinkdot
33 mkdir d du || framework_failure
34 chmod u-w fu du empty-u || framework_failure
35 cd ..
36
37
38 cat <<EOF > in
39 y
40 y
41 y
42 y
43 y
44 y
45 y
46 y
47 y
48 EOF
49
50 # Both of these should fail.
51 rm -ir z < in > out 2>&1 || fail=1
52
53 # Given input like `rm: ...? rm: ...? ' (no trailing newline),
54 # the `head...' part of the pipeline below removes the trailing space, so
55 # that sed doesn't have to deal with a line lacking a terminating newline.
56 # This avoids a bug whereby some vendor-provided (Tru64) versions of sed
57 # would mistakenly tack a newline onto the end of the output.
58 tr '?' '\n' < out | head --bytes=-1 | sed 's/^ //' |sort > o2
59 mv o2 out
60
61 sort <<EOF > exp || fail=1
62 rm: descend into directory \`z'
63 rm: remove regular empty file \`z/empty'
64 rm: remove write-protected regular file \`z/fu'
65 rm: remove write-protected regular empty file \`z/empty-u'
66 rm: remove symbolic link \`z/slink'
67 rm: remove symbolic link \`z/slinkdot'
68 rm: remove directory \`z/d'
69 rm: remove write-protected directory \`z/du'
70 rm: remove directory \`z'
71 EOF
72
73 compare out exp || fail=1
74
75 test -d z && fail=1
76
77 Exit $fail