Add/fix copyright notices and adjust to latest GNU FDL.
[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 # Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
8
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # 02110-1301, USA.
23
24 if test "$VERBOSE" = yes; then
25   set -x
26   cp --version
27   mv --version
28 fi
29
30 . $srcdir/../envvar-check
31 . $srcdir/../lang-default
32 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
33
34 pwd=`pwd`
35 tmp=dup-src.$$
36 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
37 trap '(exit $?); exit' 1 2 13 15
38
39 framework_failure=0
40 mkdir $tmp || framework_failure=1
41 cd $tmp || framework_failure=1
42
43 if test $framework_failure = 1; then
44   echo "$0: failure in testing framework" 1>&2
45   (exit 1); exit 1
46 fi
47
48 fail=0
49
50 for i in cp; do
51
52   # cp may not fail in this case.
53
54   rm -fr a d; touch a; mkdir d
55   $i a a d/ 2> out || fail=1
56   rm -fr a d; touch a; mkdir d
57   $i ./a a d/ 2>> out || fail=1
58
59   # cp succeeds with --backup=numbered.
60   rm -fr a d; touch a; mkdir d
61   $i --backup=numbered a a d/ 2>> out || fail=1
62
63   # But not with plain `--backup'
64   rm -fr a d; touch a; mkdir d
65   $i --backup a a d/ 2>> out && fail=1
66   cat <<EOF > exp
67 $i: warning: source file \`a' specified more than once
68 $i: warning: source file \`a' specified more than once
69 $i: will not overwrite just-created \`d/a' with \`a'
70 EOF
71   cmp out exp || fail=1
72   test $fail = 1 && diff out exp 2> /dev/null
73 done
74
75 for i in mv; do
76   # But mv *does* fail in this case (it has to).
77
78   rm -fr a d; touch a; mkdir d
79   $i a a d/ 2> out && fail=1
80   rm -fr a d; touch a; mkdir d
81   $i ./a a d/ 2>> out && fail=1
82   cat <<EOF > exp
83 $i: cannot stat \`a': No such file or directory
84 $i: cannot stat \`a': No such file or directory
85 EOF
86   cmp out exp || fail=1
87   test $fail = 1 && diff out exp 2> /dev/null
88 done
89
90 (exit $fail); exit $fail