Patchwork [018,of,179,tests-refactor] run-tests: move t test execution from tsttest() to TTest.run()

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

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397946511 25200
#      Sat Apr 19 15:28:31 2014 -0700
# Branch stable
# Node ID 7905efbfa8e2a7004fe963716de583af00ae92d9
# Parent  944c8d8f054267dbdedeac9bdff7826ed4b9e8ed
run-tests: move t test execution from tsttest() to TTest.run()

After this patch, tsttest() only contains output/result processing.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -740,38 +740,17 @@  def linematch(el, l):
         if el.endswith(" (re)\n"):
             return rematch(el[:-6], l)
         if el.endswith(" (glob)\n"):
             return globmatch(el[:-8], l)
         if os.altsep and l.replace('\\', '/') == el:
             return '+glob'
     return False
 
-def tsttest(t, test, wd, options, replacements, env):
-    f = open(test)
-    tlines = f.readlines()
-    f.close()
-
-    salt, script, after, expected = t._parsetest(tlines, wd)
-
-    # Write out the script and execute it
-    name = wd + '.sh'
-    f = open(name, 'w')
-    for l in script:
-        f.write(l)
-    f.close()
-
-    cmd = '%s "%s"' % (options.shell, name)
-    vlog("# Running", cmd)
-    exitcode, output = run(cmd, wd, options, replacements, env)
-    # do not merge output if skipped, return hghave message instead
-    # similarly, with --debug, output is None
-    if exitcode == SKIPPED_STATUS or output is None:
-        return exitcode, output
-
+def tsttest(t, wd, options, salt, after, expected, exitcode, output):
     # Merge the script output back into a unified test
 
     warnonly = 1 # 1: not yet, 2: yes, 3: for sure not
     if exitcode != 0: # failure has been reported
         warnonly = 3 # set to "for sure not"
     pos = -1
     postout = []
     for l in output:
@@ -826,18 +805,40 @@  def tsttest(t, test, wd, options, replac
     if warnonly == 2:
         exitcode = False # set exitcode to warned
     return exitcode, postout
 
 class TTest(Test):
     """A "t test" is a test backed by a .t file."""
 
     def _run(self, testtmp, replacements, env):
-        return tsttest(self, self._path, testtmp, self._options, replacements,
-                       env)
+        f = open(self._path)
+        lines = f.readlines()
+        f.close()
+
+        salt, script, after, expected = self._parsetest(lines, testtmp)
+
+        # Write out the generated script.
+        fname = '%s.sh' % testtmp
+        f = open(fname, 'w')
+        for l in script:
+            f.write(l)
+        f.close()
+
+        cmd = '%s "%s"' % (self._options.shell, fname)
+        vlog("# Running", cmd)
+
+        exitcode, output = run(cmd, testtmp, self._options, replacements, env)
+        # Do not merge output if skipped. Return hghave message instead.
+        # Similarly, with --debug, output is None.
+        if exitcode == SKIPPED_STATUS or output is None:
+            return exitcode, output
+
+        return tsttest(self, testtmp, self._options, salt, after, expected,
+                       exitcode, output)
 
     def _hghave(self, reqs, testtmp):
         # TODO do something smarter when all other uses of hghave are gone.
         tdir = TESTDIR.replace('\\', '/')
         proc = Popen4('%s -c "%s/hghave %s"' %
                       (self._options.shell, tdir, ' '.join(reqs)),
                       testtmp, 0)
         stdout, stderr = proc.communicate()