tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/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-2009 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 3 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, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   cp --version
22 fi
23
24 # Ensure that ls sorts the same way for everyone.
25
26 . $srcdir/test-lib.sh
27
28 umask 022
29
30 # Be careful to close $actual before removing the containing directory.
31 # Use `1>&2' rather than `1<&-' since the latter appears not to work
32 # with /bin/sh from powerpc-ibm-aix4.2.0.0.
33
34 actual=actual
35 expected=expected
36
37 exec 1> $actual
38
39 for prog in cp mv; do
40   for initial_files in 'x' 'x y' 'x y y~' 'x y y.~1~' 'x y y~ y.~1~'; do
41     for opt in none off  numbered t  existing nil  simple never; do
42       touch $initial_files
43         $prog --backup=$opt x y || fail=1
44       echo $initial_files $opt: `ls [xy]*`; rm -f x y y~ y.~?~
45     done
46   done
47 done
48
49 cat <<\EOF > $expected-tmp
50 x none: x y
51 x off: x y
52 x numbered: x y
53 x t: x y
54 x existing: x y
55 x nil: x y
56 x simple: x y
57 x never: x y
58 x y none: x y
59 x y off: x y
60 x y numbered: x y y.~1~
61 x y t: x y y.~1~
62 x y existing: x y y~
63 x y nil: x y y~
64 x y simple: x y y~
65 x y never: x y y~
66 x y y~ none: x y y~
67 x y y~ off: x y y~
68 x y y~ numbered: x y y.~1~ y~
69 x y y~ t: x y y.~1~ y~
70 x y y~ existing: x y y~
71 x y y~ nil: x y y~
72 x y y~ simple: x y y~
73 x y y~ never: x y y~
74 x y y.~1~ none: x y y.~1~
75 x y y.~1~ off: x y y.~1~
76 x y y.~1~ numbered: x y y.~1~ y.~2~
77 x y y.~1~ t: x y y.~1~ y.~2~
78 x y y.~1~ existing: x y y.~1~ y.~2~
79 x y y.~1~ nil: x y y.~1~ y.~2~
80 x y y.~1~ simple: x y y.~1~ y~
81 x y y.~1~ never: x y y.~1~ y~
82 x y y~ y.~1~ none: x y y.~1~ y~
83 x y y~ y.~1~ off: x y y.~1~ y~
84 x y y~ y.~1~ numbered: x y y.~1~ y.~2~ y~
85 x y y~ y.~1~ t: x y y.~1~ y.~2~ y~
86 x y y~ y.~1~ existing: x y y.~1~ y.~2~ y~
87 x y y~ y.~1~ nil: x y y.~1~ y.~2~ y~
88 x y y~ y.~1~ simple: x y y.~1~ y~
89 x y y~ y.~1~ never: x y y.~1~ y~
90 EOF
91
92 sed 's/: x/:/' $expected-tmp |cat $expected-tmp - > $expected
93
94 compare $expected $actual || fail=1
95
96 Exit $fail