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