Patchwork [031,of,179,tests-refactor] run-tests: move output difference processing to Test.run()

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

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397965978 25200
#      Sat Apr 19 20:52:58 2014 -0700
# Branch stable
# Node ID 2d0503771b51eb8516f7b629ec7e12b092359e5b
# Parent  0f3a03707e6879ff0b2149724966f8806426c446
run-tests: move output difference processing 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
@@ -612,16 +612,21 @@  class Test(object):
 
         killdaemons(env['DAEMON_PIDS'])
 
         result.refout = self._refout
 
         if not self._options.keep_tmpdir:
             shutil.rmtree(testtmp)
 
+        def describe(ret):
+            if ret < 0:
+                return 'killed by signal: %d' % -ret
+            return 'returned error code %d' % ret
+
         if ret == SKIPPED_STATUS:
             if out is None: # Debug mode, nothing to parse.
                 missing = ['unknown']
                 failed = None
             else:
                 missing, failed = parsehghaveoutput(out)
 
             if not missing:
@@ -630,16 +635,36 @@  class Test(object):
             if failed:
                 return self.fail('hg have failed checking for %s' % failed[-1],
                                  ret)
             else:
                 result.skipped = True
                 return self.skip(missing[-1])
         elif ret == 'timeout':
             return self.fail('timed out', ret)
+        elif out != self._refout:
+            info = {}
+            if not self._options.nodiff:
+                iolock.acquire()
+                if self._options.view:
+                    os.system("%s %s %s" % (self._options.view, self._refpath,
+                                            self._errpath))
+                else:
+                    info = showdiff(self._refout, out, self._refpath,
+                                    self._errpath)
+                iolock.release()
+            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)
 
     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'),
@@ -1072,21 +1097,16 @@  def runone(options, test, count):
     def skip(msg):
         if options.verbose:
             log("\nSkipping %s: %s" % (testpath, msg))
         return 's', test, msg
 
     def ignore(msg):
         return 'i', test, msg
 
-    def describe(ret):
-        if ret < 0:
-            return 'killed by signal %d' % -ret
-        return 'returned error code %d' % ret
-
     testpath = os.path.join(TESTDIR, test)
     err = os.path.join(TESTDIR, test + ".err")
     lctest = test.lower()
 
     if not os.path.exists(testpath):
             return skip("doesn't exist")
 
     if not (options.whitelisted and test in options.whitelisted):
@@ -1138,32 +1158,16 @@  def runone(options, test, count):
         # Save errors to a file for diagnosis
         f = open(err, "wb")
         for line in out:
             f.write(line)
         f.close()
 
     if result:
         pass
-    elif out != refout:
-        info = {}
-        if not options.nodiff:
-            iolock.acquire()
-            if options.view:
-                os.system("%s %s %s" % (options.view, ref, err))
-            else:
-                info = showdiff(refout, out, ref, err)
-            iolock.release()
-        msg = ""
-        if info.get('servefail'): msg += "serve failed and "
-        if ret:
-            msg += "output changed and " + describe(ret)
-        else:
-            msg += "output changed"
-        result = t.fail(msg, ret)
     elif ret:
         result = t.fail(describe(ret), ret)
     else:
         result = t.success()
 
     if not options.verbose:
         iolock.acquire()
         sys.stdout.write(result[0])