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 #set -x 10 11 echo file1 > file 12 testing "ln create_hardlink" "ln file hlink && [ file -ef hlink ] && 13 echo 'yes'" "yes\n" "" "" 14 testing "ln create_softlink" "ln -s file slink && [ -L slink ] && 15 readlink slink" "file\n" "" "" 16 rm slink hlink 17 18 echo hlink1 > hlink 19 testing "ln force_create_hardlink" "ln -f file hlink && 20 [ file -ef hlink ] && cat hlink 2>/dev/null" "file1\n" "" "" 21 22 echo slink1 > slink 23 testing "ln force_create_softlink" "ln -f -s file slink && 24 [ -L slink ] && readlink slink" "file\n" "" "" 25 rm slink hlink 26 27 echo hlink1 > hlink 28 set +e 29 testing "ln preserves_hardlinks" "ln file hlink 2>/dev/null || echo 'yes'" \ 30 "yes\n" "" "" 31 32 echo slink1 > slink 33 set +e 34 testing "ln preserves_softlinks" "ln -s file slink 2>/dev/null || echo 'yes'" \ 35 "yes\n" "" "" 36 rm slink hlink 37 38 mkdir dir 39 testing "ln multilevel_symbolic_links" "ln -s dir slink && 40 ln -s file slink && [ -L slink -a -L slink/file ] && 41 readlink slink && readlink slink/file" "dir\nfile\n" "" "" 42 rm slink 43 44 testing "ln no_dereference" "ln -s dir slink && 45 ln -n -s file slink 2>/dev/null || [ -L slink ] && readlink slink" \ 46 "dir\n" "" "" 47 rm -rf file dir slink 48 49 touch file1 file2 && mkdir dir 50 testing "ln create_multiple_hardlinks" "ln file* dir/ && 51 [ file1 -ef dir/file1 -a file2 -ef dir/file2 ] && echo 'yes'" "yes\n" "" "" 52 rm -rf file* dir 53 54 touch file1 file2 && mkdir dir 55 testing "ln create_multiple_softlinks" "ln -s file* dir/ && 56 [ -L dir/file1 -a -L dir/file2 ] && readlink dir/file1 && 57 readlink dir/file2" "file1\nfile2\n" "" "" 58 rm -rf file* dir 59 60 echo file1 > file 61 testing "ln create_softlink_and_remove_sourcefile" "ln -s file slink && 62 [ -L slink ] && rm file && cat slink 2>/dev/null || echo 'yes' " \ 63 "yes\n" "" "" 64 rm -f file slink 65 66 echo file1 > file 67 testing "ln create_hardlink_and_remove_sourcefile" "ln file hlink && 68 [ file -ef hlink ] && rm file && [ -f hlink ] && echo 'yes'" \ 69 "yes\n" "" "" 70 rm -f file hlink 71