Patchwork [039,of,179,tests-refactor] run-tests: move err file saving to Test.run()

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:37 p.m.
Message ID <502c9d9909022e802e28.1399055876@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4534/
State Accepted
Commit 6a90ecb6597a9e35b9867b0f9109e7b94dc4711e
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397967271 25200
#      Sat Apr 19 21:14:31 2014 -0700
# Branch stable
# Node ID 502c9d9909022e802e28e62760d2c219b6dc5051
# Parent  4f67c9dbb2bdc7d2a6b9978f5f40c5c6b13ab819
run-tests: move err file saving to Test.run()

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -633,18 +633,16 @@  class Test(object):
                                                         result.duration))
             raise
         except Exception, e:
             updateduration()
             return self.fail('Exception during execution: %s' % e, 255)
 
         killdaemons(env['DAEMON_PIDS'])
 
-        result.refout = self._refout
-
         if not options.keep_tmpdir:
             shutil.rmtree(testtmp)
 
         def describe(ret):
             if ret < 0:
                 return 'killed by signal: %d' % -ret
             return 'returned error code %d' % ret
 
@@ -654,23 +652,23 @@  class Test(object):
                 failed = None
             else:
                 missing, failed = parsehghaveoutput(out)
 
             if not missing:
                 missing = ['irrelevant']
 
             if failed:
-                return self.fail('hg have failed checking for %s' % failed[-1],
-                                 ret)
+                res = self.fail('hg have failed checking for %s' % failed[-1],
+                                ret)
             else:
                 result.skipped = True
-                return self.skip(missing[-1])
+                res = self.skip(missing[-1])
         elif ret == 'timeout':
-            return self.fail('timed out', ret)
+            res = self.fail('timed out', ret)
         elif out != self._refout:
             info = {}
             if not options.nodiff:
                 iolock.acquire()
                 if options.view:
                     os.system("%s %s %s" % (options.view, self._refpath,
                                             self._errpath))
                 else:
@@ -680,21 +678,30 @@  class Test(object):
             msg = ''
             if info.get('servefail'):
                 msg += 'serve failed and '
             if ret:
                 msg += 'output changed and ' + describe(ret)
             else:
                 msg += 'output changed'
 
-            return self.fail(msg, ret)
+            res = self.fail(msg, ret)
         elif ret:
-            return self.fail(describe(ret), ret)
+            res = self.fail(describe(ret), ret)
         else:
-            return self.success()
+            res = self.success()
+
+        if (ret != 0 or out != self._refout) and not result.skipped \
+            and not options.debug:
+            f = open(self._errpath, 'wb')
+            for line in out:
+                f.write(line)
+            f.close()
+
+        return res
 
     def _run(self, testtmp, replacements, env):
         raise NotImplemented('Subclasses must implement Test.run()')
 
     def _getreplacements(self, testtmp):
         port = self._options.port + self._count * 3
         r = [
             (r':%s\b' % port, ':$HGPORT'),
@@ -782,17 +789,16 @@  class Test(object):
 
 class TestResult(object):
     """Holds the result of a test execution."""
 
     def __init__(self):
         self.ret = None
         self.out = None
         self.duration = None
-        self.refout = None
         self.skipped = False
 
 class PythonTest(Test):
     """A Python-based test."""
     def _run(self, testtmp, replacements, env):
         py3kswitch = self._options.py3k_warnings and ' -3' or ''
         cmd = '%s%s "%s"' % (PYTHON, py3kswitch, self._path)
         vlog("# Running", cmd)
@@ -1150,26 +1156,16 @@  def runone(options, test, count):
     result = t.run(res)
 
     ret = res.ret
     out = res.out
 
     times.append((test, res.duration))
     vlog("# Ret was:", ret)
 
-    skipped = res.skipped
-    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()
-
     if not options.verbose:
         iolock.acquire()
         sys.stdout.write(result[0])
         sys.stdout.flush()
         iolock.release()
 
     del t # For cleanup side-effects.