source [file dirname [info script]]/testing.tcl 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 [$chan tty] dict exists $dict output } 1 test tty-1.2 {tty bad param} -body { $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 { $chan tty baud 12345 } -returnCodes error -result {bad value for baud: 12345} test tty-1.4 {tty bad fd} -body { set f [open [file tempfile] w] $f tty } -returnCodes error -match regexp -result {^(Inappropriate ioctl for device|Not a tty)$} -cleanup { $f close } set n 0 foreach {param value} { output raw input raw handshake rtscts } { test tty-1.[incr n] "tty setting $param" -setup { set savetty [$chan tty] } -body "$chan tty $param $value; dict get \[$chan tty\] $param" \ -result $value -cleanup { $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 [$chan tty] } -body "$chan tty $param bad" \ -returnCodes error -result "bad value for $param: bad" -cleanup { $chan tty $savetty } } testreport