* [iptables PATCH] tests: iptables-test: Use difflib if dumps differ
@ 2023-12-20 15:13 Phil Sutter
2023-12-21 13:35 ` Phil Sutter
0 siblings, 1 reply; 2+ messages in thread
From: Phil Sutter @ 2023-12-20 15:13 UTC (permalink / raw)
To: netfilter-devel
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 | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/iptables-test.py b/iptables-test.py
index 6f63cdbeda9af..179e366e02961 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 @@ STDERR_IS_TTY = sys.stderr.isatty()
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
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [iptables PATCH] tests: iptables-test: Use difflib if dumps differ
2023-12-20 15:13 [iptables PATCH] tests: iptables-test: Use difflib if dumps differ Phil Sutter
@ 2023-12-21 13:35 ` Phil Sutter
0 siblings, 0 replies; 2+ messages in thread
From: Phil Sutter @ 2023-12-21 13:35 UTC (permalink / raw)
To: netfilter-devel
On Wed, Dec 20, 2023 at 04:13:53PM +0100, Phil Sutter wrote:
> Improve log readability by printing a unified diff of the expected vs.
> actual iptables-save output.
>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
Patch applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-21 13:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-20 15:13 [iptables PATCH] tests: iptables-test: Use difflib if dumps differ Phil Sutter
2023-12-21 13:35 ` Phil Sutter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox