logo

utils-std

Collection of commonly available Unix tools

tty (1147B)


  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 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' ../cmd/tty
  8. }
  9. atf_test_case in_devnull
  10. in_devnull_body() {
  11. atf_check -s 'exit:1' -o 'inline:not a tty\n' ../cmd/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 '../cmd/tty >/dev/null'
  17. }
  18. atf_test_case out_devfull
  19. out_devfull_body() {
  20. has_glibc && atf_skip "glibc ignoring write errors for puts()"
  21. [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()"
  22. [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()"
  23. atf_check -s "exit:2" sh -c '../cmd/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. }