logo

utils

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

tee (3022B)


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