Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / cp / cp-mv-backup
1 #!/bin/sh
2 # Test basic --backup functionality for both cp and mv.
3
4 # Copyright (C) 1999, 2000, 2002, 2004, 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 if test "$VERBOSE" = yes; then
22   set -x
23   cp --version
24 fi
25
26 # Ensure that ls sorts the same way for everyone.
27 . $srcdir/../lang-default
28
29 . $srcdir/../envvar-check
30
31 umask 022
32
33 # Be careful to close $actual before removing the containing directory.
34 # Use `1>&2' rather than `1<&-' since the latter appears not to work
35 # with /bin/sh from powerpc-ibm-aix4.2.0.0.
36
37 pwd=`pwd`
38 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
39 trap 'status=$?; cd "$pwd" && exec 1>&2; rm -rf $t0 && exit $status' 0
40 trap '(exit $?); exit' 1 2 13 15
41
42 framework_failure=0
43 mkdir -p $tmp || framework_failure=1
44 cd $tmp || 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 actual=actual
52 expected=expected
53
54 exec 1> $actual
55
56 fail=0
57 for prog in cp mv; do
58   for initial_files in 'x' 'x y' 'x y y~' 'x y y.~1~' 'x y y~ y.~1~'; do
59     for opt in none off  numbered t  existing nil  simple never; do
60       touch $initial_files
61         $prog --backup=$opt x y || fail=1
62       echo $initial_files $opt: `ls [xy]*`; rm -f x y y~ y.~?~
63     done
64   done
65 done
66
67 cat <<\EOF > $expected-tmp
68 x none: x y
69 x off: x y
70 x numbered: x y
71 x t: x y
72 x existing: x y
73 x nil: x y
74 x simple: x y
75 x never: x y
76 x y none: x y
77 x y off: x y
78 x y numbered: x y y.~1~
79 x y t: x y y.~1~
80 x y existing: x y y~
81 x y nil: x y y~
82 x y simple: x y y~
83 x y never: x y y~
84 x y y~ none: x y y~
85 x y y~ off: x y y~
86 x y y~ numbered: x y y.~1~ y~
87 x y y~ t: x y y.~1~ y~
88 x y y~ existing: x y y~
89 x y y~ nil: x y y~
90 x y y~ simple: x y y~
91 x y y~ never: x y y~
92 x y y.~1~ none: x y y.~1~
93 x y y.~1~ off: x y y.~1~
94 x y y.~1~ numbered: x y y.~1~ y.~2~
95 x y y.~1~ t: x y y.~1~ y.~2~
96 x y y.~1~ existing: x y y.~1~ y.~2~
97 x y y.~1~ nil: x y y.~1~ y.~2~
98 x y y.~1~ simple: x y y.~1~ y~
99 x y y.~1~ never: x y y.~1~ y~
100 x y y~ y.~1~ none: x y y.~1~ y~
101 x y y~ y.~1~ off: x y y.~1~ y~
102 x y y~ y.~1~ numbered: x y y.~1~ y.~2~ y~
103 x y y~ y.~1~ t: x y y.~1~ y.~2~ y~
104 x y y~ y.~1~ existing: x y y.~1~ y.~2~ y~
105 x y y~ y.~1~ nil: x y y.~1~ y.~2~ y~
106 x y y~ y.~1~ simple: x y y.~1~ y~
107 x y y~ y.~1~ never: x y y.~1~ y~
108 EOF
109
110 sed 's/: x/:/' $expected-tmp |cat $expected-tmp - > $expected
111
112 cmp $expected $actual || fail=1
113
114 # Uncomment this if you see a failure and want to try to diagnose it.
115 test $fail = 1 && diff -c $expected $actual 1>&2
116
117 (exit $fail); exit $fail