3 # TODO: needs root to mount tmpfs to test moving across filesystems.
4 # check handling of chattr +i immutable bit
5 # "touch two; chmod -w two; mv one two" shouldn't prompt to delete two if
8 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
9 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
11 [ -f testing.sh ] && . testing.sh
13 #testing "name" "command" "result" "infile" "stdin"
16 testing "file to file" \
17 "mv file file1 && [ ! -e file -a -f file1 ] && echo yes" \
23 testing "file to dir" \
24 "mv file dir && [ ! -e file -a -f dir/file ] && echo yes" \
29 testing "dir to dir" \
30 "mv dir dir1 && [ ! -e dir -a -d dir1 ] && echo yes" \
35 touch file1 file2 dir1/file3
37 testing "multiple files/dirs to a dir" \
38 "mv file1 file2 link1 dir1 dir2 &&
39 [ ! -e file1 -a ! -e file2 -a ! -e link1 -a ! -e dir1 ] &&
40 [ -f dir2/file1 -a -f dir2/file2 -a -L dir2/link1 -a -d dir2/dir1 ] &&
41 [ -f dir2/dir1/file3 ] && readlink dir2/link1" \
43 rm -rf file* link* dir*
45 dd if=/dev/zero of=file1 seek=10k count=1 >/dev/null 2>&1
46 testing "random file to new file" \
47 "mv file1 file2 && [ ! -e file1 -a -f file2 ] && stat -c %s file2" \
53 testing "symlink to new symlink" \
54 "mv link1 link2 && [ ! -e link1 -a -L link2 ] && readlink link2" \
56 unlink tLink2 &>/dev/null
61 testing "hard link to new hardlink" \
62 "mv link1 link2 && [ ! -e link1 -a -f link2 -a file1 -ef link2 ] && echo yes" \
64 unlink link2 &>/dev/null
69 testing "file to unreadable file" \
70 "mv file1 file2 && [ ! -e file1 -a -f file2 ] && echo yes" \
77 testing "file hardlink dir" \
78 "mv file1 link1 dir1 &&
79 [ ! -e file1 -a ! -e link1 -a -f dir1/file1 -a -f dir1/link1 ] &&
80 [ dir1/file1 -ef dir1/link1 ] && echo yes" \
82 rm -rf file* link* dir*
84 mkdir -p dir1/dir2 dir3
85 touch dir1/dir2/file1 dir1/dir2/file2
86 testing "dir to new dir" \
87 "mv dir1/dir2 dir3/new &&
88 [ ! -e dir1/dir2 -a -d dir3/new -a -f dir3/new/file1 ] &&
89 [ -f dir3/new/file2 ] && echo yes" \
94 testing "dir to existing dir" \
95 "mv dir1 dir2 && [ ! -e dir1 -a -d dir2/dir1 ] && echo yes" \
100 chmod 400 file1 file2
101 testing "force over unwritable" \
102 "mv -f file1 file2 && [ ! -e file1 -a -e file2 ] && echo yes" \
107 testing "no clobber (dest exists)" \
108 "mv -n file1 file2 && [ -e file1 -a -e file2 ] && echo yes"\
113 testing "no clobber (dest doesn't exist)" \
114 "mv -n file1 new-dest && [ ! -e file1 -a -e new-dest ] && echo yes"\
118 # If there is stdin, it prompts. If no stdin, it moves anyway and file2 won't
121 chmod 400 file1 file2
122 testing "mv over unwritable file: no stdin" \
123 "mv file2 file1 && [ -e file1 -a ! -e file2 ] && echo yes" \
128 chmod 400 file1 file2
129 testing "mv over unwritable file: answered YES" \
130 "mv file2 file1 && [ -e file1 -a ! -e file2 ] && echo yes" \
135 chmod 400 file1 file2
136 testing "mv over unwritable file: answered NO" \
137 "mv file2 file1 && [ -e file1 -a -e file2 ] && echo yes" \
142 testing "interactive: no stdin" \
143 "mv -i file2 file1 && [ -e file1 -a ! -e file2 ] && echo yes" \
148 testing "interactive: answered YES" \
149 "mv -i file2 file1 && [ -e file1 -a ! -e file2 ] && echo yes" \
154 testing "interactive: answered NO" \
155 "mv -i file2 file1 && [ -e file1 -a -e file2 ] && echo yes" \