f27fd6cf5ea7e0395c6451813b3dd94078970288
[platform/upstream/coreutils.git] / tests / rm / rm3
1 #!/bin/sh
2 # exercise another small part of remove.c
3
4 if test "$VERBOSE" = yes; then
5   set -x
6   rm --version
7 fi
8
9 . $srcdir/../envvar-check
10 . $srcdir/../lang-default
11 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
12
13 pwd=`pwd`
14 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
15 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
16 trap '(exit $?); exit' 1 2 13 15
17
18 framework_failure=0
19 mkdir -p $tmp || framework_failure=1
20 cd $tmp || framework_failure=1
21 mkdir -p z || framework_failure=1
22 cd z || framework_failure=1
23 touch empty empty-u || framework_failure=1
24 echo not-empty > fu
25 ln -s empty-f slink
26 ln -s . slinkdot
27 mkdir d du || framework_failure=1
28 chmod u-w fu du empty-u || framework_failure=1
29 cd ..
30
31 if test $framework_failure = 1; then
32   echo "$0: failure in testing framework" 1>&2
33   (exit 1); exit 1
34 fi
35
36 fail=0
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 cmp out exp || fail=1
74 test $fail = 1 && diff -u out exp 2> /dev/null
75
76 test -d z && fail=1
77
78 (exit $fail); exit $fail