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