logo

utils

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

tty (1194B)


  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 basic
  5. basic_body() {
  6. tty >/dev/null || atf_expect_fail "test environment not in a tty"
  7. atf_check -o 'not-inline:not a tty\n' ../bin/tty
  8. }
  9. atf_test_case in_devnull
  10. in_devnull_body() {
  11. atf_check -s 'exit:1' -o 'inline:not a tty\n' ../bin/tty </dev/null
  12. }
  13. atf_test_case out_devnull
  14. out_devnull_body() {
  15. tty >/dev/null || atf_expect_fail "test environment not in a tty"
  16. atf_check -o 'not-inline:not a tty\n' sh -c '../bin/tty >/dev/null'
  17. }
  18. atf_test_case out_devfull
  19. out_devfull_body() {
  20. has_glibc && atf_expect_fail "glibc ignoring write errors for puts()"
  21. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
  22. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
  23. atf_check -s "exit:2" sh -c '../bin/tty >/dev/full'
  24. }
  25. atf_init_test_cases() {
  26. cd "$(atf_get_srcdir)" || exit 1
  27. . ../test_functions.sh
  28. atf_add_test_case basic
  29. atf_add_test_case in_devnull
  30. atf_add_test_case out_devnull
  31. atf_add_test_case out_devfull
  32. }