aboutsummaryrefslogtreecommitdiff
path: root/tests/interactive.test
blob: 8d1951270fdf824e2149b32b0912a01380e6e5e1 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
source [file dirname [info script]]/testing.tcl

needs constraint jim
needs cmd socket
needs eval "socket pty" {lmap p [socket pty] { $p close }}
constraint expr lineedit {$jim::lineedit}

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 [list [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} lineedit {
	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} -constraints lineedit -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} -constraints lineedit -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.5 {history getline} -constraints lineedit -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.6 {insert wide character} -constraints {utf8 lineedit} -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.7 {insert utf-8 combining character} -constraints {utf8 lineedit} -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