Merge with stable
authorChristian Ebert <blacktrash@gmx.net>
Sat, 12 Apr 2014 18:13:57 +0100
changeset 1367 b3bee8727631
parent 1362 a5dabff2e764 (current diff)
parent 1366 987a80dec7db (diff)
child 1371 3b0bcc658eef
Merge with stable
--- a/tests/run-tests.py	Sat Mar 22 08:44:07 2014 +0000
+++ b/tests/run-tests.py	Sat Apr 12 18:13:57 2014 +0100
@@ -133,7 +133,7 @@
         f.close()
     return entries
 
-def parseargs():
+def getparser():
     parser = optparse.OptionParser("%prog [options] [tests]")
 
     # keep these sorted
@@ -210,7 +210,11 @@
     for option, (envvar, default) in defaults.items():
         defaults[option] = type(default)(os.environ.get(envvar, default))
     parser.set_defaults(**defaults)
-    (options, args) = parser.parse_args()
+
+    return parser
+
+def parseargs(args, parser):
+    (options, args) = parser.parse_args(args)
 
     # jython is always pure
     if 'java' in sys.platform or '__pypy__' in sys.modules:
@@ -935,7 +939,7 @@
                 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):
@@ -1176,8 +1180,9 @@
 testtypes = [('.py', pytest, '.out'),
              ('.t', tsttest, '')]
 
-def main():
-    (options, args) = parseargs()
+def main(args, parser=None):
+    parser = parser or getparser()
+    (options, args) = parseargs(args, parser)
     os.umask(022)
 
     checktools()
@@ -1192,8 +1197,8 @@
             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)
@@ -1228,7 +1233,8 @@
             # Meaning of tmpdir has changed since 1.3: we used to create
             # HGTMP inside tmpdir; now HGTMP is tmpdir.  So fail if
             # tmpdir already exists.
-            sys.exit("error: temp dir %r already exists" % tmpdir)
+            print "error: temp dir %r already exists" % tmpdir
+            return 1
 
             # Automatically removing tmpdir sounds convenient, but could
             # really annoy anyone in the habit of using "--tmpdir=/tmp"
@@ -1293,10 +1299,10 @@
     vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
 
     try:
-        sys.exit(runtests(options, tests) or 0)
+        return runtests(options, tests) or 0
     finally:
         time.sleep(.1)
         cleanup(options)
 
 if __name__ == '__main__':
-    main()
+    sys.exit(main(sys.argv[1:]))