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