3 # Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
4 # Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
6 [ -f testing.sh ] && . testing.sh
8 #testing "name" "command" "result" "infile" "stdin"
11 testing "old_file to new_file" "mv file file1 && [ ! -e file -a -f file1 ] &&
12 echo 'yes'" "yes\n" "" ""
17 testing "file to a dir" "mv file dir && [ ! -e file -a -f dir/file ] &&
18 echo 'yes'" "yes\n" "" ""
22 testing "old_dir to new_dir" "mv dir dir1 && [ ! -e dir -a -d dir1 ] &&
23 echo 'yes'" "yes\n" "" ""
27 touch file1 file2 dir1/file3
29 testing "multiple files/dir to a dir" "mv file1 file2 link1 dir1 dir2 &&
30 [ ! -e file1 -a ! -e file2 -a ! -e link1 -a ! -e dir1 ] &&
31 [ -f dir2/file1 -a -f dir2/file2 -a -L dir2/link1 -a -d dir2/dir1 ] &&
32 [ -f dir2/dir1/file3 ] && readlink dir2/link1" "file1\n" "" ""
33 rm -rf file* link* dir*
36 testing "a empty file to new_file" "mv file1 file2 &&
37 [ ! -e file1 -a -f file2 ] && stat -c %s file2" "0\n" "" ""
41 testing "enpty dir to new_dir" "mv dir1 dir2 &&
42 [ ! -d dir1 -a -d dir2 ] && echo 'yes'" "yes\n" "" ""
45 dd if=/dev/zero of=file1 seek=10k count=1 >/dev/null 2>&1
46 testing "file new_file (random file)" "mv file1 file2 &&
47 [ ! -e file1 -a -f file2 ] && stat -c %s file2" "5243392\n" "" ""
52 testing "link new_link (softlink)" "mv link1 link2 &&
53 [ ! -e link1 -a -L link2 ] && readlink link2" "file1\n" "" ""
54 unlink tLink2 &>/dev/null
59 testing "link new_link (hardlink)" "mv link1 link2 &&
60 [ ! -e link1 -a -f link2 -a file1 -ef link2 ] && echo 'yes'" "yes\n" "" ""
61 unlink link2 &>/dev/null
66 testing "file new_file (unreadable)" "mv file1 file2 &&
67 [ ! -e file1 -a -f file2 ] && echo 'yes'" "yes\n" "" ""
73 testing "file link dir (hardlink)" "mv file1 link1 dir1 &&
74 [ ! -e file1 -a ! -e link1 -a -f dir1/file1 -a -f dir1/link1 ] &&
75 [ dir1/file1 -ef dir1/link1 ] && echo 'yes'" "yes\n" "" ""
76 rm -rf file* link* dir*
78 mkdir -p dir1/dir2 dir3
79 touch dir1/dir2/file1 dir1/dir2/file2
80 testing "dir1/dir2 dir3/new_dir" "mv dir1/dir2 dir3/dir4 &&
81 [ ! -e dir1/dir2 -a -d dir3/dir4 -a -f dir3/dir4/file1 ] &&
82 [ -f dir3/dir4/file2 ] && echo 'yes'" "yes\n" "" ""
86 testing "dir new_dir (already exist)" "mv dir1 dir2 &&
87 [ ! -e dir1 -a -d dir2/dir1 ] && echo 'yes'" "yes\n" "" ""
91 testing "-f file new_file (exist)" "mv -f file1 file2 &&
92 [ ! -e file1 -a -e file2 ] && echo 'yes'" "yes\n" "" ""
96 testing "-n file new_file (exist)" "mv -n file1 file2 &&
97 [ -e file1 -a -e file2 ] && echo 'yes'" "yes\n" "" ""
101 chmod 400 file1 file2
102 testing "file over unwritable file with no stdin" \
103 "</dev/null mv file2 file1 && [ -e file -a ! -e file2 ] && echo 'yes'" \