blob: 0381e6c2dd9220ec3cdfc883ccb1998c36988682 (
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
|
# detect the path to the yanglint binary
if { [info exists ::env(YANGLINT)] } {
set yanglint "$env(YANGLINT)"
} else {
set yanglint "../../../../build/yanglint"
}
# set the timeout to 1 second
set timeout 1
# expect a single line of anchored regex output
proc expect_output {output} {
expect {
-re "^${output}$" {}
timeout {exit 1}
}
}
# send a command and either expect some anchored regex output if specified or just an empty line
proc expect_command {command has_output output} {
send -- "${command}\r"
if ($has_output==1) {
expect {
-re "^${command}\r\n${output}$" {}
timeout {exit 1}
}
} else {
# input echoes
expect {
-re "^${command}\r\n$" {}
timeout {exit 1}
}
expect {
-re "^> $" {}
timeout {exit 1}
}
}
}
# send a completion request and check if the anchored regex output matches
proc expect_completion {input output} {
send -- "${input}\t"
expect {
# expecting echoing input, output and 10 terminal control characters
-re "^${input}\r> ${output}.*\r.*$" {}
timeout {exit 1}
}
}
# send a completion request and check if the anchored regex hint options match
proc expect_hint {input prev_input hints} {
set output {}
foreach i $hints {
# each element might have some number of spaces and CRLF around it
append output "${i} *(?:\\r\\n)?"
}
send -- "${input}\t"
expect {
# expecting the hints, previous input from which the hints were generated
# and some number of terminal control characters
-re "^\r\n${output}\r> ${prev_input}.*\r.*$" {}
timeout {exit 1}
}
}
|