run-tests: refactor runone() into gettest() and scheduletests()
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 19 Apr 2014 22:02:55 -0700
changeset 21339 de25e968b4d8
parent 21338 3cd2d2de4060
child 21340 fda36de1cb0e
run-tests: refactor runone() into gettest() and scheduletests() runone() has been removed. Replacing it are gettest() (which returns a Test instance) and a small amount of boilerplate in scheduletests().
tests/run-tests.py
--- a/tests/run-tests.py	Sat Apr 19 21:53:15 2014 -0700
+++ b/tests/run-tests.py	Sat Apr 19 22:02:55 2014 -0700
@@ -708,7 +708,8 @@
         return res
 
     def _run(self, testtmp, replacements, env):
-        raise NotImplemented('Subclasses must implement Test.run()')
+        # This should be implemented in child classes to run tests.
+        return self._skip('unknown test type')
 
     def _getreplacements(self, testtmp):
         port = self._options.port + self._count * 3
@@ -1083,6 +1084,26 @@
                 return '+glob'
         return False
 
+def gettest(testdir, test, options, count):
+    """Obtain a Test by looking at its filename.
+
+    Returns a Test instance. The Test may not be runnable if it doesn't map
+    to a known type.
+    """
+
+    lctest = test.lower()
+    refpath = os.path.join(testdir, test)
+
+    runner = Test
+
+    for ext, cls, out in testtypes:
+        if lctest.endswith(ext):
+            runner = cls
+            refpath = os.path.join(testdir, test + out)
+            break
+
+    return runner(testdir, test, options, count, refpath)
+
 wifexited = getattr(os, "WIFEXITED", lambda x: False)
 def run(cmd, wd, options, replacements, env):
     """Run command in a sub-process, capturing the output (stdout and stderr).
@@ -1129,31 +1150,6 @@
         output = re.sub(s, r, output)
     return ret, output.splitlines(True)
 
-def runone(options, test, count):
-    '''returns a result element: (code, test, msg)'''
-
-    def skip(msg):
-        if options.verbose:
-            log("\nSkipping %s: %s" % (testpath, msg))
-        return 's', test, msg
-
-    lctest = test.lower()
-
-    for ext, cls, out in testtypes:
-        if lctest.endswith(ext):
-            runner = cls
-            ref = os.path.join(TESTDIR, test + out)
-            break
-    else:
-        return skip("unknown test type")
-
-    t = runner(TESTDIR, test, options, count, ref)
-    result = t.run()
-
-    t.cleanup()
-
-    return result
-
 _hgpath = None
 
 def _gethgpath():
@@ -1195,7 +1191,9 @@
 
     def job(test, count):
         try:
-            done.put(runone(options, test, count))
+            t = gettest(TESTDIR, test, options, count)
+            done.put(t.run())
+            t.cleanup()
         except KeyboardInterrupt:
             pass
         except: # re-raises