realpath.test 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. TOP="$(readlink -f .)"
  5. testcmd '' '.' "$TOP\n" '' ''
  6. #testcmd '-z' '-z . | tr "\0" X' "${TOP}X" '' ''
  7. touch file
  8. testcmd 'file' 'file' "$TOP/file\n" '' ''
  9. mkdir -p one/two/three
  10. testcmd 'dir' 'one/two/three' "$TOP/one/two/three\n" '' ''
  11. #testcmd '--relative-to' '. --relative-to=one/two/three' '../../..\n' '' ''
  12. #testcmd '--relative-base' 'one one/two one/two/three --relative-base=one/two' \
  13. # "$TOP/one\n.\nthree\n" '' ''
  14. #testcmd '--relative-base stomps --relative-to' \
  15. # '--relative-to=.. --relative-base=one/two one' "$TOP/one\n" '' ''
  16. testcmd 'missing defaults to -m' 'missing' "$TOP/missing\n" '' ''
  17. testcmd 'missing -e' '-e missing 2>/dev/null || echo ok' 'ok\n' '' ''
  18. # The -s tests use $PWD instead of $TOP because symlinks in path _to_ here
  19. # should not be resolved either. The shell exports $PWD: use it.
  20. ln -s ./one uno
  21. #testcmd '-s' '-s uno/two' "$PWD/uno/two\n" '' ''
  22. ln -s one/two dos
  23. #testcmd '-s link/..' '-es dos/three' "$PWD/dos/three\n" '' ''
  24. #testcmd '-s .. eats symlink' '-s dos/..' "$PWD\n" '' ''
  25. # In toybox this test is consistent with the previous one
  26. #toyonly testing '-s .. eats symlink in $PWD' \
  27. # 'cd dos && realpath -s ..' "$PWD\n" '' ''
  28. # Logically -es means the _symlink_ should exist, but match behavior...
  29. ln -s missing dangling
  30. #testcmd '-es dangling symlink' '-es dangling 2>/dev/null || echo ok' \
  31. # 'ok\n' '' ''
  32. #testcmd '-ms' '-ms dangling/../dos/../one/two' "$PWD/one/two\n" '' ''
  33. ln -s ../two/.. one/two/ichi
  34. #testcmd '-es' '-es one/two/ichi/two/ichi/two' "$PWD/one/two/ichi/two/ichi/two\n" '' ''