Skip to content

Commit a992cbb

Browse files
committed
More Readable Pyang Error Lines
1 parent 12cc9bc commit a992cbb

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

pytests/pattern_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ fi
99
TEST_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1010
REPO_DIR="$TEST_DIR/.."
1111

12-
pyang -p $OCDIR -p "$REPO_DIR/testdata" --plugindir "$REPO_DIR/pytests/plugins" --check-patterns "$REPO_DIR/testdata/regexp-test.yang"
12+
pyang -p $OCDIR -p "$REPO_DIR/testdata" --msg-template="line {line}: {msg}" --plugindir "$REPO_DIR/pytests/plugins" --check-patterns "$REPO_DIR/testdata/regexp-test.yang"

pytests/plugins/pattern_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ def setup_ctx(self, ctx):
5757
# Test case failure states.
5858
error.add_error_code(
5959
'VALID_PATTERN_DOES_NOT_MATCH', ErrorLevel.MAJOR,
60-
'valid pattern "%s" does not match type "%s"')
60+
'type "%s" rejected valid pattern: "%s"')
6161
error.add_error_code(
6262
'INVALID_PATTERN_MATCH', ErrorLevel.MAJOR,
63-
'invalid pattern "%s" matches type "%s"')
63+
'type "%s" accepted invalid pattern: "%s"')
6464

6565
# Error states.
6666
error.add_error_code(
@@ -255,8 +255,8 @@ def check_patterns(ctx, mods):
255255
break
256256
else: # Exhausted all minterms.
257257
err_add(ctx.errors, s.pos,
258-
'VALID_PATTERN_DOES_NOT_MATCH', (s.arg,
259-
typestmt.arg))
258+
'VALID_PATTERN_DOES_NOT_MATCH', (typestmt.arg,
259+
s.arg,))
260260
elif is_statement_fail_testcase(s):
261261
# Check that no minterm in the DNF is satisfied.
262262
has_at_least_one_test = True
@@ -270,7 +270,7 @@ def check_patterns(ctx, mods):
270270
minterm_matches = False
271271
if minterm_matches:
272272
err_add(ctx.errors, s.pos, 'INVALID_PATTERN_MATCH',
273-
(s.arg, typestmt.arg))
273+
(typestmt.arg, s.arg))
274274
break
275275

276276
if not has_at_least_one_test:

pytests/tests/golden.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
testdata/python-plugin-test.yang:20: error: invalid pattern "ipv4" matches type "string"
2-
testdata/python-plugin-test.yang:21: error: valid pattern "ipv6" does not match type "string"
1+
testdata/python-plugin-test.yang:20: error: type "string" accepted invalid pattern: "ipv4"
2+
testdata/python-plugin-test.yang:21: error: type "string" rejected valid pattern: "ipv6"
33
testdata/python-plugin-test.yang:23: error: leaf "ipv4-2" does not have any test cases
44
testdata/python-plugin-test.yang:31: error: leaf "string" has unrestricted string type
55
testdata/python-plugin-test.yang:34: error: leaf "union" has unrestricted string type
6-
testdata/python-plugin-test.yang:54: error: invalid pattern "ipv4" matches type "union"
7-
testdata/python-plugin-test.yang:55: error: valid pattern "ipv5" does not match type "union"
8-
testdata/python-plugin-test.yang:64: error: invalid pattern "ipv4" matches type "t:ip-string"
9-
testdata/python-plugin-test.yang:65: error: valid pattern "ipv5" does not match type "t:ip-string"
10-
testdata/python-plugin-test.yang:74: error: invalid pattern "ipv4" matches type "t:ip-string-typedef"
11-
testdata/python-plugin-test.yang:75: error: valid pattern "ipv5" does not match type "t:ip-string-typedef"
12-
testdata/python-plugin-test.yang:91: error: invalid pattern "ipv4" matches type "union"
13-
testdata/python-plugin-test.yang:92: error: valid pattern "hehe" does not match type "union"
14-
testdata/python-plugin-test.yang:93: error: invalid pattern "ipV5" matches type "union"
15-
testdata/python-plugin-test.yang:94: error: invalid pattern "ipv6" matches type "union"
16-
testdata/python-plugin-test.yang:104: error: valid pattern "ipv6" does not match type "t:ipv4-str"
6+
testdata/python-plugin-test.yang:54: error: type "union" accepted invalid pattern: "ipv4"
7+
testdata/python-plugin-test.yang:55: error: type "union" rejected valid pattern: "ipv5"
8+
testdata/python-plugin-test.yang:64: error: type "t:ip-string" accepted invalid pattern: "ipv4"
9+
testdata/python-plugin-test.yang:65: error: type "t:ip-string" rejected valid pattern: "ipv5"
10+
testdata/python-plugin-test.yang:74: error: type "t:ip-string-typedef" accepted invalid pattern: "ipv4"
11+
testdata/python-plugin-test.yang:75: error: type "t:ip-string-typedef" rejected valid pattern: "ipv5"
12+
testdata/python-plugin-test.yang:91: error: type "union" accepted invalid pattern: "ipv4"
13+
testdata/python-plugin-test.yang:92: error: type "union" rejected valid pattern: "hehe"
14+
testdata/python-plugin-test.yang:93: error: type "union" accepted invalid pattern: "ipV5"
15+
testdata/python-plugin-test.yang:94: error: type "union" accepted invalid pattern: "ipv6"
16+
testdata/python-plugin-test.yang:104: error: type "t:ipv4-str" rejected valid pattern: "ipv6"

0 commit comments

Comments
 (0)