[PATCH 4 of 4] run-tests: allow test paths in other directories

Gregory Szorc gregory.szorc at gmail.com
Tue Mar 25 00:12:56 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1395724357 25200
#      Mon Mar 24 22:12:37 2014 -0700
# Node ID 30d0d63c248995f9e981e25389d2e79bf7e5f96c
# Parent  9d7b3768e916df9eb4acbbbce6cb55b63f152b59
run-tests: allow test paths in other directories

Previously, test paths were assumed to be in the same directory and
wouldn't have a directory component. If a path with a directory
component was specified, it would be filtered out. This change allow
paths to contain directories. This in turn allows tests from other
directories to be executed.

Executing tests in other directories may break assumptions elsewhere in
the testing code. However, on initial glance, things appear to "just
work." This approach of running tests from other directories is
successfully being used at
https://hg.mozilla.org/hgcustom/version-control-tools/file/7085790ff3af/run-mercurial-tests.py

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -934,17 +934,17 @@ def runone(options, test, count):
             t = fp.read().lower() + test.lower()
             fp.close()
             for k in options.keywords.lower().split():
                 if k in t:
                     break
                 else:
                     return ignore("doesn't match keyword")
 
-    if not lctest.startswith("test-"):
+    if not os.path.basename(lctest).startswith("test-"):
         return skip("not a test file")
     for ext, func, out in testtypes:
         if lctest.endswith(ext):
             runner = func
             ref = os.path.join(TESTDIR, test + out)
             break
     else:
         return skip("unknown test type")
@@ -1192,18 +1192,18 @@ def main(args, parser=None):
             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 t.startswith("test-")
-             and (t.endswith(".py") or t.endswith(".t"))]
+             if os.path.basename(t).startswith("test-")
+                 and (t.endswith(".py") or t.endswith(".t"))]
 
     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