logo

utils-extra

Collection of extra tools for Unixes

xcd (2191B)


  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 openfile
  5. openfile_body() {
  6. atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd inputs/all_bytes
  7. }
  8. atf_test_case stdinput
  9. stdinput_body() {
  10. atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd <inputs/all_bytes
  11. atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd - <inputs/all_bytes
  12. }
  13. atf_test_case nullfile
  14. nullfile_body() {
  15. atf_check -o file:outputs/xcd/null ../cmd/xcd /dev/null
  16. }
  17. atf_test_case nullinput
  18. nullinput_body() {
  19. atf_check -o file:outputs/xcd/null ../cmd/xcd </dev/null
  20. }
  21. atf_test_case noperm cleanup
  22. noperm_body() {
  23. touch inputs/chmod_000 || atf_fail "touching chmod_000"
  24. chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
  25. # shellcheck disable=SC1112
  26. atf_check -s exit:1 -e 'inline:\nxcd: Error opening ‘inputs/chmod_000’: Permission denied\n' -o 'inline:' ../cmd/xcd inputs/chmod_000
  27. }
  28. noperm_cleanup() {
  29. chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
  30. rm inputs/chmod_000 || atf_fail "rm chmod_000"
  31. }
  32. atf_test_case devfull
  33. devfull_body() {
  34. has_glibc && atf_expect_fail "glibc ignoring write errors for printf()"
  35. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for printf()"
  36. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for printf()"
  37. # shellcheck disable=SC1112
  38. atf_check -s 'exit:1' -e 'inline:\nxcd: Write error: No space left on device\n\nxcd: Error closing ‘inputs/all_bytes’: No space left on device\n' sh -c '../cmd/xcd inputs/all_bytes >/dev/full'
  39. atf_check -s 'exit:1' -e 'inline:\nxcd: Write error: No space left on device\n' sh -c '../cmd/xcd <inputs/all_bytes >/dev/full'
  40. atf_check -s 'exit:1' -e 'inline:\nxcd: Write error: No space left on device\n' sh -c '../cmd/xcd - <inputs/all_bytes >/dev/full'
  41. }
  42. atf_init_test_cases() {
  43. cd "$(atf_get_srcdir)" || exit 1
  44. . ../test_functions.sh
  45. atf_add_test_case openfile
  46. atf_add_test_case stdinput
  47. atf_add_test_case nullfile
  48. atf_add_test_case nullinput
  49. atf_add_test_case noperm
  50. atf_add_test_case devfull
  51. }