summaryrefslogtreecommitdiff
path: root/tests/cp/cp-mv-backup
blob: 77f62fa6b91af704ecd89d06939caf8bd0030e79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
# Test basic --backup functionality for both cp and mv.

if test "$VERBOSE" = yes; then
  set -x
  cp --version
fi

# Ensure that ls sorts the same way for everyone.
. $srcdir/../lang-default

. $srcdir/../envvar-check

umask 022

pwd=`pwd`
dir=cpmvbak-$$
actual=$dir/actual
expected=$dir/expected

# Be careful to close $actual before removing the containing directory.
# Use `1>&2' rather than `1<&-' since the latter appears not to work
# with /bin/sh from powerpc-ibm-aix4.2.0.0.
trap "cd $pwd; exec 1>&2; rm -rf $dir" 0 1 2 3 15

mkdir $dir

exec 1> $actual

fail=0
for prog in cp mv; do
  for initial_files in 'x' 'x y' 'x y y~' 'x y y.~1~' 'x y y~ y.~1~'; do
    for opt in none off  numbered t  existing nil  simple never; do
      ( cd $dir; touch $initial_files )
	$prog --backup=$opt $dir/x $dir/y || fail=1
      ( cd $dir; echo $initial_files $opt: `ls [xy]*`; rm -f x y y~ y.~?~ )
    done
  done
done

cat <<\EOF > $expected-tmp
x none: x y
x off: x y
x numbered: x y
x t: x y
x existing: x y
x nil: x y
x simple: x y
x never: x y
x y none: x y
x y off: x y
x y numbered: x y y.~1~
x y t: x y y.~1~
x y existing: x y y~
x y nil: x y y~
x y simple: x y y~
x y never: x y y~
x y y~ none: x y y~
x y y~ off: x y y~
x y y~ numbered: x y y.~1~ y~
x y y~ t: x y y.~1~ y~
x y y~ existing: x y y~
x y y~ nil: x y y~
x y y~ simple: x y y~
x y y~ never: x y y~
x y y.~1~ none: x y y.~1~
x y y.~1~ off: x y y.~1~
x y y.~1~ numbered: x y y.~1~ y.~2~
x y y.~1~ t: x y y.~1~ y.~2~
x y y.~1~ existing: x y y.~1~ y.~2~
x y y.~1~ nil: x y y.~1~ y.~2~
x y y.~1~ simple: x y y.~1~ y~
x y y.~1~ never: x y y.~1~ y~
x y y~ y.~1~ none: x y y.~1~ y~
x y y~ y.~1~ off: x y y.~1~ y~
x y y~ y.~1~ numbered: x y y.~1~ y.~2~ y~
x y y~ y.~1~ t: x y y.~1~ y.~2~ y~
x y y~ y.~1~ existing: x y y.~1~ y.~2~ y~
x y y~ y.~1~ nil: x y y.~1~ y.~2~ y~
x y y~ y.~1~ simple: x y y.~1~ y~
x y y~ y.~1~ never: x y y.~1~ y~
EOF

sed 's/: x/:/' $expected-tmp |cat $expected-tmp - > $expected

cmp $expected $actual || fail=1

# Uncomment this if you see a failure and want to try to diagnose it.
test $fail = 1 && diff -c $expected $actual 1>&2

(exit $fail); exit