blob: e85f34e7f16d78a2b2b82837f72eff7141c2bfca [file] [log] [blame]
romane84f7dc2022-10-21 10:25:38 +02001# set the timeout to 1 second
2set timeout 1
3
4# expect a single line of anchored regex output
5proc expect_output {output} {
6 expect {
7 -re "^${output}$" {}
8 timeout {exit 1}
9 }
10}
11
12# send a command and either expect some anchored regex output if specified or just an empty line
13proc expect_command {command has_output output} {
14 send -- "${command}\r"
15
16 if ($has_output==1) {
17 expect {
18 -re "^${command}\r\n${output}$" {}
19 timeout {exit 1}
20 }
21 } else {
22 # input echoes
23 expect {
24 -re "^${command}\r\n$" {}
25 timeout {exit 1}
26 }
27 expect {
28 -re "^> $" {}
29 timeout {exit 1}
30 }
31 }
32}
33
34# send a completion request and check if the anchored regex output matches
35proc expect_completion {input output} {
36 send -- "${input}\t"
37
38 expect {
39 # expecting echoing input, output and 10 terminal control characters
40 -re "^${input}\r> ${output}.*\r.*$" {}
41 timeout {exit 1}
42 }
43}
44
45# send a completion request and check if the anchored regex hint options match
46proc expect_hint {input prev_input hints} {
47 set output {}
48 foreach i $hints {
49 # each element might have some number of spaces and CRLF around it
50 append output "${i} *(?:\\r\\n)?"
51 }
52
53 send -- "${input}\t"
54
55 expect {
56 # expecting the hints, previous input from which the hints were generated
57 # and some number of terminal control characters
58 -re "^\r\n${output}\r> ${prev_input}.*\r.*$" {}
59 timeout {exit 1}
60 }
61}