39e508e5e9eafb5f3922000e04185d19d790cea4
[platform/upstream/coreutils.git] / tests / rm / dir-no-w
1 #!/bin/sh
2 # rm (without -r) must give a diagnostic for any directory.
3 # It must not prompt, even if that directory is unwritable.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   rm --version
8 fi
9
10 . $srcdir/../envvar-check
11 . $srcdir/../lang-default
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 --mode=0500 unwritable-dir || framework_failure=1
22
23 if test $framework_failure = 1; then
24   echo "$0: failure in testing framework" 1>&2
25   (exit 1); exit 1
26 fi
27
28 fail=0
29
30 # For rm from coreutils-5.0.1, this would prompt.
31 rm ---presume-input-tty unwritable-dir < /dev/null > out-t 2>&1 && fail=1
32 cat <<\EOF > exp || fail=1
33 rm: cannot remove `unwritable-dir': Is a directory
34 EOF
35
36 # When run by a non-privileged user we get this:
37 # rm: cannot remove directory `unwritable-dir': Is a directory
38 # When run by root we get this:
39 # rm: cannot remove `unwritable-dir': Is a directory
40 # Normalize the message.
41 sed 's/remove directory/remove/' out-t > out
42 rm -f out-t
43
44 cmp out exp || fail=1
45 test $fail = 1 && diff out exp 2> /dev/null
46
47 (exit $fail); exit $fail