Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / rm / interactive-always
1 #!/bin/sh
2 # Test the --interactive[=WHEN] changes added to coreutils 6.0
3
4 # Copyright (C) 2006 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 2 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, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 test=interactive-always
22
23 if test "$VERBOSE" = yes; then
24   set -x
25   rm --version
26 fi
27
28 . $srcdir/../lang-default
29
30 pwd=`pwd`
31 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
32 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
33 trap '(exit $?); exit $?' 1 2 13 15
34
35 framework_failure=0
36 mkdir -p $tmp || framework_failure=1
37 cd $tmp || framework_failure=1
38
39 touch file1-1 file1-2 file2-1 file2-2 file3-1 file3-2 file4-1 file4-2 \
40   || framework_failure=1
41 # If asked, answer no to first question, then yes to second.
42 echo 'n
43 y' > $test.I || framework_failure=1
44 rm -f out err || framework_failure=1
45
46 if test $framework_failure = 1; then
47   echo "$0: failure in testing framework" 1>&2
48   (exit 1); exit 1
49 fi
50
51 fail=0
52
53 # The prompt has a trailing space, and no newline, so an extra
54 # 'echo .' is inserted after each rm to make it obvious what was asked.
55
56 echo 'no WHEN' > err || fail=1
57 rm -R --interactive file1-* < $test.I >> out 2>> err || fail=1
58 echo . >> err || fail=1
59 test -f file1-1 || fail=1
60 test -f file1-2 && fail=1
61
62 echo 'WHEN=never' >> err || fail=1
63 rm -R --interactive=never file2-* < $test.I >> out 2>> err || fail=1
64 echo . >> err || fail=1
65 test -f file2-1 && fail=1
66 test -f file2-2 && fail=1
67
68 echo 'WHEN=once' >> err || fail=1
69 rm -R --interactive=once file3-* < $test.I >> out 2>> err || fail=1
70 echo . >> err || fail=1
71 test -f file3-1 || fail=1
72 test -f file3-2 || fail=1
73
74 echo 'WHEN=always' >> err || fail=1
75 rm -R --interactive=always file4-* < $test.I >> out 2>> err || fail=1
76 echo . >> err || fail=1
77 test -f file4-1 || fail=1
78 test -f file4-2 && fail=1
79
80 echo '-f overrides --interactive' >> err || fail=1
81 rm -R --interactive=once -f file1-* < $test.I >> out 2>> err || fail=1
82 echo . >> err || fail=1
83 test -f file1-1 && fail=1
84
85 echo '--interactive overrides -f' >> err || fail=1
86 rm -R -f --interactive=once file4-* < $test.I >> out 2>> err || fail=1
87 echo . >> err || fail=1
88 test -f file4-1 || fail=1
89
90 cat <<\EOF > expout || fail=1
91 EOF
92 cat <<\EOF > experr || fail=1
93 no WHEN
94 rm: remove regular empty file `file1-1'? rm: remove regular empty file `file1-2'? .
95 WHEN=never
96 .
97 WHEN=once
98 rm: remove all arguments recursively? .
99 WHEN=always
100 rm: remove regular empty file `file4-1'? rm: remove regular empty file `file4-2'? .
101 -f overrides --interactive
102 .
103 --interactive overrides -f
104 rm: remove all arguments recursively? .
105 EOF
106
107 cmp out expout || fail=1
108 cmp err experr || fail=1
109 test $fail = 1 && {
110   diff out expout 2> /dev/null; diff err experr 2> /dev/null
111 }
112
113 (exit $fail); exit $fail