[PATCH 068 of 179 tests-refactor] run-tests: move test discovery logic into a function

Gregory Szorc gregory.szorc at gmail.com
Fri May 2 18:38:25 UTC 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1397978586 25200
#      Sun Apr 20 00:23:06 2014 -0700
# Branch stable
# Node ID ffd38bfe92ba73742bf11d95f0215d46575b8034
# Parent  753aa4f617abdc39a66ba6499a9cf61b60fe3da8
run-tests: move test discovery logic into a function

The new function is easily monkeypatchable. This facilitates more
advanced test discovery by 3rd parties such as extensions.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1019,16 +1019,35 @@ class TestRunner(object):
             '!': [],
             '~': [],
             's': [],
             'i': [],
         }
         self.abort = [False]
         self._createdfiles = []
 
+    def findtests(self, args):
+        """Finds possible test files from arguments.
+
+        If you wish to inject custom tests into the test harness, this would
+        be a good function to monkeypatch or override in a derived class.
+        """
+        if not args:
+            if self.options.changed:
+                proc = Popen4('hg st --rev "%s" -man0 .' %
+                              self.options.changed, None, 0)
+                stdout, stderr = proc.communicate()
+                args = stdout.strip('\0').split('\0')
+            else:
+                args = os.listdir('.')
+
+        return [t for t in args
+                if os.path.basename(t).startswith('test-')
+                    and (t.endswith('.py') or t.endswith('.t'))]
+
     def runtests(self, tests):
         try:
             if self.inst:
                 self.installhg()
                 self.checkhglib("Testing")
             else:
                 self.usecorrectpython()
 
@@ -1315,28 +1334,17 @@ def main(args, parser=None):
 
     parser = parser or getparser()
     (options, args) = parseargs(args, parser)
     runner.options = options
     os.umask(022)
 
     checktools()
 
-    if not args:
-        if options.changed:
-            proc = Popen4('hg st --rev "%s" -man0 .' % options.changed,
-                          None, 0)
-            stdout, stderr = proc.communicate()
-            args = stdout.strip('\0').split('\0')
-        else:
-            args = os.listdir(".")
-
-    tests = [t for t in args
-             if os.path.basename(t).startswith("test-")
-                 and (t.endswith(".py") or t.endswith(".t"))]
+    tests = runner.findtests(args)
 
     if options.random:
         random.shuffle(tests)
     else:
         # keywords for slow tests
         slow = 'svn gendoc check-code-hg'.split()
         def sortkey(f):
             # run largest tests first, as they tend to take the longest



More information about the Mercurial-devel mailing list