changeset 21363:00e5f5b9fc90

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 20 Apr 2014 00:23:06 -0700
parents ff4ce72cc8d6
children 558246fa98b8
files tests/run-tests.py
diffstat 1 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Sun Apr 20 00:12:26 2014 -0700
+++ b/tests/run-tests.py	Sun Apr 20 00:23:06 2014 -0700
@@ -1026,6 +1026,25 @@
         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:
@@ -1322,18 +1341,7 @@
 
     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)