Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / rm / interactive-once
1 #!/bin/sh
2 # Test the -I option 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-once
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 mkdir -p dir1-1 dir2-1 dir2-2 || framework_failure=1
40 touch file1-1 file2-1 file2-2 file2-3 file3-1 file3-2 file3-3 file3-4 \
41   || framework_failure=1
42 echo y > $test.Iy || framework_failure=1
43 echo n > $test.In || 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 'one file, no recursion' > err || fail=1
57 rm -I file1-* < $test.In >> out 2>> err || fail=1
58 echo . >> err || fail=1
59 test -f file1-1 && fail=1
60
61 echo 'three files, no recursion' >> err || fail=1
62 rm -I file2-* < $test.In >> out 2>> err || fail=1
63 echo . >> err || fail=1
64 test -f file2-1 && fail=1
65 test -f file2-2 && fail=1
66 test -f file2-3 && fail=1
67
68 echo 'four files, no recursion, answer no' >> err || fail=1
69 rm -I file3-* < $test.In >> 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 test -f file3-3 || fail=1
74 test -f file3-4 || fail=1
75
76 echo 'four files, no recursion, answer yes' >> err || fail=1
77 rm -I file3-* < $test.Iy >> out 2>> err || fail=1
78 echo . >> err || fail=1
79 test -f file3-1 && fail=1
80 test -f file3-2 && fail=1
81 test -f file3-3 && fail=1
82 test -f file3-4 && fail=1
83
84 echo 'one file, recursion, answer no' >> err || fail=1
85 rm -I -R dir1-* < $test.In >> out 2>> err || fail=1
86 echo . >> err || fail=1
87 test -d dir1-1 || fail=1
88
89 echo 'one file, recursion, answer yes' >> err || fail=1
90 rm -I -R dir1-* < $test.Iy >> out 2>> err || fail=1
91 echo . >> err || fail=1
92 test -d dir1-1 && fail=1
93
94 echo 'multiple files, recursion, answer no' >> err || fail=1
95 rm -I -R dir2-* < $test.In >> out 2>> err || fail=1
96 echo . >> err || fail=1
97 test -d dir2-1 || fail=1
98 test -d dir2-2 || fail=1
99
100 echo 'multiple files, recursion, answer yes' >> err || fail=1
101 rm -I -R dir2-* < $test.Iy >> out 2>> err || fail=1
102 echo . >> err || fail=1
103 test -d dir2-1 && fail=1
104 test -d dir2-2 && fail=1
105
106 cat <<\EOF > expout || fail=1
107 EOF
108 cat <<\EOF > experr || fail=1
109 one file, no recursion
110 .
111 three files, no recursion
112 .
113 four files, no recursion, answer no
114 rm: remove all arguments? .
115 four files, no recursion, answer yes
116 rm: remove all arguments? .
117 one file, recursion, answer no
118 rm: remove all arguments recursively? .
119 one file, recursion, answer yes
120 rm: remove all arguments recursively? .
121 multiple files, recursion, answer no
122 rm: remove all arguments recursively? .
123 multiple files, recursion, answer yes
124 rm: remove all arguments recursively? .
125 EOF
126
127 cmp out expout || fail=1
128 cmp err experr || fail=1
129 test $fail = 1 && {
130   diff out expout 2> /dev/null; diff err experr 2> /dev/null
131 }
132
133 (exit $fail); exit $fail