t / lib-terminal.shon commit test_terminal: catch use without TTY prerequisite (996621e)
   1#!/bin/sh
   2
   3test_expect_success 'set up terminal for tests' '
   4        if test -t 1 && test -t 2
   5        then
   6                >have_tty
   7        elif
   8                test_have_prereq PERL &&
   9                "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \
  10                        sh -c "test -t 1 && test -t 2"
  11        then
  12                >test_terminal_works
  13        fi
  14'
  15
  16if test -e have_tty
  17then
  18        test_terminal_() { "$@"; }
  19        test_set_prereq TTY
  20elif test -e test_terminal_works
  21then
  22        test_terminal_() {
  23                "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@"
  24        }
  25        test_set_prereq TTY
  26else
  27        say "# no usable terminal, so skipping some tests"
  28fi
  29
  30test_terminal () {
  31        if ! test_declared_prereq TTY
  32        then
  33                echo >&2 'test_terminal: need to declare TTY prerequisite'
  34                return 127
  35        fi
  36        test_terminal_ "$@"
  37}