Skip to content

Commit

Permalink
Added a negative test and a must constraint for at least one endpoint…
Browse files Browse the repository at this point in the history
… (fix for issue #1)
  • Loading branch information
GrumpyOldTroll committed Sep 23, 2019
1 parent 265e3a0 commit 886b5ee
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -15,4 +15,6 @@ pulls.json
report.xml
lib
*.withyang
*.yangdeps
tmp-negative.out
modules/
3 changes: 3 additions & 0 deletions ietf-taps-api.yang
Expand Up @@ -232,6 +232,9 @@ module ietf-taps-api {
}

container preconnection {
must "count(//preconnection/local-endpoints) > 0 or
count(//preconnection/remote-endpoints) > 0";

description "preconnection config for a taps connection";

list local-endpoints {
Expand Down
3 changes: 3 additions & 0 deletions negative-ietf-taps-api-no-endpoints.expect
@@ -0,0 +1,3 @@
+ yanglint -f json -t data -D -s -V -p modules -p . ietf-taps-api.yang negative-ietf-taps-api-no-endpoints.json
err : Must condition "count(//preconnection/local-endpoints) > 0 or
count(//preconnection/remote-endpoints) > 0" not satisfied. (/ietf-taps-api:preconnection)
4 changes: 4 additions & 0 deletions negative-ietf-taps-api-no-endpoints.json
@@ -0,0 +1,4 @@
{
"ietf-taps-api:preconnection":{
}
}
55 changes: 55 additions & 0 deletions negative.sh
@@ -0,0 +1,55 @@
#!/bin/bash

input_yang=$1

if [ ! -f "$input_yang" ] ; then
echo "no file $input_yang"
echo "usage: $0 <input>.yang :"
echo " runs yanglint on all files named negative-<input>-*.json,"
echo " with <input>.yang, and confirms that they all fail."
exit 1
fi

yangfile=$(basename -- "$input_yang")
# extension="${yangfile##*.}"
input="${yangfile%.*}"

problems=0
problems_in=""
passed=""
passed_count=0

for f in $(ls negative-${input}-*.json); do
bash -x -e -c "yanglint -f json -t data -D -s -V -p modules -p . $input.yang $f" 2>&1 | grep -v "warn: Module's revisions are not unique (2018-06-28)" > tmp-negative.out

if [ "${PIPESTATUS[0]}" = "0" ]; then
problems=$((problems+1))
problems_in="$problems_in\\n $f"
else
filename=$(basename -- "$f")
# extension="${filename##*.}"
basename="${filename%.*}"
if [ ! -e $basename.expect ]; then
echo "no such file: $basename.expect"
problems=$((problems+1))
problems_in="$problems_in\\n $f"
else
if ! bash -x -c "diff $basename.expect tmp-negative.out"; then
problems=$((problems+1))
problems_in="$problems_in\\n $f"
else
passed="$passed\\n $f"
passed_count=$((passed_count+1))
fi
fi
fi
done

if [ "$problems" != "0" ]; then
printf "$problems negative tests had problems:"
printf "$problems_in\\n"
exit 1
else
printf "all $passed_count negative tests passed:"
printf "$passed\\n"
fi

0 comments on commit 886b5ee

Please sign in to comment.