logo

utils-std

Collection of commonly available Unix tools

cat (2557B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. atf_test_case allfile
  5. allfile_body() {
  6. atf_check -o file:inputs/all_bytes ../cmd/cat inputs/all_bytes
  7. }
  8. atf_test_case allinput
  9. allinput_body() {
  10. atf_check -o file:inputs/all_bytes ../cmd/cat <inputs/all_bytes
  11. }
  12. atf_test_case alldashinput
  13. alldashinput_body() {
  14. atf_check -o file:inputs/all_bytes ../cmd/cat - <inputs/all_bytes
  15. }
  16. atf_test_case devnull
  17. devnull_body() {
  18. atf_check ../cmd/cat /dev/null
  19. atf_check ../cmd/cat </dev/null
  20. atf_check ../cmd/cat - </dev/null
  21. }
  22. atf_test_case noperm cleanup
  23. noperm_body() {
  24. touch inputs/chmod_000 || atf_fail "touching chmod_000"
  25. chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
  26. # shellcheck disable=SC1112
  27. atf_check -s exit:1 -e 'inline:cat: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/cat inputs/chmod_000
  28. }
  29. noperm_cleanup() {
  30. chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
  31. rm inputs/chmod_000 || atf_fail "rm chmod_000"
  32. }
  33. atf_test_case devfull
  34. devfull_body() {
  35. 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'
  36. 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'
  37. 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'
  38. }
  39. atf_test_case readslash
  40. readslash_body() {
  41. [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD allows to read directories"
  42. # shellcheck disable=SC1112
  43. atf_check -s exit:1 -e 'inline:cat: Error reading ‘/’: Is a directory\n' ../cmd/cat /
  44. }
  45. atf_test_case enoent
  46. enoent_body() {
  47. # shellcheck disable=SC1112
  48. atf_check -s exit:1 -e 'inline:cat: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/cat /var/empty/e/no/ent
  49. }
  50. atf_test_case doubledash
  51. doubledash_body() {
  52. atf_check -o file:inputs/all_bytes -- ../cmd/cat -- inputs/all_bytes
  53. # shellcheck disable=SC1112
  54. atf_check -s exit:1 -e "inline:cat: Error: Unrecognised option: '--'\nUsage: cat [-u] [files ...]\n" -o empty -- ../cmd/cat --- inputs/all_bytes
  55. }
  56. atf_init_test_cases() {
  57. cd "$(atf_get_srcdir)" || exit 1
  58. atf_add_test_case allfile
  59. atf_add_test_case allinput
  60. atf_add_test_case alldashinput
  61. atf_add_test_case devnull
  62. atf_add_test_case noperm
  63. atf_add_test_case devfull
  64. atf_add_test_case readslash
  65. atf_add_test_case enoent
  66. atf_add_test_case doubledash
  67. }