From 4b147a6ab9cba20f4e95d5514d64f46bd3beb4af Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 30 Oct 2021 09:53:47 -0700 Subject: [PATCH] rewrite strps.awk in Python and inline it Related to #2118. --- rtest/Makefile.am | 2 +- rtest/rtest.py | 31 +++++++++++++++++++------------ rtest/strps.awk | 3 --- 3 files changed, 20 insertions(+), 16 deletions(-) delete mode 100644 rtest/strps.awk diff --git a/rtest/Makefile.am b/rtest/Makefile.am index 9d52aa840..4d9c73be5 100644 --- a/rtest/Makefile.am +++ b/rtest/Makefile.am @@ -1,3 +1,3 @@ SUBDIRS = graphs linux.x86 -EXTRA_DIST = graphs nshare rtest.py strps.awk tests.txt tests_subset.txt test_regression.py +EXTRA_DIST = graphs nshare rtest.py tests.txt tests_subset.txt test_regression.py diff --git a/rtest/rtest.py b/rtest/rtest.py index 3645775a4..da1c4243d 100755 --- a/rtest/rtest.py +++ b/rtest/rtest.py @@ -3,8 +3,6 @@ """ Graphviz regression test driver -Also relies on strps.awk. - TODO: Report differences with shared version and with new output. """ @@ -126,16 +124,25 @@ def doDiff(OUTFILE, testname, subtest_index, fmt): file=sys.stderr) return if F in ["ps", "ps2"]: - with open(TMPFILE1, mode="w") as fd: - subprocess.check_call( - ["awk", "-f", "strps.awk", FILE1], - stdout=fd, - ) - with open(TMPFILE2, mode="w") as fd: - subprocess.check_call( - ["awk", "-f", "strps.awk", FILE2], - stdout=fd, - ) + + with open(FILE1, "rt") as src: + with open(TMPFILE1, "wt") as dst: + done_setup = False + for line in src: + if done_setup: + dst.write(line) + else: + done_setup = re.match(r"%%End.*Setup", line) is not None + + with open(FILE2, "rt") as src: + with open(TMPFILE2, "wt") as dst: + done_setup = False + for line in src: + if done_setup: + dst.write(line) + else: + done_setup = re.match(r"%%End.*Setup", line) is not None + returncode = 0 if filecmp.cmp(TMPFILE1, TMPFILE2) else -1 elif F == "svg": with open(FILE1) as f: diff --git a/rtest/strps.awk b/rtest/strps.awk deleted file mode 100644 index 0218d4d0d..000000000 --- a/rtest/strps.awk +++ /dev/null @@ -1,3 +0,0 @@ -BEGIN{doit = 0} - { if (doit) print $0 } - $0 = /%%End.*Setup/ { doit = 1 } -- 2.40.0