readlink.tests 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. # Readlink tests.
  3. # Copyright 2006 by Natanael Copa <n@tanael.org>
  4. # Licensed under GPLv2, see file LICENSE in this source tree.
  5. . ./testing.sh
  6. TESTDIR=readlink_testdir
  7. TESTFILE="$TESTDIR/testfile"
  8. TESTLINK="testlink"
  9. FAILLINK="$TESTDIR/$TESTDIR/testlink"
  10. # create the dir and test files
  11. mkdir -p "./$TESTDIR"
  12. touch "./$TESTFILE"
  13. ln -s "./$TESTFILE" "./$TESTLINK"
  14. testing "readlink on a file" "readlink ./$TESTFILE" "" "" ""
  15. testing "readlink on a link" "readlink ./$TESTLINK" "./$TESTFILE\n" "" ""
  16. optional FEATURE_READLINK_FOLLOW
  17. # shell's $PWD may leave symlinks unresolved.
  18. # "pwd" may be a built-in and have the same problem.
  19. # External pwd _can't_ have that problem (current dir on Unix is physical).
  20. pwd=`which pwd`
  21. pwd=`$pwd`
  22. testing "readlink -f on a file" "readlink -f ./$TESTFILE" "$pwd/$TESTFILE\n" "" ""
  23. testing "readlink -f on a link" "readlink -f ./$TESTLINK" "$pwd/$TESTFILE\n" "" ""
  24. testing "readlink -f on an invalid link" "readlink -f ./$FAILLINK" "" "" ""
  25. testing "readlink -f on a wierd dir" "readlink -f $TESTDIR/../$TESTFILE" "$pwd/$TESTFILE\n" "" ""
  26. # clean up
  27. rm -r "$TESTLINK" "$TESTDIR"
  28. exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255))