blob: cf10ea48f837d4bbeca53b20c76518e0dddbb528 [file] [log] [blame]
Rob Landleyb4ed7622007-12-15 22:05:42 -06001#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7testing "readlink missing" "readlink notfound || echo yes" "yes\n" "" ""
8
Rob Landleye25e8b52007-12-16 18:02:44 -06009# simple tests on a file
10
Rob Landleyb4ed7622007-12-15 22:05:42 -060011touch file
12testing "readlink file" "readlink file || echo yes" "yes\n" "" ""
13testing "readlink -f dir" "readlink -f ." "$(pwd)\n" "" ""
14testing "readlink -f missing" "readlink -f notfound" "$(pwd)/notfound\n" "" ""
15
Rob Landleye25e8b52007-12-16 18:02:44 -060016# Test a link that points to nonexistent file
Rob Landleyb4ed7622007-12-15 22:05:42 -060017ln -s notfound link
18testing "readlink link" "readlink link" "notfound\n" "" ""
19testing "readlink link->missing" "readlink -f link" "$(pwd)/notfound\n" "" ""
20ln -sf file link
21testing "readlink -f link->file" "readlink -f link" "$(pwd)/file\n" "" ""
22ln -sf . link
23testing "readlink -f link->dir" "readlink -f link" "$(pwd)\n" "" ""
24ln -snf link link
25testing "readlink link->link (recursive)" "readlink link" "link\n" "" ""
26testing "readlink -f link->link (recursive)" "readlink -f link || echo yes" \
27 "yes\n" "" ""
28rm file link
29
Rob Landleye25e8b52007-12-16 18:02:44 -060030# Make sure circular links don't run away.
31
Rob Landleyb4ed7622007-12-15 22:05:42 -060032ln -s link1 link2
33ln -s link2 link1
34testing "readlink follow recursive2" "readlink -f link1 || echo yes" \
35 "yes\n" "" ""
36rm link1 link2
Rob Landleye25e8b52007-12-16 18:02:44 -060037
38# Fun with relative paths
39
40ln -s /usr/include/sys/../sys newsys
41ln -s newsys newsys2
42testing "readlink maintains relative paths" "readlink newsys" \
43 "/usr/include/sys/../sys\n" "" ""
44testing "readlink -f resolves relative path" "readlink -f newsys2/../stdio.h" \
45 "/usr/include/stdio.h\n" "" ""
46rm newsys newsys2