summaryrefslogtreecommitdiffstats
path: root/tests/winConsole.test
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2022-07-01 05:58:13 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2022-07-01 05:58:13 (GMT)
commit6d20feb2f0e199aedc0ff2812f4e38336bdca915 (patch)
tree2f48bef10723f12cd9f919bdb2b3bfc97423664a /tests/winConsole.test
parent539282ee0ffe1772db9e3f27c1baaaa47851ea02 (diff)
parent83253ae734a523f4c548f386cc890d065d6d3d1e (diff)
downloadtcl-6d20feb2f0e199aedc0ff2812f4e38336bdca915.zip
tcl-6d20feb2f0e199aedc0ff2812f4e38336bdca915.tar.gz
tcl-6d20feb2f0e199aedc0ff2812f4e38336bdca915.tar.bz2
Merge core-8-branch. Wakeup console reader thread when data read.
Diffstat (limited to 'tests/winConsole.test')
-rw-r--r--tests/winConsole.test38
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/winConsole.test b/tests/winConsole.test
index 8ca1457..795e16d 100644
--- a/tests/winConsole.test
+++ b/tests/winConsole.test
@@ -14,6 +14,39 @@ if {"::tcltest" ni [namespace children]} {
namespace import -force ::tcltest::*
}
+::tcltest::ConstraintInitializer twapi { expr {![catch {package require twapi}]} }
+
+# Prompt user for a yes/no response
+proc yesno {question {default "Y"}} {
+ set answer ""
+ # Make sure we are seen but catch because ui and console
+ # packages may not be available
+ catch {twapi::set_foreground_window [twapi::get_console_window]}
+ while {![string is boolean -strict $answer]} {
+ puts -nonewline stdout "$question Type Y/N followed by Enter \[$default\] : "
+ flush stdout
+ set answer [string trim [gets stdin]]
+ if {$answer eq ""} {
+ set answer $default
+ }
+ }
+ return [expr {!! $answer}]
+}
+
+proc prompt {prompt} {
+ set answer ""
+ # Make sure we are seen but catch because ui and console
+ # packages may not be available
+ catch {twapi::set_foreground_window [twapi::get_console_window]}
+ puts -nonewline stdout "$prompt"
+ return [gets stdin]
+}
+
+
+test winConsole-1.0 {Console blocking gets} -constraints {win interactive xx} -body {
+ set response [prompt "Type a line of text and press Return\n"]
+ yesno "Did you type \"$response\""
+} -result 1
test winConsole-1.1 {Console file channel: non-blocking gets} {win interactive} {
set oldmode [fconfigure stdin]
@@ -23,7 +56,7 @@ test winConsole-1.1 {Console file channel: non-blocking gets} {win interactive}
fileevent stdin readable {
if {[gets stdin line] >= 0} {
set result $line
- } else {
+ } elseif {[eof stdin]} {
set result "gets failed"
}
}
@@ -41,6 +74,9 @@ test winConsole-1.1 {Console file channel: non-blocking gets} {win interactive}
} "abcdef"
+
+
+
#cleanup
::tcltest::cleanupTests