Teach regrtest how to pass on doctest failure msgs.  This is done via a
horridly inefficient hack in regrtest's Compare class, but it's about as
clean as can be:  regrtest has to set up the Compare instance before
importing a test module, and by the time the module *is* imported it's too
late to change that decision.  The good news is that the more tests we
convert to unittest and doctest, the less the inefficiency here matters.
Even now there are few tests with large expected-output files (the new
cost here is a Python-level call per .write() when there's an expected-
output file).
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 0e87131..53e8ae7 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -2,7 +2,6 @@
 
 import sys
 
-
 class Error(Exception):
     """Base class for regression test exceptions."""
 
@@ -22,6 +21,26 @@
 verbose = 1              # Flag set to 0 by regrtest.py
 use_resources = None       # Flag set to [] by regrtest.py
 
+# _output_comparison controls whether regrtest will try to compare stdout
+# with an expected-output file.  For straight regrtests, it should.
+# The doctest driver should set_output_comparison(0) for the duration, and
+# restore the old value when it's done.
+# Note that this control is in addition to verbose mode:  output will be
+# compared if and only if _output_comparison is true and verbose mode is
+# not in effect.
+_output_comparison = 1
+
+def set_output_comparison(newvalue):
+    global _output_comparison
+    oldvalue = _output_comparison
+    _output_comparison = newvalue
+    return oldvalue
+
+# regrtest's interface to _output_comparison.
+def suppress_output_comparison():
+    return not _output_comparison
+
+
 def unload(name):
     try:
         del sys.modules[name]
@@ -156,3 +175,29 @@
             raise TestFailed("errors occurred in %s.%s"
                              % (testclass.__module__, testclass.__name__))
         raise TestFailed(err)
+
+#=======================================================================
+# doctest driver.
+
+def run_doctest(module, verbosity=None):
+    """Run doctest on the given module.
+
+    If optional argument verbosity is not specified (or is None), pass
+    test_support's belief about verbosity on to doctest.  Else doctest
+    sys.argv for -v.
+    """
+
+    import doctest
+
+    if verbosity is None:
+        verbosity = verbose
+    else:
+        verbosity = None
+
+    oldvalue = set_output_comparison(0)
+    try:
+        f, t = doctest.testmod(module, verbose=verbosity)
+        if f:
+            raise TestFailed("%d of %d doctests failed" % (f, t))
+    finally:
+        set_output_comparison(oldvalue)