blob: ae39fb68c94b96947c6081d02c2fd83227dc5cf9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#!/bin/bash
# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
[ -f testing.sh ] && . testing.sh
#testing "name" "command" "result" "infile" "stdin"
touch file
testing "mv old_file to new_file" "mv file file1 && [ ! -e file -a -f file1 ] &&
echo 'yes'" "yes\n" "" ""
rm -f file*
touch file
mkdir dir
testing "mv file to a dir" "mv file dir && [ ! -e file -a -f dir/file ] &&
echo 'yes'" "yes\n" "" ""
rm -rf file* dir*
mkdir dir
testing "mv old_dir to new_dir" "mv dir dir1 && [ ! -e dir -a -d dir1 ] &&
echo 'yes'" "yes\n" "" ""
rm -rf dir*
mkdir dir1 dir2
touch file1 file2 dir1/file3
ln -s file1 link1
testing "mv multiple files/dir to a dir" "mv file1 file2 link1 dir1 dir2 &&
[ ! -e file1 -a ! -e file2 -a ! -e link1 -a ! -e dir1 ] &&
[ -f dir2/file1 -a -f dir2/file2 -a -L dir2/link1 -a -d dir2/dir1 ] &&
[ -f dir2/dir1/file3 ] && readlink dir2/link1" "file1\n" "" ""
rm -rf file* link* dir*
touch file1
testing "mv a empty file to new_file" "mv file1 file2 &&
[ ! -e file1 -a -f file2 ] && stat -c %s file2" "0\n" "" ""
rm -rf file*
mkdir dir1
testing "mv enpty dir to new_dir" "mv dir1 dir2 &&
[ ! -d dir1 -a -d dir2 ] && echo 'yes'" "yes\n" "" ""
rm -rf dir*
dd if=/dev/zero of=file1 seek=10k count=1 >/dev/null 2>&1
testing "mv file new_file (random file)" "mv file1 file2 &&
[ ! -e file1 -a -f file2 ] && stat -c %s file2" "5243392\n" "" ""
rm -f file*
touch file1
ln -s file1 link1
testing "mv link new_link (softlink)" "mv link1 link2 &&
[ ! -e link1 -a -L link2 ] && readlink link2" "file1\n" "" ""
unlink tLink2 &>/dev/null
rm -f file* link*
touch file1
ln file1 link1
testing "mv link new_link (hardlink)" "mv link1 link2 &&
[ ! -e link1 -a -f link2 -a file1 -ef link2 ] && echo 'yes'" "yes\n" "" ""
unlink link2 &>/dev/null
rm -f file* link*
touch file1
chmod a-r file1
testing "mv file new_file (unreadable)" "mv file1 file2 &&
[ ! -e file1 -a -f file2 ] && echo 'yes'" "yes\n" "" ""
rm -f file*
touch file1
ln file1 link1
mkdir dir1
testing "mv file link dir (hardlink)" "mv file1 link1 dir1 &&
[ ! -e file1 -a ! -e link1 -a -f dir1/file1 -a -f dir1/link1 ] &&
[ dir1/file1 -ef dir1/link1 ] && echo 'yes'" "yes\n" "" ""
rm -rf file* link* dir*
mkdir -p dir1/dir2 dir3
touch dir1/dir2/file1 dir1/dir2/file2
testing "mv dir1/dir2 dir3/new_dir" "mv dir1/dir2 dir3/dir4 &&
[ ! -e dir1/dir2 -a -d dir3/dir4 -a -f dir3/dir4/file1 ] &&
[ -f dir3/dir4/file2 ] && echo 'yes'" "yes\n" "" ""
rm -rf file* dir*
mkdir dir1 dir2
testing "mv dir new_dir (already exist)" "mv dir1 dir2 &&
[ ! -e dir1 -a -d dir2/dir1 ] && echo 'yes'" "yes\n" "" ""
rm -rf dir*
touch file1 file2
testing "mv -f file new_file (exist)" "mv -f file1 file2 &&
[ ! -e file1 -a -e file2 ] && echo 'yes'" "yes\n" "" ""
rm -f file*
touch file1 file2
testing "mv -n file new_file (exist)" "mv -n file1 file2 &&
[ -e file1 -a -e file2 ] && echo 'yes'" "yes\n" "" ""
rm -f file*
touch file1 file2
chmod 400 file1 file2
testing "mv file over unwritable file with no stdin" \
"</dev/null mv file2 file1 && [ -e file -a ! -e file2 ] && echo 'yes'" \
"yes\n" "" ""
rm -f file*
|