Home | History | Annotate | Download | only in tests
      1 #!/bin/bash
      2 
      3 [ -f testing.sh ] && . testing.sh
      4 
      5 #testing "name" "command" "result" "infile" "stdin"
      6 
      7 APWD="$(pwd -P)"
      8 
      9 testing "readlink missing" "readlink notfound || echo yes" "yes\n" "" ""
     10 
     11 # simple tests on a file
     12 
     13 touch file
     14 testing "readlink file" "readlink file || echo yes" "yes\n" "" ""
     15 testing "readlink -f dir" "readlink -f ." "$APWD\n" "" ""
     16 testing "readlink -f missing" "readlink -f notfound" "$APWD/notfound\n" "" ""
     17 
     18 ln -sf notfound link
     19 testing "readlink link" "readlink link" "notfound\n" "" ""
     20 testing "readlink link->missing" "readlink -f link" "$APWD/notfound\n" "" ""
     21 ln -sf ../../ link
     22 testing "readlink stays relative" "readlink link" "../../\n" "" ""
     23 rm link
     24 ln -sf file link
     25 testing "readlink -f link->file" "readlink -f link" "$APWD/file\n" "" ""
     26 ln -sf . link
     27 testing "readlink -f link->dir" "readlink -f link" "$APWD\n" "" ""
     28 ln -snf link link
     29 testing "readlink link->link (recursive)" "readlink link" "link\n" "" ""
     30 testing "readlink -f link->link (recursive)" \
     31   "readlink -f link 2>/dev/null || echo yes" "yes\n" "" ""
     32 
     33 testing "readlink -q notlink" "readlink -q file || echo yes" "yes\n" "" ""
     34 testing "readlink -q link" "readlink -q link && echo yes" "yes\n" "" ""
     35 testing "readlink -q notfound" "readlink -q notfound || echo yes" "yes\n" "" ""
     36 testing "readlink -e found" "readlink -e file" "$APWD/file\n" "" ""
     37 testing "readlink -e notfound" \
     38   "readlink -e notfound 2>/dev/null || echo yes" "yes\n" "" ""
     39 testing "readlink -nf ." "readlink -nf ." "$APWD" "" ""
     40 
     41 mkdir sub &&
     42 ln -s . here &&
     43 ln -s ./sub dir &&
     44 touch sub/bang || exit 1
     45 testing "readlink -f multi" "readlink -f dir/../here/dir/bang" \
     46   "$APWD/sub/bang\n" "" ""
     47 testing "readlink -f link/missing" "readlink -f dir/boing" \
     48   "$APWD/sub/boing\n" "" ""
     49 testing "readlink -f /dev/null/file" \
     50   "readlink -f /dev/null/file 2>/dev/null || echo yes" "yes\n" "" ""
     51 ln -sf / link || exit 1
     52 testing "readlink -f link->/" "readlink -e link/dev" "/dev\n" "" ""
     53 testing "readlink -f /dev/null/.." \
     54   "readlink -f link/null/.. 2>/dev/null || echo yes" "yes\n" "" ""
     55 rm -f link && ln -sf link link || exit 1
     56 testing "readlink recurse" "readlink link" "link\n" "" ""
     57 
     58 rm file link sub/bang dir here
     59 rmdir sub
     60 
     61 # Make sure circular links don't run away.
     62 
     63 ln -s link1 link2
     64 ln -s link2 link1
     65 testing "readlink follow recursive2" "readlink -f link1 || echo yes" \
     66 	"yes\n" "" ""
     67 rm link1 link2
     68