build: ensure sys/select.h is included
[coreutils.git] / tests / mv / dup-source.sh
blob4d44ec10d6c5ba5ba8d37d257808e52d77fb5964
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 # Copyright (C) 2001-2019 Free Software Foundation, Inc.
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 3 of the License, or
12 # (at your option) any later version.
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.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
22 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
23 print_ver_ cp mv
25 skip_if_root_
27 reset_files() { rm -fr a b d; touch a; mkdir b d; }
29 for i in cp; do
31 # cp may not fail in this case.
32 reset_files
33 $i a a d/ 2> out || fail=1
34 reset_files
35 $i ./a a d/ 2>> out || fail=1
37 # Similarly for directories, but handle
38 # source == dest appropriately.
39 reset_files
40 $i -a ./b b d/ 2>> out || fail=1
41 reset_files
42 returns_ 1 $i -a ./b b b/ 2>> out || fail=1
44 # cp succeeds with --backup=numbered.
45 reset_files
46 $i --backup=numbered a a d/ 2>> out || fail=1
48 # But not with plain '--backup'
49 reset_files
50 returns_ 1 $i --backup a a d/ 2>> out || fail=1
52 cat <<EOF > exp
53 $i: warning: source file 'a' specified more than once
54 $i: warning: source file 'a' specified more than once
55 $i: warning: source directory 'b' specified more than once
56 $i: cannot copy a directory, './b', into itself, 'b/b'
57 $i: warning: source directory 'b' specified more than once
58 $i: will not overwrite just-created 'd/a' with 'a'
59 EOF
60 compare exp out || fail=1
61 done
63 for i in mv; do
64 # But mv *does* fail in this case (it has to).
65 reset_files
66 returns_ 1 $i a a d/ 2> out || fail=1
67 returns_ 1 test -e a || fail=1
68 reset_files
69 returns_ 1 $i ./a a d/ 2>> out || fail=1
70 returns_ 1 test -e a || fail=1
72 # Similarly for directories, also handling
73 # source == dest appropriately.
74 reset_files
75 returns_ 1 $i ./b b d/ 2>> out || fail=1
76 returns_ 1 test -e b || fail=1
77 reset_files
78 returns_ 1 $i --verbose ./b b b/ 2>> out || fail=1
79 test -d b || fail=1
81 cat <<EOF > exp
82 $i: cannot stat 'a': No such file or directory
83 $i: cannot stat 'a': No such file or directory
84 $i: cannot stat 'b': No such file or directory
85 $i: cannot move './b' to a subdirectory of itself, 'b/b'
86 $i: warning: source directory 'b' specified more than once
87 EOF
88 compare exp out || fail=1
89 done
91 Exit $fail