7868e903ab10d2fc0b49bad6a0d57b6d10eac67c
[platform/upstream/coreutils.git] / tests / rm / rm5
1 #!/bin/sh
2 # a basic test of rm -ri
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 d/e || framework_failure=1
22 cat <<EOF > in || framework_failure=1
23 y
24 y
25 y
26 EOF
27
28 cat <<\EOF > exp || framework_failure=1
29 rm: descend into directory `d'
30 rm: remove directory `d/e'
31 rm: remove directory `d'
32 EOF
33
34 if test $framework_failure = 1; then
35   echo "$0: failure in testing framework" 1>&2
36   (exit 1); exit 1
37 fi
38
39 fail=0
40
41 rm -ir d < in > out 2>&1 || fail=1
42
43 # Given input like `rm: ...? rm: ...? ' (no trailing newline),
44 # the `head...' part of the pipeline below removes the trailing space, so
45 # that sed doesn't have to deal with a line lacking a terminating newline.
46 # This avoids a bug whereby some vendor-provided (Tru64) versions of sed
47 # would mistakenly tack a newline onto the end of the output.
48 tr '?' '\n' < out | head --bytes=-1 | sed 's/^ //' > o2
49 mv o2 out
50
51 # Make sure it's been removed.
52 test -d d && fail=1
53
54 cmp out exp || fail=1
55 test $fail = 1 && diff -u out exp 2> /dev/null
56
57 (exit $fail); exit $fail