mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Christmas present to myself: changed regrtest in two ways:
1. When running in verbose mode, if any test happens to pass, print a warning that the apparent success may be bogus (stdout isn't compared in verbose mode). Been fooled by that too often. 2. When a test fails because the expected stdout doesn't match the actual stdout, print as much of stdout as did match before the first failing write. Else we get failures of the form "expected 'a', got 'b'" and a glance at the expected output file shows 500 instances of 'a' -- no idea where it failed, and, as in #1, trying to run in verbose mode instead doesn't help because stdout isn't compared then.
This commit is contained in:
parent
52328165c5
commit
1a4d77b252
1 changed files with 30 additions and 4 deletions
|
@ -158,6 +158,9 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0,
|
|||
if not bad and not skipped and len(good) > 1:
|
||||
print "All",
|
||||
print count(len(good), "test"), "OK."
|
||||
if verbose:
|
||||
print "CAUTION: stdout isn't compared in verbose mode: a test"
|
||||
print "that passes in verbose mode may fail without it."
|
||||
if bad:
|
||||
print count(len(bad), "test"), "failed:",
|
||||
print string.join(bad)
|
||||
|
@ -280,12 +283,34 @@ class Compare:
|
|||
|
||||
def __init__(self, filename):
|
||||
self.fp = open(filename, 'r')
|
||||
self.stuffthatmatched = []
|
||||
|
||||
def write(self, data):
|
||||
expected = self.fp.read(len(data))
|
||||
if data != expected:
|
||||
raise test_support.TestFailed, \
|
||||
'Writing: '+`data`+', expected: '+`expected`
|
||||
if data == expected:
|
||||
self.stuffthatmatched.append(expected)
|
||||
else:
|
||||
# This Compare instance is spoofing stdout, so we need to write
|
||||
# to stderr instead.
|
||||
from sys import stderr as e
|
||||
print >> e, "The actual stdout doesn't match the expected stdout."
|
||||
if self.stuffthatmatched:
|
||||
print >> e, "This much did match (between asterisk lines):"
|
||||
print >> e, "*" * 70
|
||||
good = "".join(self.stuffthatmatched)
|
||||
e.write(good)
|
||||
if not good.endswith("\n"):
|
||||
e.write("\n")
|
||||
print >> e, "*" * 70
|
||||
print >> e, "Then ..."
|
||||
else:
|
||||
print >> e, "The first write to stdout clashed:"
|
||||
# Note that the prompts are the same length in next two lines.
|
||||
# This is so what we expected and what we got line up.
|
||||
print >> e, "We expected (repr):", `expected`
|
||||
print >> e, "But instead we got:", `data`
|
||||
raise test_support.TestFailed('Writing: ' + `data`+
|
||||
', expected: ' + `expected`)
|
||||
|
||||
def writelines(self, listoflines):
|
||||
map(self.write, listoflines)
|
||||
|
@ -296,7 +321,8 @@ class Compare:
|
|||
def close(self):
|
||||
leftover = self.fp.read()
|
||||
if leftover:
|
||||
raise test_support.TestFailed, 'Unread: '+`leftover`
|
||||
raise test_support.TestFailed('Tail of expected stdout unseen: ' +
|
||||
`leftover`)
|
||||
self.fp.close()
|
||||
|
||||
def isatty(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue