summaryrefslogtreecommitdiffstats
path: root/Lib/test/regrtest.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-12-30 22:21:22 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-12-30 22:21:22 (GMT)
commit1a4d77b2527ced1052b4faae3d176b125a764325 (patch)
tree9e85ea0c2087689197cade1dbcb0a0ae7a14bf8a /Lib/test/regrtest.py
parent52328165c52d775d336968b40da9619f5f7f677a (diff)
downloadcpython-1a4d77b2527ced1052b4faae3d176b125a764325.zip
cpython-1a4d77b2527ced1052b4faae3d176b125a764325.tar.gz
cpython-1a4d77b2527ced1052b4faae3d176b125a764325.tar.bz2
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.
Diffstat (limited to 'Lib/test/regrtest.py')
-rwxr-xr-xLib/test/regrtest.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index dadf69b..60bc6c6 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -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):