From 526541f90e865bc8598e59daa2b70c2181d5d5db Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Thu, 22 Jun 2023 08:13:53 +1000 Subject: tests: tty.test: use a pty pair if stdin/stdout is not a tty Signed-off-by: Steve Bennett --- tests/tty.test | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/tests/tty.test b/tests/tty.test index 5199e6a..104683f 100644 --- a/tests/tty.test +++ b/tests/tty.test @@ -1,21 +1,34 @@ source [file dirname [info script]]/testing.tcl -needs cmd {stdout tty} -if {![stdout isatty]} { - skiptest " (aio tty)" +needs cmd {stdin tty} +needs cmd {stdin isatty} + +if {[stdin isatty]} { + set chan stdin +} else { + # If stdin isn't a tty, try to create a pty pair + if {[catch { + lassign [socket pty] chan schan + }]} { + skiptest " (socket pty)" + } + defer { + $chan close + $schan close + } } test tty-1.1 {tty status} { - set dict [stdout tty] + set dict [$chan tty] dict exists $dict output } 1 test tty-1.2 {tty bad param} -body { - stdout tty bad value + $chan tty bad value } -returnCodes error -result {bad setting "bad": must be baud, data, echo, handshake, input, output, parity, stop, vmin, or vtime} test tty-1.3 {tty bad baud} -body { - stdout tty baud 12345 + $chan tty baud 12345 } -returnCodes error -result {bad value for baud: 12345} test tty-1.4 {tty bad fd} -body { @@ -33,20 +46,20 @@ foreach {param value} { handshake rtscts } { test tty-1.[incr n] "tty setting $param" -setup { - set savetty [stdout tty] - } -body "stdout tty $param $value; dict get \[stdout tty\] $param" \ + set savetty [$chan tty] + } -body "$chan tty $param $value; dict get \[$chan tty\] $param" \ -result $value -cleanup { - stdout tty $savetty + $chan tty $savetty } } set n 0 foreach param {output input handshake baud stop data vmin vtime} { test tty-2.[incr n] "tty bad setting $param" -setup { - set savetty [stdout tty] - } -body "stdout tty $param bad" \ + set savetty [$chan tty] + } -body "$chan tty $param bad" \ -returnCodes error -result "bad value for $param: bad" -cleanup { - stdout tty $savetty + $chan tty $savetty } } -- cgit v1.1