bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tests: add a tool for mass updates


From: Akim Demaille
Subject: tests: add a tool for mass updates
Date: Sat, 30 Mar 2019 08:43:26 +0100

commit 75303c61d86606a400a6398aa8f914a1070bdf6d
Author: Akim Demaille <address@hidden>
Date:   Sat Feb 16 07:31:36 2019 +0100

    tests: add a tool for mass updates
    
    When we update some output format, too many adjustements must be made
    by hand.  This script updates most tests based on the actual output
    made during the tests.
    
    * build-aux/update-test: New.

diff --git a/README-hacking b/README-hacking
index ff701e99..4a977a35 100644
--- a/README-hacking
+++ b/README-hacking
@@ -195,6 +195,11 @@ update.
 ** make check
 Use liberally.
 
+** Updating the expectations
+Sometimes some changes have a large impact on the test suite (e.g., when we
+added the "[-Wother]" part to all the warnings).  Part of the update can be
+done with a crude tool: tests/update-test.  Read it for more information.
+
 ** TESTSUITEFLAGS
 
 To run just the testsuite (not the tests related to the examples), run `make
diff --git a/build-aux/update-test b/build-aux/update-test
new file mode 100755
index 00000000..fc7ed701
--- /dev/null
+++ b/build-aux/update-test
@@ -0,0 +1,93 @@
+#! /usr/bin/env python
+
+# usage:
+# update-test _build/8d/tests/testsuite.dir/*.testsuite.log
+
+import argparse
+import os
+import re
+
+
+def getargs():
+    p = argparse.ArgumentParser(description='Update test cases.')
+    opt = p.add_argument
+    opt('tests', metavar='test', nargs='+', type=str, default=None,
+        help='test files to update')
+    opt('-v', '--verbose', action='store_true',
+        help='Be verbose')
+    return p.parse_args()
+
+args = getargs()
+subst = dict()
+
+
+def log(*args_):
+    if args.verbose:
+        print(*args_)
+
+
+def contents(file):
+    '''The contents of a file.'''
+    log(file)
+    f = open(file)
+    return f.read()
+
+
+def diff_to_re(match):
+    '''Convert a portion of patch into a regex substitution to perform.
+    No longer used, we now use the expected/effective parts.
+    '''
+    frm = []
+    to = []
+    is_diff = False
+    for l in match.group(1).splitlines():
+        print(l)
+        # t in [-+ ]
+        t = l[0]
+        l = l[1:]
+        if t in ['-', ' ']:
+            is_diff = True
+            frm.append(l)
+        if t in ['+', ' ']:
+            is_diff = True
+            to.append(l)
+    if is_diff:
+        frm = "\n".join(frm)
+        to = "\n".join(to)
+        subst[frm] = to
+
+
+def update(at_file, logfile):
+    test = contents(at_file)
+    if os.path.isfile(logfile):
+        log("LOG: ", logfile)
+        l = contents(logfile)
+        log("LOG: ", l)
+        global subst
+        subst = {}
+        re.sub(r'(?:^@@.*\n)((?:^[-+ ].*\n)+)',
+               diff_to_re, l, flags = re.MULTILINE)
+        print(subst)
+        if subst:
+            # Turn "subst{frm} -> to" into a large RE.
+            frm = '|'.join([re.escape(x) for x in subst])
+            log("FROM:", frm)
+            test = re.sub("(" + frm + ")",
+                          lambda m: subst[m.group(1)],
+                          test, flags=re.MULTILINE)
+    open(at_file, 'w').write(test)
+
+
+def process(logfile):
+    log = contents(logfile)
+    # Look for the file to update.
+    m = re.search(r'^\d+\. (\w+\.at):\d+: ', log, re.MULTILINE)
+    if not m:
+        return
+    at_file = 'tests/' + m.group(1)
+    print(at_file)
+    update(at_file, logfile)
+
+for t in args.tests:
+    log("FILE:", t)
+    process(t)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]