run-tests: capture reference output in TestResult class
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 19 Apr 2014 14:09:46 -0700
changeset 21308 935ade207253
parent 21307 cd4fd7b3c3c4
child 21309 0b123e6a318c
run-tests: capture reference output in TestResult class
tests/run-tests.py
--- a/tests/run-tests.py	Sat Apr 19 14:01:18 2014 -0700
+++ b/tests/run-tests.py	Sat Apr 19 14:09:46 2014 -0700
@@ -559,7 +559,7 @@
 
         self._setreplacements(count)
 
-    def run(self, result):
+    def run(self, result, refpath):
         env = self._getenv()
         createhgrc(env['HGRCPATH'], self._options)
 
@@ -582,6 +582,17 @@
 
         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()')
 
@@ -648,6 +659,7 @@
         self.duration = None
         self.interrupted = False
         self.exception = None
+        self.refout = None
 
     @property
     def skipped(self):
@@ -1055,7 +1067,7 @@
 
     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))
@@ -1071,17 +1083,7 @@
     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