diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:55:11 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:55:11 +0000 |
commit | cd07912073c951b4bbb871ed2653af1be2cfc714 (patch) | |
tree | 1073c2308492e6aea4c66cb7436ee92db2abfd42 /tools/lint/tests/expect/common.exp | |
parent | Initial commit. (diff) | |
download | libyang2-upstream/2.1.30.tar.xz libyang2-upstream/2.1.30.zip |
Adding upstream version 2.1.30.upstream/2.1.30upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/tests/expect/common.exp')
-rw-r--r-- | tools/lint/tests/expect/common.exp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/lint/tests/expect/common.exp b/tools/lint/tests/expect/common.exp new file mode 100644 index 0000000..0381e6c --- /dev/null +++ b/tools/lint/tests/expect/common.exp @@ -0,0 +1,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} + } +} |