logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

tee (2980B)


  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 allinput
  5. allinput_body() {
  6. atf_check -o file:inputs/all_bytes ../cmd/tee <inputs/all_bytes
  7. }
  8. atf_test_case writefile cleanup
  9. writefile_body() {
  10. echo 'hello' > tmp_tee.log
  11. atf_check -o file:inputs/all_bytes ../cmd/tee tmp_tee.log <inputs/all_bytes
  12. atf_check -o empty -s exit:1 grep hello tmp_tee.log
  13. }
  14. writefile_cleanup() {
  15. rm tmp_tee.log
  16. }
  17. atf_test_case appendfile cleanup
  18. appendfile_body() {
  19. echo 'hello' > tmp_tee.log
  20. atf_check -o file:inputs/all_bytes ../cmd/tee -a tmp_tee.log <inputs/all_bytes
  21. atf_check -o file:outputs/tee/hello_all_bytes cat tmp_tee.log
  22. }
  23. appendfile_cleanup() {
  24. rm tmp_tee.log
  25. }
  26. atf_test_case noperm cleanup
  27. noperm_body() {
  28. touch inputs/chmod_000 || atf_fail "touching chmod_000"
  29. chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
  30. # shellcheck disable=SC1112
  31. atf_check -s exit:1 -e 'inline:tee: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/tee inputs/chmod_000 </dev/null
  32. }
  33. noperm_cleanup() {
  34. chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
  35. rm inputs/chmod_000 || atf_fail "rm chmod_000"
  36. }
  37. atf_test_case devfull
  38. devfull_body() {
  39. has_glibc && atf_expect_fail "glibc ignoring write errors for fputs()"
  40. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for fputs()"
  41. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for fputs()"
  42. # shellcheck disable=SC1112
  43. atf_check -s exit:1 -e 'inline:tee: Error writing ‘<stdout>’: No space left on device\n' sh -c '../cmd/tee <inputs/all_bytes >/dev/full'
  44. # shellcheck disable=SC1112
  45. atf_check -s exit:1 -e 'inline:tee: Error writing ‘<stdout>’: No space left on device\n' sh -c '../cmd/tee - <inputs/all_bytes >/dev/full'
  46. }
  47. atf_test_case nullinput
  48. nullinput_body() {
  49. atf_check ../cmd/tee </dev/null
  50. }
  51. atf_test_case writeslash
  52. writeslash_body() {
  53. # shellcheck disable=SC1112
  54. atf_check -s exit:1 -e 'inline:tee: Error opening ‘./’: Is a directory\n' ../cmd/tee ./ <inputs/all_bytes
  55. }
  56. atf_test_case enoent
  57. enoent_body() {
  58. # shellcheck disable=SC1112
  59. atf_check -s exit:1 -e 'inline:tee: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/tee /var/empty/e/no/ent <inputs/all_bytes
  60. }
  61. atf_test_case doubledash
  62. doubledash_body() {
  63. atf_check -o file:inputs/all_bytes -- ../cmd/tee -- <inputs/all_bytes
  64. #atf_check -s exit:1 -e 'inline:tee: Error opening ‘---’: No such file or directory\n' -o empty -- ../cmd/tee --- <inputs/all_bytes
  65. }
  66. atf_init_test_cases() {
  67. cd "$(atf_get_srcdir)" || exit 1
  68. . ../test_functions.sh
  69. atf_add_test_case allinput
  70. atf_add_test_case writefile
  71. atf_add_test_case appendfile
  72. atf_add_test_case noperm
  73. atf_add_test_case devfull
  74. atf_add_test_case nullinput
  75. atf_add_test_case writeslash
  76. atf_add_test_case enoent
  77. atf_add_test_case doubledash
  78. }