logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

realpath.sh (2977B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. target="$(dirname "$0")/../cmd/realpath"
  5. plans=31
  6. . "$(dirname "$0")/tap.sh"
  7. t . '.' "${PWD}
  8. "
  9. t / / '/
  10. '
  11. t /var /var '/var
  12. '
  13. t /var/empty /var/empty '/var/empty
  14. '
  15. t --exit=1 /var/empty/foo/bar /var/empty/foo/bar 'realpath: error: Failed canonilizing parent of full path "/var/empty/foo/bar": No such file or directory
  16. '
  17. t --exit=1 /var/empty/foo/bar/ /var/empty/foo/bar/ 'realpath: error: Failed canonilizing parent of full path "/var/empty/foo/bar": No such file or directory
  18. '
  19. t --exit=1 /var/empty/foo/bar// /var/empty/foo/bar// 'realpath: error: Failed canonilizing parent of full path "/var/empty/foo/bar": No such file or directory
  20. '
  21. t e:/ '-e /' '/
  22. '
  23. t e:/var '-e /var' '/var
  24. '
  25. t --exit=1 e:/var/empty/foo '-e /var/empty/foo' 'realpath: error: Failed canonilizing "/var/empty/foo": No such file or directory
  26. '
  27. t --exit=1 e:/var/empty/foo/ '-e /var/empty/foo/' 'realpath: error: Failed canonilizing "/var/empty/foo/": No such file or directory
  28. '
  29. t --exit=1 e:/var/empty/foo// '-e /var/empty/foo//' 'realpath: error: Failed canonilizing "/var/empty/foo//": No such file or directory
  30. '
  31. t --exit=1 e:/var/empty/foo/bar '-e /var/empty/foo/bar' 'realpath: error: Failed canonilizing "/var/empty/foo/bar": No such file or directory
  32. '
  33. t --exit=1 e:/var/empty/foo/bar/ '-e /var/empty/foo/bar/' 'realpath: error: Failed canonilizing "/var/empty/foo/bar/": No such file or directory
  34. '
  35. t --exit=1 e:/var/empty/foo/bar// '-e /var/empty/foo/bar//' 'realpath: error: Failed canonilizing "/var/empty/foo/bar//": No such file or directory
  36. '
  37. # Non-directory
  38. t /dev/null /dev/null '/dev/null
  39. '
  40. t e:/dev/null '-e /dev/null' '/dev/null
  41. '
  42. t E:/dev/null '-E /dev/null' '/dev/null
  43. '
  44. t --exit=1 /dev/null/ /dev/null/ 'realpath: error: Failed canonilizing "/dev/null/": Not a directory
  45. '
  46. t --exit=1 e:/dev/null/ '-e /dev/null/' 'realpath: error: Failed canonilizing "/dev/null/": Not a directory
  47. '
  48. t --exit=1 E:/dev/null/ '-E /dev/null/' 'realpath: error: Failed canonilizing "/dev/null/": Not a directory
  49. '
  50. t --exit=1 /dev/null/.. /dev/null/.. 'realpath: error: Failed canonilizing "/dev/null/..": Not a directory
  51. '
  52. t --exit=1 e:/dev/null/.. '-e /dev/null/..' 'realpath: error: Failed canonilizing "/dev/null/..": Not a directory
  53. '
  54. t --exit=1 E:/dev/null/.. '-E /dev/null/..' 'realpath: error: Failed canonilizing "/dev/null/..": Not a directory
  55. '
  56. # Zero-separation
  57. # t z:/dev/null_/var/empty '-z /dev/null /var/empty' $'/dev/null\0/var/empty\0'
  58. # No final newline
  59. t n:/dev/null_/var/empty '-n /dev/null /var/empty' '/dev/null
  60. /var/empty'
  61. # As required by POSIX.1-2024 -E and -e aren't erroneous
  62. t Ee:/dev/null '-E -e /dev/null' '/dev/null
  63. '
  64. t s:foo '-s foo' "$PWD/foo
  65. "
  66. t s:foo/bar '-s foo/bar' "$PWD/foo/bar
  67. "
  68. t s:./foo/bar '-s ./foo/bar' "$PWD/foo/bar
  69. "
  70. t s:/foo/bar '-s /foo/bar' "/foo/bar
  71. "
  72. t s:/foo/del/../bar '-s /foo/del/../bar' "/foo/bar
  73. "