• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "links" "readlink link link" "notfound\nnotfound\n" "" ""
21testing "link->missing" "readlink -f link" "$APWD/notfound\n" "" ""
22ln -sf ../../ link
23testing "stays relative" "readlink link" "../../\n" "" ""
24rm link
25ln -sf file link
26testing "-f link->file" "readlink -f link" "$APWD/file\n" "" ""
27ln -sf . link
28testing "-f link->dir" "readlink -f link" "$APWD\n" "" ""
29ln -snf link link
30testing "link->link (recursive)" "readlink link" "link\n" "" ""
31testing "-f link->link (recursive)" \
32  "readlink -f link 2>/dev/null || echo yes" "yes\n" "" ""
33
34testing "-q notlink" "readlink -q file || echo yes" "yes\n" "" ""
35testing "-q link" "readlink -q link && echo yes" "yes\n" "" ""
36testing "-q notfound" "readlink -q notfound || echo yes" "yes\n" "" ""
37testing "-e found" "readlink -e file" "$APWD/file\n" "" ""
38testing "-e notfound" \
39  "readlink -e notfound 2>/dev/null || echo yes" "yes\n" "" ""
40testing "-nf ." "readlink -nf ." "$APWD" "" ""
41
42mkdir sub &&
43ln -s . here &&
44ln -s ./sub dir &&
45touch sub/bang || exit 1
46testing "-f multi" "readlink -f dir/../here/dir/bang" \
47  "$APWD/sub/bang\n" "" ""
48testing "-f link/missing" "readlink -f dir/boing" \
49  "$APWD/sub/boing\n" "" ""
50testing "-f /dev/null/file" \
51  "readlink -f /dev/null/file 2>/dev/null || echo yes" "yes\n" "" ""
52testing "-m missing/dir" "readlink -m sub/two/three" "$APWD/sub/two/three\n" "" ""
53testing "-m missing/../elsewhere" "readlink -m sub/two/../../three" "$APWD/three\n" "" ""
54testing "-m file/dir" "readlink -m sub/bang/two 2>/dev/null || echo err" "err\n" "" ""
55rm link
56ln -sf / link || exit 1
57testing "-f link->/" "readlink -e link/dev" "/dev\n" "" ""
58testing "-f /dev/null/.." \
59  "readlink -f link/null/.. 2>/dev/null || echo yes" "yes\n" "" ""
60rm -f link && ln -sf link link || exit 1
61testing "recurse" "readlink link" "link\n" "" ""
62
63rm file link sub/bang dir here
64rmdir sub
65
66# Make sure circular links don't run away.
67
68ln -s link1 link2
69ln -s link2 link1
70testing "follow recursive2" "readlink -f link1 || echo yes" \
71	"yes\n" "" ""
72rm link1 link2
73