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