view scripts/test/readlink.test @ 668:0ee40175a307

Fix catv to display byte 255 correctly. (It's both M- and ^?.)
author Rob Landley <rob@landley.net>
date Sat, 06 Oct 2012 01:54:24 -0500
parents 98d1fc53b1c4
children 0027cfa330da
line wrap: on
line source

#!/bin/bash

[ -f testing.sh ] && . testing.sh

#testing "name" "command" "result" "infile" "stdin"

testing "readlink missing" "readlink notfound || echo yes" "yes\n" "" ""

# simple tests on a file

touch file
testing "readlink file" "readlink file || echo yes" "yes\n" "" ""
testing "readlink -f dir" "readlink -f ." "$(pwd)\n" "" ""
testing "readlink -f missing" "readlink -f notfound" "$(pwd)/notfound\n" "" ""

# Test a link that points to nonexistent file
ln -s notfound link
testing "readlink link" "readlink link" "notfound\n" "" ""
testing "readlink link->missing" "readlink -f link" "$(pwd)/notfound\n" "" ""
ln -sf file link
testing "readlink -f link->file" "readlink -f link" "$(pwd)/file\n" "" ""
ln -sf . link
testing "readlink -f link->dir" "readlink -f link" "$(pwd)\n" "" ""
ln -snf link link
testing "readlink link->link (recursive)" "readlink link" "link\n" "" ""
testing "readlink -f link->link (recursive)" "readlink -f link || echo yes" \
	"yes\n" "" ""
rm file link

# Make sure circular links don't run away.

ln -s link1 link2
ln -s link2 link1
testing "readlink follow recursive2" "readlink -f link1 || echo yes" \
	"yes\n" "" ""
rm link1 link2

# Fun with relative paths

ln -s /usr/include/sys/../sys newsys
ln -s newsys newsys2
testing "readlink maintains relative paths" "readlink newsys" \
	"/usr/include/sys/../sys\n" "" ""
testing "readlink -f resolves relative path" "readlink -f newsys2/../stdio.h" \
	"/usr/include/stdio.h\n" "" ""
rm newsys newsys2