Bug 537302: allow jstests shell harness to run from any directory, r=jorendorff

This commit is contained in:
David Mandelin 2010-01-06 14:05:41 -08:00
Родитель edf4668bd6
Коммит 52a7627592
2 изменённых файлов: 27 добавлений и 6 удалений

Просмотреть файл

@ -196,7 +196,7 @@ if __name__ == '__main__':
help='hide progress bar')
op.add_option('-j', '--worker-count', dest='worker_count', type=int, default=2,
help='number of worker threads to run tests on (default 2)')
op.add_option('-m', '--manifest', dest='manifest', default='jstests.list',
op.add_option('-m', '--manifest', dest='manifest',
help='select manifest file')
op.add_option('-t', '--timeout', dest='timeout', type=float, default=60.0,
help='set test timeout in seconds')
@ -225,6 +225,9 @@ if __name__ == '__main__':
JS, args = None, []
else:
JS, args = args[0], args[1:]
# Convert to an absolute path so we can run JS from a different directory.
if JS is not None:
JS = os.path.abspath(JS)
if OPTIONS.debug:
if OPTIONS.valgrind:
@ -253,6 +256,17 @@ if __name__ == '__main__':
output_file == sys.stdout or OPTIONS.tinderbox):
OPTIONS.hide_progress = True
if OPTIONS.manifest is None:
filenames = ('jstests.list',
os.path.join(os.path.dirname(__file__), 'jstests.list'))
for filename in filenames:
if os.path.isfile(filename):
OPTIONS.manifest = filename
break
if OPTIONS.manifest is None:
print >> sys.stderr, 'no manifest file given and defaults not found'
sys.exit(2)
import manifest
if JS is None:
xul_tester = manifest.NullXULInfoTester()
@ -306,8 +320,13 @@ if __name__ == '__main__':
if not test_list:
print 'no tests selected'
else:
curdir = os.getcwd()
os.chdir(os.path.dirname(OPTIONS.manifest))
try:
results = ResultsSink()
run_tests(test_list, results)
finally:
os.chdir(curdir)
if output_file != sys.stdout:
output_file.close()

Просмотреть файл

@ -84,7 +84,7 @@ class NullXULInfoTester:
def test(self, cond):
return False
def parse(filename, xul_tester):
def parse(filename, xul_tester, reldir = ''):
ans = []
comment_re = re.compile(r'#.*')
dir = os.path.dirname(filename)
@ -99,7 +99,9 @@ def parse(filename, xul_tester):
sline = comment_re.sub('', line)
parts = sline.split()
if parts[0] == 'include':
ans += parse(os.path.join(dir, parts[1]), xul_tester)
include_file = parts[1]
include_reldir = os.path.join(reldir, os.path.dirname(include_file))
ans += parse(os.path.join(dir, include_file), xul_tester, include_reldir)
elif parts[0] == 'url-prefix':
# Doesn't apply to shell tests
pass
@ -143,6 +145,6 @@ def parse(filename, xul_tester):
pos += 1
assert script is not None
ans.append(TestCase(os.path.join(dir, script),
ans.append(TestCase(os.path.join(reldir, script),
enable, expect, random))
return ans