*** empty log message ***
[coreutils.git] / tests / mv / dup-source
blob4028538283942d2012298bdb4abb1a8b4543537c
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.
7 if test "$VERBOSE" = yes; then
8 set -x
9 cp --version
10 mv --version
13 . $srcdir/../envvar-check
14 . $srcdir/../lang-default
15 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
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
22 framework_failure=0
23 mkdir $tmp || framework_failure=1
24 cd $tmp || framework_failure=1
26 if test $framework_failure = 1; then
27 echo "$0: failure in testing framework" 1>&2
28 (exit 1); exit
31 fail=0
33 for i in cp; do
35 # cp may not fail in this case.
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
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
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
58 for i in mv; do
59 # But mv *does* fail in this case (it has to).
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
73 (exit $fail); exit