summaryrefslogtreecommitdiffstats
path: root/tests/py
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-05-08 13:08:44 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-05-11 12:17:45 +0200
commit875232bc3e6bf55cc31f3763449503a80a7c2382 (patch)
tree9cf34657940efb95090fe82fd83326da1d743996 /tests/py
parent15ce42d6f7749fb391bb27b01aac735f0f0bbe95 (diff)
tests/py: Highlight offending parts in differences warnings
Print the non-equal parts of the two rules in yellow when printing the differences warning. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests/py')
-rwxr-xr-xtests/py/nft-test.py35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/py/nft-test.py b/tests/py/nft-test.py
index 6684bcd1..1e26d182 100755
--- a/tests/py/nft-test.py
+++ b/tests/py/nft-test.py
@@ -122,8 +122,41 @@ def print_warning(reason, filename=None, lineno=None):
print_msg(reason, filename, lineno, Colors.YELLOW, "WARNING:")
+def color_differences(rule, other, color):
+ rlen = len(rule)
+ olen = len(other)
+
+ # find equal part at start
+ for i in range(rlen):
+ if i >= olen or rule[i] != other[i]:
+ break
+ start_idx = i
+
+ # find equal part at end
+ found = False
+ for i in range(-1, start_idx -rlen - 1, -1):
+ if i < start_idx -olen:
+ break
+ if rule[i] != other[i]:
+ found = True
+ break
+ end_idx = i
+ if found:
+ end_idx += 1
+
+ out = ""
+ if start_idx > 0:
+ out += rule[:start_idx]
+ out += color + rule[start_idx:end_idx] + Colors.ENDC
+ if end_idx < 0:
+ out += rule[end_idx:]
+
+ return out
+
def print_differences_warning(filename, lineno, rule1, rule2, cmd):
- reason = "'" + rule1 + "' mismatches '" + rule2 + "'"
+ colored_rule1 = color_differences(rule1, rule2, Colors.YELLOW)
+ colored_rule2 = color_differences(rule2, rule1, Colors.YELLOW)
+ reason = "'" + colored_rule1 + "' mismatches '" + colored_rule2 + "'"
print filename + ": " + Colors.YELLOW + "WARNING: " + Colors.ENDC + \
"line: " + str(lineno + 1) + ": '" + cmd + "': " + reason