36 lines
527 B
Bash
Executable File
36 lines
527 B
Bash
Executable File
#!/bin/sh
|
|
bin=$PWD/realpath.sh
|
|
dir="$(mktemp -d)"
|
|
cd "$dir"
|
|
|
|
do_test() {
|
|
name=$dir/$2
|
|
target=$3
|
|
case "$name" in
|
|
*/*) mkdir -p "${name%/*}";;
|
|
esac
|
|
|
|
ln -s "$target" "$name"
|
|
|
|
is=$($bin "$name")
|
|
|
|
should=$(readlink -f "$name")
|
|
|
|
if [ "$is" == "$should" ]; then
|
|
echo "Test $1 success"
|
|
else
|
|
echo "Test $1 fail: \"${bin##*/} $name\" returned \"$is\" instead of \"$should\""
|
|
stat "$name"
|
|
fi
|
|
rm -r "$name"
|
|
}
|
|
|
|
touch t
|
|
|
|
do_test 1 a /bin
|
|
do_test 2 a/b .
|
|
do_test 3 a/b ..
|
|
do_test 4 a/b ../t
|
|
|
|
rm -rf "$dir"
|