logo

utils-std

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

pwd.sh (814B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. WD="$(dirname "$0")"
  5. target="$(realpath "$WD/../cmd/pwd")"
  6. plans=6
  7. . "$(dirname "$0")/tap.sh"
  8. t noargs '' "${PWD?}
  9. "
  10. t --exit=1 usage '-H' "pwd: error: Unrecognised option '-H'
  11. Usage: pwd [-L|-P]
  12. "
  13. oldpwd=$PWD
  14. PWD=/$PWD t 'PWD=/$PWD' '' "/${oldpwd}
  15. "
  16. PWD=//foo t 'PWD=//foo' '' "${oldpwd}
  17. "
  18. PWD=foo t PWD=foo '' "${oldpwd}
  19. "
  20. PWD=$oldpwd
  21. if command -v mktemp >/dev/null 2>/dev/null
  22. then
  23. tmpdir="$(mktemp -d)" || exit 1
  24. test -d "$tmpdir" || exit 1
  25. oldpwd="$PWD"
  26. cd "$tmpdir" || exit 1
  27. (
  28. cd "$oldpwd" || exit 1
  29. rm -r "$tmpdir" || exit 1
  30. )
  31. t --exit=1 enoent '' 'pwd: error: getcwd: No such file or directory
  32. '
  33. cd "$oldpwd"
  34. else
  35. skip enoent 'requires mktemp(1)'
  36. fi