summaryrefslogtreecommitdiffstats
path: root/iptables-test.py
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2023-11-28 22:26:44 +0100
committerPhil Sutter <phil@nwl.cc>2023-12-21 14:34:29 +0100
commit075e4de85b96ad905c2113d580290963a7872e67 (patch)
treefe8f41a5ad7195dcd7563121c46b468a51f157ab /iptables-test.py
parent63ab5b8906f6913a14d38ec231f21daa760339a9 (diff)
tests: iptables-test: Use difflib if dumps differ
Improve log readability by printing a unified diff of the expected vs. actual iptables-save output. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables-test.py')
-rwxr-xr-xiptables-test.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/iptables-test.py b/iptables-test.py
index 6f63cdbe..179e366e 100755
--- a/iptables-test.py
+++ b/iptables-test.py
@@ -15,6 +15,7 @@ import sys
import os
import subprocess
import argparse
+from difflib import unified_diff
IPTABLES = "iptables"
IP6TABLES = "ip6tables"
@@ -367,11 +368,12 @@ def run_test_file_fast(iptables, filename, netns):
out = out.decode('utf-8').rstrip()
if out.find(out_expect) < 0:
- msg = ["dumps differ!"]
- msg.extend(["expect: " + l for l in out_expect.split("\n")])
- msg.extend(["got: " + l for l in out.split("\n")
- if not l[0] in ['*', ':', '#']])
- print("\n".join(msg), file=log_file)
+ print("dumps differ!", file=log_file)
+ out_clean = [ l for l in out.split("\n")
+ if not l[0] in ['*', ':', '#']]
+ diff = unified_diff(out_expect.split("\n"), out_clean,
+ fromfile="expect", tofile="got", lineterm='')
+ print("\n".join(diff), file=log_file)
return -1
return tests