ad2b7eb3f47b7ed886c420ae4073efdfa348ba98
[platform/upstream/coreutils.git] / tests / mv / dup-source
1 #!/bin/sh
2 # Ensure that cp merely warns when a non-directory source file is
3 # listed on the command line more than once.  fileutils-4.1.1
4 # made this fail:  cp a a d/
5 # Ensure that mv fails with a similar command.
6
7 if test "$VERBOSE" = yes; then
8   set -x
9   cp --version
10   mv --version
11 fi
12
13 . $srcdir/../envvar-check
14 . $srcdir/../lang-default
15 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
16
17 pwd=`pwd`
18 tmp=dup-src.$$
19 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
20 trap '(exit $?); exit' 1 2 13 15
21
22 framework_failure=0
23 mkdir $tmp || framework_failure=1
24 cd $tmp || framework_failure=1
25
26 if test $framework_failure = 1; then
27   echo "$0: failure in testing framework" 1>&2
28   (exit 1); exit 1
29 fi
30
31 fail=0
32
33 for i in cp; do
34
35   # cp may not fail in this case.
36
37   rm -fr a d; touch a; mkdir d
38   $i a a d/ 2> out || fail=1
39   rm -fr a d; touch a; mkdir d
40   $i ./a a d/ 2>> out || fail=1
41
42   # cp succeeds with --backup=numbered.
43   rm -fr a d; touch a; mkdir d
44   $i --backup=numbered a a d/ 2>> out || fail=1
45
46   # But not with plain `--backup'
47   rm -fr a d; touch a; mkdir d
48   $i --backup a a d/ 2>> out && fail=1
49   cat <<EOF > exp
50 $i: warning: source file \`a' specified more than once
51 $i: warning: source file \`a' specified more than once
52 $i: will not overwrite just-created \`d/a' with \`a'
53 EOF
54   cmp out exp || fail=1
55   test $fail = 1 && diff out exp 2> /dev/null
56 done
57
58 for i in mv; do
59   # But mv *does* fail in this case (it has to).
60
61   rm -fr a d; touch a; mkdir d
62   $i a a d/ 2> out && fail=1
63   rm -fr a d; touch a; mkdir d
64   $i ./a a d/ 2>> out && fail=1
65   cat <<EOF > exp
66 $i: cannot stat \`a': No such file or directory
67 $i: cannot stat \`a': No such file or directory
68 EOF
69   cmp out exp || fail=1
70   test $fail = 1 && diff out exp 2> /dev/null
71 done
72
73 (exit $fail); exit $fail