@@ -920,36 +920,16 @@ class TTest(Test):
if el.endswith(" (re)\n"):
return TTest.rematch(el[:-6], l)
if el.endswith(" (glob)\n"):
return TTest.globmatch(el[:-8], l)
if os.altsep and l.replace('\\', '/') == el:
return '+glob'
return False
-def gettest(runner, test, 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(runner.testdir, test)
-
- testcls = Test
-
- for ext, cls, out in testtypes:
- if lctest.endswith(ext):
- testcls = cls
- refpath = os.path.join(runner.testdir, test + out)
- break
-
- return testcls(runner, test, 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).
Return a tuple (exitcode, output). output is None in debug mode."""
# TODO: Use subprocess.Popen if we're running on Python 2.4
if options.debug:
proc = subprocess.Popen(cmd, shell=True, cwd=wd, env=env)
ret = proc.wait()
@@ -1017,17 +997,17 @@ def scheduletests(runner, tests):
jobs = runner.options.jobs
done = queue.Queue()
running = 0
count = 0
global abort
def job(test, count):
try:
- t = gettest(runner, test, count)
+ t = runner.gettest(test, count)
done.put(t.run())
del t # For side-effects.
except KeyboardInterrupt:
pass
except: # re-raises
done.put(('!', test, 'run-test raised an error, see traceback'))
raise
@@ -1101,35 +1081,57 @@ def runtests(runner, tests):
failed = True
print "\ninterrupted!"
if failed:
return 1
if warned:
return 80
-testtypes = [('.py', PythonTest, '.out'),
- ('.t', TTest, '')]
-
class TestRunner(object):
"""Holds context for executing tests.
Tests rely on a lot of state. This object holds it for them.
"""
+
+ TESTTYPES = [
+ ('.py', PythonTest, '.out'),
+ ('.t', TTest, ''),
+ ]
+
def __init__(self):
self.options = None
self.testdir = None
self.hgtmp = None
self.inst = None
self.bindir = None
self.tmpbinddir = None
self.pythondir = None
self.coveragefile = None
self._createdfiles = []
+ def gettest(self, test, 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(self.testdir, test)
+
+ testcls = Test
+
+ for ext, cls, out in self.TESTTYPES:
+ if lctest.endswith(ext):
+ testcls = cls
+ refpath = os.path.join(self.testdir, test + out)
+ break
+
+ return testcls(self, test, count, refpath)
+
def cleanup(self):
"""Clean up state from this test invocation."""
if self.options.keep_tmpdir:
return
vlog("# Cleaning up HGTMP", self.hgtmp)
shutil.rmtree(self.hgtmp, True)