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