mach: Extract suite_for_path()

This commit is contained in:
Andrew Shu 2016-06-03 18:41:14 -07:00
parent a5115c13fd
commit 7eac0a9e45

View file

@ -14,6 +14,7 @@ import re
import sys import sys
import os import os
import os.path as path import os.path as path
import copy
from collections import OrderedDict from collections import OrderedDict
from time import time from time import time
@ -35,6 +36,26 @@ PROJECT_TOPLEVEL_PATH = os.path.abspath(os.path.join(SCRIPT_PATH, "..", ".."))
WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "web-platform-tests") WEB_PLATFORM_TESTS_PATH = os.path.join("tests", "wpt", "web-platform-tests")
SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests") SERVO_TESTS_PATH = os.path.join("tests", "wpt", "mozilla", "tests")
TEST_SUITES = OrderedDict([
("tidy", {"kwargs": {"all_files": False, "no_progress": False, "self_test": False},
"include_arg": "include"}),
("wpt", {"kwargs": {"release": False},
"paths": [path.abspath(WEB_PLATFORM_TESTS_PATH),
path.abspath(SERVO_TESTS_PATH)],
"include_arg": "include"}),
("css", {"kwargs": {"release": False},
"paths": [path.abspath(path.join("tests", "wpt", "css-tests"))],
"include_arg": "include"}),
("unit", {"kwargs": {},
"paths": [path.abspath(path.join("tests", "unit"))],
"include_arg": "test_name"}),
("compiletest", {"kwargs": {"release": False},
"paths": [path.abspath(path.join("tests", "compiletest"))],
"include_arg": "test_name"})
])
TEST_SUITES_BY_PREFIX = {path: k for k, v in TEST_SUITES.iteritems() if "paths" in v for path in v["paths"]}
def create_parser_wpt(): def create_parser_wpt():
parser = wptcommandline.create_parser() parser = wptcommandline.create_parser()
@ -79,25 +100,12 @@ class MachCommands(CommandBase):
help="Run all test suites") help="Run all test suites")
def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, tidy_all=False, def test(self, params, render_mode=DEFAULT_RENDER_MODE, release=False, tidy_all=False,
no_progress=False, self_test=False, all_suites=False): no_progress=False, self_test=False, all_suites=False):
suites = OrderedDict([ suites = copy.deepcopy(TEST_SUITES)
("tidy", {"kwargs": {"all_files": tidy_all, "no_progress": no_progress, "self_test": self_test}, suites["tidy"]["kwargs"] = {"all_files": tidy_all, "no_progress": no_progress, "self_test": self_test}
"include_arg": "include"}), suites["wpt"]["kwargs"] = {"release": release}
("wpt", {"kwargs": {"release": release}, suites["css"]["kwargs"] = {"release": release}
"paths": [path.abspath(path.join("tests", "wpt", "web-platform-tests")), suites["unit"]["kwargs"] = {}
path.abspath(path.join("tests", "wpt", "mozilla"))], suites["compiletest"]["kwargs"] = {"release": release}
"include_arg": "include"}),
("css", {"kwargs": {"release": release},
"paths": [path.abspath(path.join("tests", "wpt", "css-tests"))],
"include_arg": "include"}),
("unit", {"kwargs": {},
"paths": [path.abspath(path.join("tests", "unit"))],
"include_arg": "test_name"}),
("compiletest", {"kwargs": {"release": release},
"paths": [path.abspath(path.join("tests", "compiletest"))],
"include_arg": "test_name"})
])
suites_by_prefix = {path: k for k, v in suites.iteritems() if "paths" in v for path in v["paths"]}
selected_suites = OrderedDict() selected_suites = OrderedDict()
@ -115,16 +123,14 @@ class MachCommands(CommandBase):
if arg in suites and arg not in selected_suites: if arg in suites and arg not in selected_suites:
selected_suites[arg] = [] selected_suites[arg] = []
found = True found = True
else:
elif os.path.exists(path.abspath(arg)): suite = self.suite_for_path(arg)
abs_path = path.abspath(arg) if suite is not None:
for prefix, suite in suites_by_prefix.iteritems(): if suite not in selected_suites:
if abs_path.startswith(prefix): selected_suites[suite] = []
if suite not in selected_suites: selected_suites[suite].append(arg)
selected_suites[suite] = [] found = True
selected_suites[suite].append(arg) break
found = True
break
if not found: if not found:
print("%s is not a valid test path or suite name" % arg) print("%s is not a valid test path or suite name" % arg)
@ -143,6 +149,15 @@ class MachCommands(CommandBase):
print("Tests completed in %0.2fs" % elapsed) print("Tests completed in %0.2fs" % elapsed)
# Helper to determine which test suite owns the path
def suite_for_path(self, path_arg):
if os.path.exists(path.abspath(path_arg)):
abs_path = path.abspath(path_arg)
for prefix, suite in TEST_SUITES_BY_PREFIX.iteritems():
if abs_path.startswith(prefix):
return suite
return None
@Command('test-unit', @Command('test-unit',
description='Run unit tests', description='Run unit tests',
category='testing') category='testing')