summaryrefslogtreecommitdiffstats
path: root/tools/lint/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:55:11 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:55:11 +0000
commitcd07912073c951b4bbb871ed2653af1be2cfc714 (patch)
tree1073c2308492e6aea4c66cb7436ee92db2abfd42 /tools/lint/tests
parentInitial commit. (diff)
downloadlibyang2-upstream.tar.xz
libyang2-upstream.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')
-rw-r--r--tools/lint/tests/expect/common.exp68
-rwxr-xr-xtools/lint/tests/expect/completion.exp60
-rwxr-xr-xtools/lint/tests/expect/feature.exp20
-rwxr-xr-xtools/lint/tests/expect/list.exp20
-rwxr-xr-xtools/lint/tests/shunit2/feature.sh19
-rwxr-xr-xtools/lint/tests/shunit2/list.sh28
6 files changed, 215 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}
+ }
+}
diff --git a/tools/lint/tests/expect/completion.exp b/tools/lint/tests/expect/completion.exp
new file mode 100755
index 0000000..ed4f6bd
--- /dev/null
+++ b/tools/lint/tests/expect/completion.exp
@@ -0,0 +1,60 @@
+#!/usr/bin/expect -f
+
+if { [info exists ::env(CURRENT_SOURCE_DIR)] } {
+ source "$env(CURRENT_SOURCE_DIR)/tests/expect/common.exp"
+ set yang_dir "$env(CURRENT_SOURCE_DIR)/examples"
+} else {
+ source "common.exp"
+ set yang_dir "../../examples"
+}
+
+spawn $yanglint
+
+# skip no dir and/or no history warnings
+expect_output "(YANGLINT.*)*> "
+
+expect_command "clear -ii" 0 ""
+
+expect_command "add ${yang_dir}/ietf-ip.yang" 0 ""
+
+expect_completion "print -f info -P " "print -f info -P /ietf-"
+
+set hints {"/ietf-yang-schema-mount:schema-mounts" "/ietf-interfaces:interfaces" "/ietf-interfaces:interfaces-state"}
+
+expect_hint "" "print -f info -P /ietf-" $hints
+
+expect_completion "i" "print -f info -P /ietf-interfaces:interfaces"
+
+expect_completion "/" "print -f info -P /ietf-interfaces:interfaces/interface"
+
+set hints {"/ietf-interfaces:interfaces/interface"
+"/ietf-interfaces:interfaces/interface/name" "/ietf-interfaces:interfaces/interface/description"
+"/ietf-interfaces:interfaces/interface/type" "/ietf-interfaces:interfaces/interface/enabled"
+"/ietf-interfaces:interfaces/interface/link-up-down-trap-enable"
+"/ietf-interfaces:interfaces/interface/ietf-ip:ipv4" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv6"}
+
+expect_hint "" "print -f info -P /ietf-interfaces:interfaces/interface" $hints
+
+expect_completion "/i" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv"
+
+expect_completion "4" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv4"
+
+set hints { "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/enabled"
+"/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/forwarding" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/mtu"
+"/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address" "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/neighbor"
+}
+
+expect_hint "\t" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv" $hints
+
+expect_completion "/e" "print -f info -P /ietf-interfaces:interfaces/interface/ietf-ip:ipv4/enabled "
+
+send -- "\r"
+
+expect {
+ -re ".*\r\n> " {}
+ timeout {exit 1}
+}
+
+send -- "exit\r"
+
+expect eof
diff --git a/tools/lint/tests/expect/feature.exp b/tools/lint/tests/expect/feature.exp
new file mode 100755
index 0000000..37680b0
--- /dev/null
+++ b/tools/lint/tests/expect/feature.exp
@@ -0,0 +1,20 @@
+#!/usr/bin/expect -f
+
+if { [info exists ::env(CURRENT_SOURCE_DIR)] } {
+ source "$env(CURRENT_SOURCE_DIR)/tests/expect/common.exp"
+ set yang_dir "$env(CURRENT_SOURCE_DIR)/examples"
+} else {
+ source "common.exp"
+ set yang_dir "../../examples"
+}
+
+spawn $yanglint
+
+# skip no dir and/or no history warnings
+expect_output "(YANGLINT.*)*> "
+
+expect_command "feature -a" 1 "yang:\r\n\t\\(none\\)\r\n\r\nietf-yang-schema-mount:\r\n\t\\(none\\)\r\n\r\n> "
+
+send -- "exit\r"
+
+expect eof
diff --git a/tools/lint/tests/expect/list.exp b/tools/lint/tests/expect/list.exp
new file mode 100755
index 0000000..ec3cdba
--- /dev/null
+++ b/tools/lint/tests/expect/list.exp
@@ -0,0 +1,20 @@
+#!/usr/bin/expect -f
+
+if { [info exists ::env(CURRENT_SOURCE_DIR)] } {
+ source "$env(CURRENT_SOURCE_DIR)/tests/expect/common.exp"
+ set yang_dir "$env(CURRENT_SOURCE_DIR)/examples"
+} else {
+ source "common.exp"
+ set yang_dir "../../examples"
+}
+
+spawn $yanglint
+
+# skip no dir and/or no history warnings
+expect_output "(YANGLINT.*)*> "
+
+expect_command "list" 1 "List of the loaded models:\r\n *i ietf-yang-metadata@2016-08-05\r\n *I yang@2022-06-16\r\n *i ietf-inet-types@2013-07-15\r\n *i ietf-yang-types@2013-07-15\r\n *I ietf-yang-schema-mount@2019-01-14\r\n *i ietf-yang-structure-ext@2020-06-17\r\n> "
+
+send -- "exit\r"
+
+expect eof
diff --git a/tools/lint/tests/shunit2/feature.sh b/tools/lint/tests/shunit2/feature.sh
new file mode 100755
index 0000000..fb2ee88
--- /dev/null
+++ b/tools/lint/tests/shunit2/feature.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+testFeature() {
+ models=( "iana-if-type@2014-05-08.yang" "ietf-netconf@2011-06-01.yang" "ietf-netconf-with-defaults@2011-06-01.yang"
+ "sm.yang" "ietf-interfaces@2014-05-08.yang" "ietf-netconf-acm@2018-02-14.yang" "ietf-origin@2018-02-14.yang"
+ "ietf-ip@2014-06-16.yang" "ietf-restconf@2017-01-26.yang" )
+ features=( " -F iana-if-type:"
+ " -F ietf-netconf:writable-running,candidate,confirmed-commit,rollback-on-error,validate,startup,url,xpath"
+ " -F ietf-netconf-with-defaults:" " -F sm:" " -F ietf-interfaces:arbitrary-names,pre-provisioning,if-mib"
+ " -F ietf-netconf-acm:" " -F ietf-origin:" " -F ietf-ip:ipv4-non-contiguous-netmasks,ipv6-privacy-autoconf"
+ " -F ietf-restconf:" )
+
+ for i in ${!models[@]}; do
+ output=`${YANGLINT} -f feature-param ${YANG_MODULES_DIR}/${models[$i]}`
+ assertEquals "Unexpected features of module ${models[$i]}." "${features[$i]}" "${output}"
+ done
+}
+
+. shunit2
diff --git a/tools/lint/tests/shunit2/list.sh b/tools/lint/tests/shunit2/list.sh
new file mode 100755
index 0000000..d64503a
--- /dev/null
+++ b/tools/lint/tests/shunit2/list.sh
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+
+LIST_BASE="List of the loaded models:
+ i ietf-yang-metadata@2016-08-05
+ I yang@2022-06-16
+ i ietf-inet-types@2013-07-15
+ i ietf-yang-types@2013-07-15
+ I ietf-yang-schema-mount@2019-01-14
+ i ietf-yang-structure-ext@2020-06-17"
+
+testListEmptyContext() {
+ output=`${YANGLINT} -l`
+ assertEquals "Unexpected list of modules in empty context." "${LIST_BASE}" "${output}"
+}
+
+testListAllImplemented() {
+ LIST_BASE_ALLIMPLEMENTED="List of the loaded models:
+ I ietf-yang-metadata@2016-08-05
+ I yang@2022-06-16
+ I ietf-inet-types@2013-07-15
+ I ietf-yang-types@2013-07-15
+ I ietf-yang-schema-mount@2019-01-14
+ I ietf-yang-structure-ext@2020-06-17"
+ output=`${YANGLINT} -lii`
+ assertEquals "Unexpected list of modules in empty context with -ii." "${LIST_BASE_ALLIMPLEMENTED}" "${output}"
+}
+
+. shunit2