logo

utils-extra

Collection of extra tools for Unixes git clone https://anongit.hacktivis.me/git/utils-extra.git/

pat (2611B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017-2022 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:outputs/pat/all_bytes ../cmd/pat outputs/pat/all_bytes
  7. }
  8. atf_test_case allinput
  9. allinput_body() {
  10. atf_check -o file:outputs/pat/all_bytes ../cmd/pat <outputs/pat/all_bytes
  11. }
  12. atf_test_case alldashinput
  13. alldashinput_body() {
  14. atf_check -o file:outputs/pat/all_bytes ../cmd/pat - <outputs/pat/all_bytes
  15. }
  16. atf_test_case devnull
  17. devnull_body() {
  18. atf_check ../cmd/pat /dev/null
  19. atf_check ../cmd/pat </dev/null
  20. atf_check ../cmd/pat - </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:pat: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/pat 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:pat: Error writing: No space left on device\n' sh -c '../cmd/pat outputs/pat/all_bytes >/dev/full'
  36. atf_check -s exit:1 -e 'inline:pat: Error writing: No space left on device\n' sh -c '../cmd/pat <outputs/pat/all_bytes >/dev/full'
  37. atf_check -s exit:1 -e 'inline:pat: Error writing: No space left on device\n' sh -c '../cmd/pat - <outputs/pat/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:pat: Error reading ‘/’: Is a directory\n' ../cmd/pat /
  44. }
  45. atf_test_case enoent
  46. enoent_body() {
  47. # shellcheck disable=SC1112
  48. atf_check -s exit:1 -e 'inline:pat: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/pat /var/empty/e/no/ent
  49. }
  50. atf_test_case doubledash
  51. doubledash_body() {
  52. atf_check -o file:outputs/pat/all_bytes -- ../cmd/pat -- outputs/pat/all_bytes
  53. # shellcheck disable=SC1112
  54. atf_check -s exit:1 -e 'inline:pat: Error opening ‘---’: No such file or directory\n' -o empty -- ../cmd/pat --- outputs/pat/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. }