[PATCH 013 of 179 tests-refactor] run-tests: capture reference output in TestResult class

Gregory Szorc gregory.szorc at gmail.com
Fri May 2 13:37:30 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397941786 25200
#      Sat Apr 19 14:09:46 2014 -0700
# Branch stable
# Node ID 020837217a5004ee99186e2e0002f8a7480a4b26
# Parent  eb3f807fc79740895e93eaa39ca1dee890a51173
run-tests: capture reference output in TestResult class

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -552,17 +552,17 @@ class Test(object):
         self.threadtmp = os.path.join(HGTMP, 'child%d' % count)
         os.mkdir(self.threadtmp)
 
         self._testtmp = os.path.join(self.threadtmp, os.path.basename(path))
         os.mkdir(self._testtmp)
 
         self._setreplacements(count)
 
-    def run(self, result):
+    def run(self, result, refpath):
         env = self._getenv()
         createhgrc(env['HGRCPATH'], self._options)
 
         starttime = time.time()
 
         def updateduration():
             result.duration = time.time() - starttime
 
@@ -575,16 +575,27 @@ class Test(object):
             updateduration()
             result.interrupted = True
         except Exception, e:
             updateduration()
             result.exception = e
 
         killdaemons(env['DAEMON_PIDS'])
 
+        # If we're not in --debug mode and reference output file exists,
+        # check test output against it.
+        if self._options.debug:
+            result.refout = None # to match "out is None"
+        elif os.path.exists(refpath):
+            f = open(refpath, 'r')
+            result.refout = f.read().splitlines(True)
+            f.close()
+        else:
+            result.refout = []
+
     def _run(self, replacements, env):
         raise NotImplemented('Subclasses must implement Test.run()')
 
     def _setreplacements(self, count):
         port = self._options.port + count * 3
         r = [
             (r':%s\b' % port, ':$HGPORT'),
             (r':%s\b' % (port + 1), ':$HGPORT1'),
@@ -641,16 +652,17 @@ class TestResult(object):
     """Holds the result of a test execution."""
 
     def __init__(self):
         self.ret = None
         self.out = None
         self.duration = None
         self.interrupted = False
         self.exception = None
+        self.refout = None
 
     @property
     def skipped(self):
         """Whether the test was skipped."""
         return self.ret == SKIPPED_STATUS
 
 def pytest(test, wd, options, replacements, env):
     py3kswitch = options.py3k_warnings and ' -3' or ''
@@ -1048,43 +1060,33 @@ def runone(options, test, count):
 
     vlog("# Test", test)
 
     if os.path.exists(err):
         os.remove(err)       # Remove any previous output files
 
     t = runner(testpath, options, count)
     res = TestResult()
-    t.run(res)
+    t.run(res, ref)
 
     if res.interrupted:
         log('INTERRUPTED: %s (after %d seconds)' % (test, res.duration))
         raise KeyboardInterrupt()
 
     if res.exception:
         return fail('Exception during execution: %s' % res.exception, 255)
 
     ret = res.ret
     out = res.out
 
     times.append((test, res.duration))
     vlog("# Ret was:", ret)
 
     skipped = res.skipped
-
-    # If we're not in --debug mode and reference output file exists,
-    # check test output against it.
-    if options.debug:
-        refout = None                   # to match "out is None"
-    elif os.path.exists(ref):
-        f = open(ref, "r")
-        refout = f.read().splitlines(True)
-        f.close()
-    else:
-        refout = []
+    refout = res.refout
 
     if (ret != 0 or out != refout) and not skipped and not options.debug:
         # Save errors to a file for diagnosis
         f = open(err, "wb")
         for line in out:
             f.write(line)
         f.close()
 


More information about the Mercurial-devel mailing list