From 85452ab66e188327bb8d65c5dd3c165529037846 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 28 Sep 2017 19:08:24 +0200 Subject: Print unified diff on test suite failures Compares the .config's generated by us and the C implementation. Speeds up debugging compared to manually generating them. Clean up the test code a bit too. --- testsuite.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/testsuite.py b/testsuite.py index 5263720..5a870f6 100644 --- a/testsuite.py +++ b/testsuite.py @@ -40,6 +40,7 @@ from __future__ import print_function +import difflib import errno import kconfiglib import os @@ -2095,11 +2096,10 @@ def run_compatibility_tests(): del os.environ["SRCARCH"] if compare_configs: - sys.stdout.write(" {:14}".format(arch)) if equal_confs(): - print("OK") + print(" {:14}OK".format(arch)) else: - print("FAIL") + print(" {:14}FAIL".format(arch)) fail() if all_ok(): @@ -2431,30 +2431,38 @@ def rm_configs(): rm_if_exists("._config") def equal_confs(): - with open(".config") as menu_conf: - l1 = menu_conf.readlines() + with open(".config") as f: + their = f.readlines() + + # Strip the header generated by 'conf' + i = 0 + for line in their: + if not line.startswith("#") or \ + re.match(r"# CONFIG_(\w+) is not set", line): + break + i += 1 + their = their[i:] try: - my_conf = open("._config") + f = open("._config") except IOError as e: if e.errno != errno.ENOENT: raise print("._config not found. Did you forget to apply the Makefile patch?") return False else: - with my_conf: - l2 = my_conf.readlines() + with f: + our = f.readlines() - # Skip the header generated by 'conf' - unset_re = r"# CONFIG_(\w+) is not set" - i = 0 - for line in l1: - if not line.startswith("#") or \ - re.match(unset_re, line): - break - i += 1 + if their == our: + return True + + # Print a unified diff to help debugging + print("Mismatched .config's! Unified diff:") + sys.stdout.writelines(difflib.unified_diff(their, our, fromfile="their", + tofile="our")) - return l1[i:] == l2 + return False _all_ok = True -- cgit v1.2.3