Rob Landley | c008c74 | 2006-05-05 21:07:41 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Readlink tests. |
| 4 | # Copyright 2006 by Natanael Copa <n@tanael.org> |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 5 | # Licensed under GPLv2, see file LICENSE in this source tree. |
Rob Landley | c008c74 | 2006-05-05 21:07:41 +0000 | [diff] [blame] | 6 | |
Mike Frysinger | caa7940 | 2009-11-04 18:41:22 -0500 | [diff] [blame] | 7 | . ./testing.sh |
Rob Landley | c008c74 | 2006-05-05 21:07:41 +0000 | [diff] [blame] | 8 | |
| 9 | TESTDIR=readlink_testdir |
| 10 | TESTFILE="$TESTDIR/testfile" |
| 11 | TESTLINK="testlink" |
| 12 | FAILLINK="$TESTDIR/$TESTDIR/testlink" |
| 13 | |
| 14 | # create the dir and test files |
| 15 | mkdir -p "./$TESTDIR" |
| 16 | touch "./$TESTFILE" |
| 17 | ln -s "./$TESTFILE" "./$TESTLINK" |
| 18 | |
| 19 | testing "readlink on a file" "readlink ./$TESTFILE" "" "" "" |
| 20 | testing "readlink on a link" "readlink ./$TESTLINK" "./$TESTFILE\n" "" "" |
Rob Landley | 42bd987 | 2006-05-05 22:22:30 +0000 | [diff] [blame] | 21 | |
| 22 | optional FEATURE_READLINK_FOLLOW |
| 23 | |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 24 | # shell's $PWD may leave symlinks unresolved. |
| 25 | # "pwd" may be a built-in and have the same problem. |
| 26 | # External pwd _can't_ have that problem (current dir on Unix is physical). |
| 27 | pwd=`which pwd` |
| 28 | pwd=`$pwd` |
| 29 | testing "readlink -f on a file" "readlink -f ./$TESTFILE" "$pwd/$TESTFILE\n" "" "" |
| 30 | testing "readlink -f on a link" "readlink -f ./$TESTLINK" "$pwd/$TESTFILE\n" "" "" |
Rob Landley | c008c74 | 2006-05-05 21:07:41 +0000 | [diff] [blame] | 31 | testing "readlink -f on an invalid link" "readlink -f ./$FAILLINK" "" "" "" |
Denys Vlasenko | 69c8c69 | 2015-10-11 16:27:55 +0200 | [diff] [blame] | 32 | testing "readlink -f on a wierd dir" "readlink -f $TESTDIR/../$TESTFILE" "$pwd/$TESTFILE\n" "" "" |
Rob Landley | c008c74 | 2006-05-05 21:07:41 +0000 | [diff] [blame] | 33 | |
| 34 | |
| 35 | # clean up |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 36 | rm -r "$TESTLINK" "$TESTDIR" |
Dan Fandrich | 140ac91 | 2010-08-29 04:47:03 +0200 | [diff] [blame] | 37 | |
| 38 | exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255)) |