1#!/bin/sh
2# Test basic --backup functionality for both cp and mv.
3
4# Copyright (C) 1999-2023 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 <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ cp
21
22umask 022
23
24# Be careful to close $actual before removing the containing directory.
25# Use '1>&2' rather than '1<&-' since the latter appears not to work
26# with /bin/sh from powerpc-ibm-aix4.2.0.0.
27
28actual=actual
29expected=expected
30
31exec 3>&1 1> $actual
32
33for prog in cp mv; do
34  for initial_files in 'x' 'x y' 'x y y~' 'x y y.~1~' 'x y y~ y.~1~'; do
35    for opt in none off  numbered t  existing nil  simple never; do
36      touch $initial_files
37        $prog --backup=$opt x y || fail=1
38      echo $initial_files $opt: $(ls [xy]*); rm -f x y y~ y.~?~
39    done
40  done
41done
42
43cat <<\EOF > $expected-tmp
44x none: x y
45x off: x y
46x numbered: x y
47x t: x y
48x existing: x y
49x nil: x y
50x simple: x y
51x never: x y
52x y none: x y
53x y off: x y
54x y numbered: x y y.~1~
55x y t: x y y.~1~
56x y existing: x y y~
57x y nil: x y y~
58x y simple: x y y~
59x y never: x y y~
60x y y~ none: x y y~
61x y y~ off: x y y~
62x y y~ numbered: x y y.~1~ y~
63x y y~ t: x y y.~1~ y~
64x y y~ existing: x y y~
65x y y~ nil: x y y~
66x y y~ simple: x y y~
67x y y~ never: x y y~
68x y y.~1~ none: x y y.~1~
69x y y.~1~ off: x y y.~1~
70x y y.~1~ numbered: x y y.~1~ y.~2~
71x y y.~1~ t: x y y.~1~ y.~2~
72x y y.~1~ existing: x y y.~1~ y.~2~
73x y y.~1~ nil: x y y.~1~ y.~2~
74x y y.~1~ simple: x y y.~1~ y~
75x y y.~1~ never: x y y.~1~ y~
76x y y~ y.~1~ none: x y y.~1~ y~
77x y y~ y.~1~ off: x y y.~1~ y~
78x y y~ y.~1~ numbered: x y y.~1~ y.~2~ y~
79x y y~ y.~1~ t: x y y.~1~ y.~2~ y~
80x y y~ y.~1~ existing: x y y.~1~ y.~2~ y~
81x y y~ y.~1~ nil: x y y.~1~ y.~2~ y~
82x y y~ y.~1~ simple: x y y.~1~ y~
83x y y~ y.~1~ never: x y y.~1~ y~
84EOF
85
86sed 's/: x/:/' $expected-tmp |cat $expected-tmp - > $expected
87
88exec 1>&3 3>&-
89
90compare $expected $actual || fail=1
91
92Exit $fail
93