aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2023-06-22 08:13:53 +1000
committerSteve Bennett <steveb@workware.net.au>2023-07-04 09:23:43 +1000
commit526541f90e865bc8598e59daa2b70c2181d5d5db (patch)
treefbb2b1e4b793ae195268fd7302be43d7c057239c
parentc25a2752e33601cb188dcefca521a8dc580b9dd6 (diff)
downloadjimtcl-526541f90e865bc8598e59daa2b70c2181d5d5db.zip
jimtcl-526541f90e865bc8598e59daa2b70c2181d5d5db.tar.gz
jimtcl-526541f90e865bc8598e59daa2b70c2181d5d5db.tar.bz2
tests: tty.test: use a pty pair if stdin/stdout is not a tty
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--tests/tty.test37
1 files 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
}
}