Linux Netfilter development
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH] tests: iptables-test: Use difflib if dumps differ
Date: Wed, 20 Dec 2023 16:13:53 +0100	[thread overview]
Message-ID: <20231220151353.25210-1-phil@nwl.cc> (raw)

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


             reply	other threads:[~2023-12-20 15:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-20 15:13 Phil Sutter [this message]
2023-12-21 13:35 ` [iptables PATCH] tests: iptables-test: Use difflib if dumps differ Phil Sutter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231220151353.25210-1-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox