7d4c47d64387896cdefda222a1ad45fb65d3fa34
[platform/upstream/coreutils.git] / tests / cp / backup-is-src
1 #!/bin/sh
2
3 if test "$VERBOSE" = yes; then
4   set -x
5   cp --version
6 fi
7
8 . $srcdir/../lang-default
9 . $srcdir/../envvar-check
10
11 pwd=`pwd`
12 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
13 trap 'status=$?; cd $pwd; rm -rf $t0 && exit $status' 0
14 trap '(exit $?); exit' 1 2 13 15
15
16 framework_failure=0
17 mkdir -p $tmp || framework_failure=1
18 cd $tmp || framework_failure=1
19
20 echo a > a || framework_failure=1
21 echo a-tilde > a~ || framework_failure=1
22
23 if test $framework_failure = 1; then
24   echo "$0: failure in testing framework" 1>&2
25   (exit 1); exit 1
26 fi
27
28 # This cp command should exit nonzero.
29 cp --b=simple a~ a > out 2>&1 && fail=1
30
31 sed "s,cp:,XXX:," out > out2
32
33 cat > exp <<\EOF
34 XXX: backing up `a' would destroy source;  `a~' not copied
35 EOF
36
37 cmp out2 exp || fail=1
38
39 (exit $fail); exit $fail