realpath.tests 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # Realpath tests.
  3. # Copyright 2006 by Natanael Copa <n@tanael.org>
  4. # Copyright 2021 by Ron Yorston <rmy@pobox.com>
  5. # Licensed under GPLv2, see file LICENSE in this source tree.
  6. . ./testing.sh
  7. unset LC_ALL
  8. unset LC_MESSAGES
  9. unset LANG
  10. unset LANGUAGE
  11. TESTDIR=realpath_testdir
  12. TESTLINK1="link1"
  13. TESTLINK2="link2"
  14. # create the dir and test files
  15. mkdir -p "./$TESTDIR"
  16. ln -s "./$TESTDIR/not_file" "./$TESTLINK1"
  17. ln -s "./$TESTDIR/not_file/not_dir" "./$TESTLINK2"
  18. # shell's $PWD may leave symlinks unresolved.
  19. # "pwd" may be a built-in and have the same problem.
  20. # External pwd _can't_ have that problem (current dir on Unix is physical).
  21. pwd=`which pwd`
  22. pwd=`$pwd`
  23. testing "realpath on non-existent absolute path 1" "realpath /not_file" "/not_file\n" "" ""
  24. testing "realpath on non-existent absolute path 2" "realpath /not_file/" "/not_file\n" "" ""
  25. testing "realpath on non-existent absolute path 3" "realpath //not_file" "/not_file\n" "" ""
  26. testing "realpath on non-existent absolute path 4" "realpath /not_dir/not_file 2>&1" "realpath: /not_dir/not_file: No such file or directory\n" "" ""
  27. testing "realpath on non-existent local file 1" "realpath $TESTDIR/not_file" "$pwd/$TESTDIR/not_file\n" "" ""
  28. testing "realpath on non-existent local file 2" "realpath $TESTDIR/not_dir/not_file 2>&1" "realpath: $TESTDIR/not_dir/not_file: No such file or directory\n" "" ""
  29. testing "realpath on link to non-existent file 1" "realpath $TESTLINK1" "$pwd/$TESTDIR/not_file\n" "" ""
  30. testing "realpath on link to non-existent file 2" "realpath $TESTLINK2 2>&1" "realpath: $TESTLINK2: No such file or directory\n" "" ""
  31. testing "realpath on link to non-existent file 3" "realpath ./$TESTLINK1" "$pwd/$TESTDIR/not_file\n" "" ""
  32. testing "realpath on link to non-existent file 4" "realpath ./$TESTLINK2 2>&1" "realpath: ./$TESTLINK2: No such file or directory\n" "" ""
  33. # clean up
  34. rm -r "$TESTLINK1" "$TESTLINK2" "$TESTDIR"
  35. exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255))