1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
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, vstart, vstop, 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
|