Commit c377b16d authored by Tim Peters's avatar Tim Peters

Since the most likely failure mode for an expected-output test is a change

somewhere inside a line, use ndiff so that intraline difference marking
can point out what changed within a line.  I don't remember diff-style
abbreviations either (haven't used it since '94, except to produce
patches), so say the rest in English too.
parent 58b072d5
...@@ -349,38 +349,45 @@ def runtest(test, generate, verbose, quiet, testdir = None): ...@@ -349,38 +349,45 @@ def runtest(test, generate, verbose, quiet, testdir = None):
return 0 return 0
def reportdiff(expected, output): def reportdiff(expected, output):
print "*" * 70
import difflib import difflib
a = expected.splitlines() print "*" * 70
b = output.splitlines() a = expected.splitlines(1)
b = output.splitlines(1)
sm = difflib.SequenceMatcher(a=a, b=b) sm = difflib.SequenceMatcher(a=a, b=b)
tuples = sm.get_opcodes() tuples = sm.get_opcodes()
def pair(x0, x1): def pair(x0, x1):
# x0:x1 are 0-based slice indices; convert to 1-based line indices.
x0 += 1 x0 += 1
if x0 >= x1: if x0 >= x1:
return str(x0) return "line " + str(x0)
else: else:
return "%d,%d" % (x0, x1) return "lines %d-%d" % (x0, x1)
for op, a0, a1, b0, b1 in tuples: for op, a0, a1, b0, b1 in tuples:
if op == 'equal': if op == 'equal':
pass pass
elif op == 'delete': elif op == 'delete':
print pair(a0, a1) + "d" + pair(b0, b1) print "***", pair(a0, a1), "of expected output missing:"
for line in a[a0:a1]: for line in a[a0:a1]:
print "<", line print "-", line,
elif op == 'replace': elif op == 'replace':
print pair(a0, a1) + "c" + pair(b0, b1) print "*** mismatch between", pair(a0, a1), "of expected", \
for line in a[a0:a1]: "output and", pair(b0, b1), "of actual output:"
print "<", line for line in difflib.ndiff(a[a0:a1], b[b0:b1]):
print "---" print line,
for line in b[b0:b1]:
print ">", line
elif op == 'insert': elif op == 'insert':
print str(a0) + "a" + pair(b0, b1) print "***", pair(b0, b1), "of actual output doesn't appear", \
"in expected output after line", str(a1)+":"
for line in b[b0:b1]: for line in b[b0:b1]:
print ">", line print "+", line,
else: else:
print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1) print "get_opcodes() returned bad tuple?!?!", (op, a0, a1, b0, b1)
print "*" * 70 print "*" * 70
def findtestdir(): def findtestdir():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment