mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
update-test: some file names have dashes in them
* build-aux/update-test (log): Rename as... (trace): this, to avoid clashes with the log variable. (getargs): Clarify the type of the arguments.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
# usage:
|
# usage:
|
||||||
# update-test _build/8d/tests/testsuite.dir/*.testsuite.log
|
# update-test _build/8d/tests/testsuite.dir/*/testsuite.log
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
@@ -11,8 +11,8 @@ import re
|
|||||||
def getargs():
|
def getargs():
|
||||||
p = argparse.ArgumentParser(description='Update test cases.')
|
p = argparse.ArgumentParser(description='Update test cases.')
|
||||||
opt = p.add_argument
|
opt = p.add_argument
|
||||||
opt('tests', metavar='test', nargs='+', type=str, default=None,
|
opt('logs', metavar='log', nargs='+', type=str, default=None,
|
||||||
help='test files to update')
|
help='log files to process')
|
||||||
opt('-v', '--verbose', action='store_true',
|
opt('-v', '--verbose', action='store_true',
|
||||||
help='Be verbose')
|
help='Be verbose')
|
||||||
return p.parse_args()
|
return p.parse_args()
|
||||||
@@ -21,14 +21,14 @@ args = getargs()
|
|||||||
subst = dict()
|
subst = dict()
|
||||||
|
|
||||||
|
|
||||||
def log(*args_):
|
def trace(*args_):
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(*args_)
|
print(*args_)
|
||||||
|
|
||||||
|
|
||||||
def contents(file):
|
def contents(file):
|
||||||
'''The contents of a file.'''
|
'''The contents of a file.'''
|
||||||
log(file)
|
trace(file)
|
||||||
f = open(file)
|
f = open(file)
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
@@ -60,9 +60,9 @@ def diff_to_re(match):
|
|||||||
def update(at_file, logfile):
|
def update(at_file, logfile):
|
||||||
test = contents(at_file)
|
test = contents(at_file)
|
||||||
if os.path.isfile(logfile):
|
if os.path.isfile(logfile):
|
||||||
log("LOG: ", logfile)
|
trace("LOG: ", logfile)
|
||||||
l = contents(logfile)
|
l = contents(logfile)
|
||||||
log("LOG: ", l)
|
trace("LOG: ", l)
|
||||||
global subst
|
global subst
|
||||||
subst = {}
|
subst = {}
|
||||||
re.sub(r'(?:^@@.*\n)((?:^[-+ ].*\n)+)',
|
re.sub(r'(?:^@@.*\n)((?:^[-+ ].*\n)+)',
|
||||||
@@ -71,7 +71,7 @@ def update(at_file, logfile):
|
|||||||
if subst:
|
if subst:
|
||||||
# Turn "subst{frm} -> to" into a large RE.
|
# Turn "subst{frm} -> to" into a large RE.
|
||||||
frm = '|'.join([re.escape(x) for x in subst])
|
frm = '|'.join([re.escape(x) for x in subst])
|
||||||
log("FROM:", frm)
|
trace("FROM:", frm)
|
||||||
test = re.sub("(" + frm + ")",
|
test = re.sub("(" + frm + ")",
|
||||||
lambda m: subst[m.group(1)],
|
lambda m: subst[m.group(1)],
|
||||||
test, flags=re.MULTILINE)
|
test, flags=re.MULTILINE)
|
||||||
@@ -81,13 +81,14 @@ def update(at_file, logfile):
|
|||||||
def process(logfile):
|
def process(logfile):
|
||||||
log = contents(logfile)
|
log = contents(logfile)
|
||||||
# Look for the file to update.
|
# Look for the file to update.
|
||||||
m = re.search(r'^\d+\. (\w+\.at):\d+: ', log, re.MULTILINE)
|
m = re.search(r'^\d+\. ([-\w]+\.at):\d+: ', log, re.MULTILINE)
|
||||||
if not m:
|
if not m:
|
||||||
|
trace("no diff found:", logfile)
|
||||||
return
|
return
|
||||||
at_file = 'tests/' + m.group(1)
|
at_file = 'tests/' + m.group(1)
|
||||||
print(at_file)
|
print(at_file)
|
||||||
update(at_file, logfile)
|
update(at_file, logfile)
|
||||||
|
|
||||||
for t in args.tests:
|
for logfile in args.logs:
|
||||||
log("FILE:", t)
|
trace("FILE:", logfile)
|
||||||
process(t)
|
process(logfile)
|
||||||
|
|||||||
Reference in New Issue
Block a user