tests: move input-tty into a test-lib.sh function
[platform/upstream/coreutils.git] / tests / test-lib.sh
index f386933..f0e1070 100644 (file)
@@ -57,6 +57,19 @@ require_strace_()
     skip_test_ 'strace -qe "'"$1"'" does not work'
 }
 
+# Require a controlling input `terminal'.
+require_controlling_input_terminal_()
+{
+  tty -s || have_input_tty=no
+  test -t 1 || have_input_tty=no
+  if test "$have_input_tty" = no; then
+    echo "$0: This test must have a controlling input \`terminal'," 1>&2
+    echo "  so it may not be run via \`batch', \`at', or \`rsh'." 1>&2
+    echo "  On some systems, it may not even be run in the background." 1>&2
+    (exit 77); exit 77
+  fi
+}
+
 require_built_()
 {
   skip_=no