aboutsummaryrefslogtreecommitdiff
path: root/tests/interactive.test
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2020-05-02 16:44:28 +1000
committerSteve Bennett <steveb@workware.net.au>2020-05-07 12:34:38 +1000
commitee4d0961cc6089218e0244b4699cf480318bf7d7 (patch)
treebb6998ad3317dabeec00c7e26d23564fc4096ac5 /tests/interactive.test
parenta6c24e9c1a78da2ae9a5d5e6a110f26da40ac143 (diff)
downloadjimtcl-ee4d0961cc6089218e0244b4699cf480318bf7d7.zip
jimtcl-ee4d0961cc6089218e0244b4699cf480318bf7d7.tar.gz
jimtcl-ee4d0961cc6089218e0244b4699cf480318bf7d7.tar.bz2
tests: Add interactive mode tests
Using a custom "expect-like" module to allow testing Jim in interactive mode. This also exercises the 'socket pty' support. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/interactive.test')
-rw-r--r--tests/interactive.test137
1 files changed, 137 insertions, 0 deletions
diff --git a/tests/interactive.test b/tests/interactive.test
new file mode 100644
index 0000000..d403775
--- /dev/null
+++ b/tests/interactive.test
@@ -0,0 +1,137 @@
+source [file dirname [info script]]/testing.tcl
+
+needs constraint jim
+
+package require expect
+
+set saveenv $env
+
+# Make sure we start with an empty history
+set env(HOME) [pwd]
+file delete .jim_history
+
+# spawn the process to be used for testing
+set p [expect::spawn [info nameofexecutable]]
+
+set env $saveenv
+
+$p timeout 1
+# Turn on echo since we get echo with linenoise anyway
+$p tty echo 1
+
+proc wait-for-prompt {p} {
+ $p expect {\. }
+}
+
+# Start with an empty history
+file delete test_history
+wait-for-prompt $p
+$p send "history load test_history\r"
+# skip echoed output
+$p expect {\r\n}
+wait-for-prompt $p
+
+test interactive-1.1 {basic command} -body {
+ $p send "lsort \[info commands li*\]\r"
+ # skip echoed output
+ $p expect {\r\n}
+ # get command result
+ $p expect {\r\n}
+ $p before
+} -result {lindex linsert list} -cleanup {
+ wait-for-prompt $p
+}
+
+test interactive-1.2 {command line completion} {
+ set check 0
+ set failed 0
+ $p send "li\t"
+ $p expect {lindex} { incr check } TIMEOUT { incr failed }
+ if {!$failed} {
+ $p send "\t"
+ $p expect {linsert} { incr check }
+ $p send "\t"
+ $p expect {list} { incr check }
+ $p send \r
+ }
+ $p expect {\r\n}
+ wait-for-prompt $p
+
+ list $check $failed
+} {3 0}
+
+test interactive-1.3 {history show} -body {
+ $p send "history show\r"
+ $p expect {\r\n}
+ $p expect {history show\r\n}
+ string cat [$p before] [$p after]
+} -result " 1 history load test_history\r\n 2 lsort \[info commands li*\]\r\n 3 list\r\n 4 history show\r\n" -cleanup {
+ wait-for-prompt $p
+}
+
+test interactive-1.4 {history getline} -body {
+ $p send "history getline {PROMPT> }\r"
+ $p expect {\r\n}
+ sleep 0.25
+ $p send "abc\bd\x01e\r"
+ $p expect {\r\n}
+ $p expect {\r\n}
+ $p before
+} -result {eabd} -cleanup {
+ wait-for-prompt $p
+}
+
+test interactive-1.4 {history getline} -body {
+ $p send "set len \[history getline {PROMPT> } buf\]\r"
+ $p expect {\r\n}
+ sleep 0.25
+ $p send "abcde\r"
+ $p expect {\r\n}
+ $p expect {\r\n}
+ sleep 0.25
+ $p wait-for-prompt
+ $p send "list \$len \$buf\r"
+ $p expect {\r\n}
+ $p expect {\r\n}
+ $p before
+} -result {5 abcde} -cleanup {
+ wait-for-prompt $p
+}
+
+test interactive-1.5 {insert wide character} -constraints utf8 -body {
+ $p send "set x a\u1100b"
+ # now arrow left twice over the wide char and insert another char
+ $p send \x1bOD
+ $p send \x1bOD
+ $p send y
+ $p send \r
+ $p expect {\r\n}
+ sleep 0.25
+ $p expect {\r\n}
+ $p before
+} -result ay\u1100b -cleanup {
+ wait-for-prompt $p
+}
+
+test interactive-1.6 {insert utf-8 combining character} -constraints utf8 -body {
+ $p send "set x x\u0300"
+ # now arrow left twice over the combining char and "x" and insert another char
+ $p send \x1bOD
+ $p send \x1bOD
+ $p send y
+ $p send \r
+ $p expect {\r\n}
+ sleep 0.25
+ $p expect {\r\n}
+ $p before
+} -result yx\u0300 -cleanup {
+ wait-for-prompt $p
+}
+
+# send ^D to cause the interpeter to exit
+$p send \x04
+sleep 0.25
+$p expect EOF
+$p close
+
+testreport