logo

utils

Old programs, got split in utils-std and utils-extra git clone https://hacktivis.me/git/utils.git

xcd (1915B)


  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. # shellcheck disable=SC1112
  35. atf_check -s 'exit:1' -e 'inline:\nxcd: Write error: No space left on device\n\nxcd: Error closing ‘inputs/strings/true’: No space left on device\n' sh -c '../cmd/xcd inputs/strings/true >/dev/full'
  36. atf_check -s 'exit:1' -e 'inline:\nxcd: Write error: No space left on device\n' sh -c '../cmd/xcd <inputs/strings/true >/dev/full'
  37. atf_check -s 'exit:1' -e 'inline:\nxcd: Write error: No space left on device\n' sh -c '../cmd/xcd - <inputs/strings/true >/dev/full'
  38. }
  39. atf_init_test_cases() {
  40. cd "$(atf_get_srcdir)" || exit 1
  41. atf_add_test_case openfile
  42. atf_add_test_case stdinput
  43. atf_add_test_case nullfile
  44. atf_add_test_case nullinput
  45. atf_add_test_case noperm
  46. atf_add_test_case devfull
  47. }