logo

utils-std

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

pathchk.sh (2342B)


  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="${WD}/cmd/pathchk"
  6. plans=13
  7. . "${WD}/test-cmd/tap.sh"
  8. # Thanks glibc for the broken getconf
  9. POSIX_NAME_MAX=$(getconf _POSIX_NAME_MAX 2>/dev/null || echo 14)
  10. POSIX_PATH_MAX=$(getconf _POSIX_PATH_MAX 2>/dev/null || echo 256)
  11. # Get NAME_MAX and PATH_MAX from <limits.h> (getconf doesn't always matches, such as on NetBSD)
  12. if ! test -f "${WD}/test-cmd/pathchk-getlimits"; then
  13. echo "${WD}/test-cmd/pathchk-getlimits: Is missing, did you use make?"
  14. exit 1
  15. fi
  16. export $("${WD}/test-cmd/pathchk-getlimits")
  17. echo "# NAME_MAX: ${NAME_MAX?}"
  18. echo "# PATH_MAX: ${PATH_MAX?}"
  19. name_max_str=$(printf "%*s" "${NAME_MAX}" | tr ' ' _)
  20. t name_max:ok "foo/${name_max_str}/bar"
  21. t --exit=1 name_max:xfail "foo/s${name_max_str}/bar" "pathchk: error: Path component ($(( ${NAME_MAX} + 1 )) octets) is over the maximum size (${NAME_MAX} octets): s${name_max_str}
  22. "
  23. posix_name_max_str=$(printf "%*s" "${POSIX_NAME_MAX}" | tr ' ' _)
  24. t posix_name_max:ok "-p foo/${posix_name_max_str}/bar"
  25. t --exit=1 posix_name_max:xfail "-p foo/s${posix_name_max_str}/bar" "pathchk: error: Path component ($(( ${POSIX_NAME_MAX} + 1 )) octets) is over the maximum size (${POSIX_NAME_MAX} octets): s${posix_name_max_str}
  26. "
  27. path_max_str=$(printf "%*s" "$(( ${PATH_MAX} - 1 ))" | tr ' ' /)
  28. t path_max:ok "${path_max_str}"
  29. t --exit=1 path_max:xfail "s${path_max_str}" "pathchk: error: Path (${PATH_MAX} octets) is over the maximum size ($(( ${PATH_MAX} - 1 )) octets): s${path_max_str}
  30. "
  31. posix_path_max_str=$(printf "%*s" "$(( ${POSIX_PATH_MAX} - 1 ))" | tr ' ' /)
  32. t posix_path_max:ok "-p ${posix_path_max_str}"
  33. t --exit=1 posix_path_max:xfail "-p s${posix_path_max_str}" "pathchk: error: Path (${POSIX_PATH_MAX} octets) is over the maximum size ($(( ${POSIX_PATH_MAX} - 1 )) octets): s${posix_path_max_str}
  34. "
  35. t enoent /dev/null/foo
  36. t noparent /../foo
  37. t --exit=1 hyphen '-P ./-foo' 'pathchk: error: Path component starts with an hyphen: -foo
  38. '
  39. t --exit=1 hyphen_subdir '-P ./bar/-foo' 'pathchk: error: Path component starts with an hyphen: -foo
  40. '
  41. zero_two="$(printf '\02')"
  42. t --exit=1 posix_charset "-p foo${zero_two}bar" "pathchk: error: Non-portable character '${zero_two}' (0x02) found in: foo${zero_two}bar
  43. "