logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

tee (2781B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017 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_skip "glibc ignoring write errors for fputs()"
  40. [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for fputs()"
  41. [ "$(uname -s)" = "FreeBSD" ] && atf_skip "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. }
  45. atf_test_case nullinput
  46. nullinput_body() {
  47. atf_check ../cmd/tee </dev/null
  48. }
  49. atf_test_case writeslash
  50. writeslash_body() {
  51. # shellcheck disable=SC1112
  52. atf_check -s exit:1 -e 'inline:tee: Error opening ‘./’: Is a directory\n' ../cmd/tee ./ <inputs/all_bytes
  53. }
  54. atf_test_case enoent
  55. enoent_body() {
  56. # shellcheck disable=SC1112
  57. 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
  58. }
  59. atf_test_case doubledash
  60. doubledash_body() {
  61. atf_check -o file:inputs/all_bytes -- ../cmd/tee -- <inputs/all_bytes
  62. #atf_check -s exit:1 -e 'inline:tee: Error opening ‘---’: No such file or directory\n' -o empty -- ../cmd/tee --- <inputs/all_bytes
  63. }
  64. atf_init_test_cases() {
  65. cd "$(atf_get_srcdir)" || exit 1
  66. . ../test_functions.sh
  67. atf_add_test_case allinput
  68. atf_add_test_case writefile
  69. atf_add_test_case appendfile
  70. atf_add_test_case noperm
  71. atf_add_test_case devfull
  72. atf_add_test_case nullinput
  73. atf_add_test_case writeslash
  74. atf_add_test_case enoent
  75. atf_add_test_case doubledash
  76. }