summaryrefslogtreecommitdiffstats
path: root/debian/tests
diff options
context:
space:
mode:
Diffstat (limited to 'debian/tests')
-rw-r--r--debian/tests/control6
-rwxr-xr-xdebian/tests/yanglint18
-rwxr-xr-xdebian/tests/yangre31
3 files changed, 55 insertions, 0 deletions
diff --git a/debian/tests/control b/debian/tests/control
new file mode 100644
index 0000000..146e626
--- /dev/null
+++ b/debian/tests/control
@@ -0,0 +1,6 @@
+Tests: yanglint
+Depends: gzip,
+ libyang2-tools
+
+Tests: yangre
+Depends: libyang2-tools
diff --git a/debian/tests/yanglint b/debian/tests/yanglint
new file mode 100755
index 0000000..eda5573
--- /dev/null
+++ b/debian/tests/yanglint
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+set -e
+
+# Setup the test file
+trap 'rm -f "${TESTFILE}"; rmdir "${TESTDIR}"' EXIT
+TESTDIR=$(mktemp -d /tmp/yanglint.XXXXXX)
+TESTFILE="${TESTDIR}/ietf-interfaces.yang"
+
+# Unpack or copy the test file
+if test -f /usr/share/doc/libyang2-tools/examples/ietf-interfaces.yang.gz; then
+ gunzip -c < /usr/share/doc/libyang2-tools/examples/ietf-interfaces.yang.gz > "${TESTFILE}"
+else
+ cp /usr/share/doc/libyang2-tools/examples/ietf-interfaces.yang "${TESTFILE}"
+fi
+
+# Lint the test file
+yanglint "${TESTFILE}"
diff --git a/debian/tests/yangre b/debian/tests/yangre
new file mode 100755
index 0000000..7ef17f9
--- /dev/null
+++ b/debian/tests/yangre
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+set -e
+
+cleanup() {
+ if [ -n "${patternsfile}" ]; then
+ rm -f "${patternsfile}"
+ fi
+}
+trap cleanup EXIT
+
+# All these tests were taken from the yangre(1) manpage
+echo "Testing plain regular expression"
+yangre -p 'te.*xt' text_text
+
+echo "Testing multiple patterns"
+yangre -p '.*pat1' -p 'pat2.*' pat2testpat1
+
+echo "Testing multiple patterns including an inverted one"
+yangre -p '.*pat1' -p 'pat2.*' -p 'notpat' -i pat2testpat1
+
+echo "Testing multiple patterns, including an inverted one, via a file"
+patternsfile=$(mktemp)
+cat > "${patternsfile}" <<EOF
+.*pat1
+pat2.*
+ notpat
+
+pat2testpat1
+EOF
+yangre -f "${patternsfile}"