diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-03-19 16:12:00 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2024-03-19 16:12:00 (GMT) |
commit | 7208478d1c5c7ed65b3d0bdaced2740830f3859b (patch) | |
tree | eef639b380b170cca7cd66f4c51ec6ac69e1a03a /tests | |
parent | 20547771bb29c967bf3eb2c0d8b17df50ddb8950 (diff) | |
download | tcl-7208478d1c5c7ed65b3d0bdaced2740830f3859b.zip tcl-7208478d1c5c7ed65b3d0bdaced2740830f3859b.tar.gz tcl-7208478d1c5c7ed65b3d0bdaced2740830f3859b.tar.bz2 |
Backport fix for [bda99f2393]: gets stdin problem when non-blocking - Windows
(cherry-pick): Fix indentation/brace usage style issues
Diffstat (limited to 'tests')
-rw-r--r-- | tests/winConsole.test | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/tests/winConsole.test b/tests/winConsole.test index 3f23c07..166599f 100644 --- a/tests/winConsole.test +++ b/tests/winConsole.test @@ -4,7 +4,8 @@ # built-in commands. Sourcing this file into Tcl runs the tests and # generates output for errors. No output means no errors were found. # -# Copyright © 1999 Scriptics Corporation. +# NOTE THIS CANNOT BE RUN VIA nmake/make test since stdin is connected to +# nmake in that case. # # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -15,7 +16,6 @@ if {"::tcltest" ni [namespace children]} { } catch {package require twapi} ;# Only to bring window to foreground. Not critical - ::tcltest::ConstraintInitializer haveThread { expr {![catch {package require Thread}]} } # Prompt user for a yes/no response @@ -155,6 +155,54 @@ test console-input-2.1 {Console file channel: non-blocking read} -constraints { set result } -result abc +test console-input-3.0 {Console gets blocking - long lines bug-bda99f2393} -constraints { + win interactive +} -body { + prompt "Try typing a line of at least 256 characters. Hit ENTER exactly once unless you don't see another prompt.\n" + gets stdin line + set len [string length $line] + list [yesno "Did you hit ENTER only once?"] [expr {$len > 256}] [yesno "Line length was $len characters. Is this correct?"] +} -result {1 1 1} + +test console-input-3.1 {Console gets blocking, small channel buffer size - long lines bug-bda99f2393} -constraints { + win interactive +} -body { + prompt "Try typing a line of at least 256 characters. Hit ENTER exactly once unless you don't see another prompt.\n" + set bufSize [fconfigure stdin -buffersize] + fconfigure stdin -buffersize 10 + gets stdin line + fconfigure stdin -buffersize $bufSize + set len [string length $line] + list [yesno "Did you hit ENTER only once?"] [expr {$len > 256}] [yesno "Line length was $len characters. Is this correct?"] +} -result {1 1 1} + +test console-input-3.2 {Console gets nonblocking - long lines bug-bda99f2393} -constraints { + win interactive +} -body { + prompt "Try typing a line of at least 256 characters. Hit ENTER exactly once unless you don't see another prompt.\n" + fconfigure stdin -blocking 0 + while {[gets stdin line] < 0} { + after 1000 + } + fconfigure stdin -blocking 1 + set len [string length $line] + list [yesno "Did you hit ENTER only once?"] [expr {$len > 256}] [yesno "Line length was $len characters. Is this correct?"] +} -result {1 1 1} + +test console-input-3.3 {Console gets nonblocking small channel buffer size - long lines bug-bda99f2393} -constraints { + win interactive +} -body { + prompt "Try typing a line of at least 256 characters. Hit ENTER exactly once unless you don't see another prompt.\n" + set bufSize [fconfigure stdin -buffersize] + fconfigure stdin -blocking 0 -buffersize 10 + while {[gets stdin line] < 0} { + after 1000 + } + fconfigure stdin -blocking 1 -buffersize $bufSize + set len [string length $line] + list [yesno "Did you hit ENTER only once?"] [expr {$len > 256}] [yesno "Line length was $len characters. Is this correct?"] +} -result {1 1 1} + # Output tests test console-output-1.0 {Console blocking puts stdout} -constraints {win interactive} -body { @@ -344,7 +392,7 @@ test console-fconfigure-set-3.0 { fconfigure stderr -winsize } -constraints {win interactive} -body { fconfigure stderr -winsize {10 30} -} -result {bad option "-winsize": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, or -profile, -translation} -returnCodes error +} -result {bad option "-winsize": should be one of -blocking, -buffering, -buffersize, -encoding, -eofchar, -profile, or -translation} -returnCodes error # Multiple threads |