logo

utils-std

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

cat.sh (1621B)


  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/cat"
  6. plans=10
  7. . "$(dirname "$0")/tap.sh"
  8. t --input='' noargs '' ''
  9. t --input='foo' stdin '' 'foo'
  10. t --input='foo' stdin_dash '-' 'foo'
  11. t devnull '/dev/null' ''
  12. t_file all_bytes "$WD/inputs/all_bytes" "$WD/inputs/all_bytes"
  13. if [ "$(id -u)" = 0 ]
  14. then
  15. skip noperm 'needs to be run unprivileged'
  16. else
  17. touch "$WD/inputs/chmod_000"
  18. chmod 0000 "$WD/inputs/chmod_000"
  19. t --exit=1 'noperm' "$WD/inputs/chmod_000" "cat: Error opening ‘$WD/inputs/chmod_000’: Permission denied
  20. "
  21. chmod 0600 "$WD/inputs/chmod_000"
  22. rm "$WD/inputs/chmod_000"
  23. fi
  24. #atf_test_case devfull
  25. #devfull_body() {
  26. # atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat inputs/all_bytes >/dev/full'
  27. # atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat <inputs/all_bytes >/dev/full'
  28. # atf_check -s exit:1 -e 'inline:cat: Error writing: No space left on device\n' sh -c '../cmd/cat - <inputs/all_bytes >/dev/full'
  29. #}
  30. if [ "$(uname -s)" = "NetBSD" ]; then
  31. skip readslash "NetBSD allows to read directories"
  32. else
  33. t --exit=1 readslash / 'cat: Error reading ‘/’: Is a directory
  34. '
  35. fi
  36. t --exit=1 enoent /var/empty/e/no/ent 'cat: Error opening ‘/var/empty/e/no/ent’: No such file or directory
  37. '
  38. t_file doubledash "$WD/inputs/all_bytes" -- "$WD/inputs/all_bytes"
  39. t --exit=1 tripledash "--- $WD/inputs/all_bytes" "cat: Error: Unrecognised option: '--'
  40. Usage: cat [-u] [files ...]
  41. "