]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
tests: iptables-test: Use difflib if dumps differ
authorPhil Sutter <phil@nwl.cc>
Tue, 28 Nov 2023 21:26:44 +0000 (22:26 +0100)
committerPhil Sutter <phil@nwl.cc>
Thu, 21 Dec 2023 13:34:29 +0000 (14:34 +0100)
Improve log readability by printing a unified diff of the expected vs.
actual iptables-save output.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables-test.py

index 6f63cdbeda9af819be713f22c4c553da6f3f5d10..179e366e029617f720b94ded71744e2a606f5589 100755 (executable)
@@ -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