From a844ce74f9089b4efcdf0ea2af6ab113392d3179 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 30 Sep 2015 20:23:52 -0400 Subject: Allow `./mach test` and `./mach test-unit` to run unit tests with file path --- python/servo/testing_commands.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'python/servo/testing_commands.py') diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index db5c3795219..fd4308aaa18 100644 --- a/python/servo/testing_commands.py +++ b/python/servo/testing_commands.py @@ -10,6 +10,7 @@ from __future__ import print_function, unicode_literals import argparse +import re import sys import os import os.path as path @@ -90,7 +91,9 @@ class MachCommands(CommandBase): ("css", {"kwargs": {"release": release}, "paths": [path.abspath(path.join("tests", "wpt", "css-tests"))], "include_arg": "include"}), - ("unit", {}), + ("unit", {"kwargs": {}, + "paths": [path.abspath(path.join("tests", "unit"))], + "include_arg": "test_name"}) ]) suites_by_prefix = {path: k for k, v in suites.iteritems() if "paths" in v for path in v["paths"]} @@ -138,7 +141,7 @@ class MachCommands(CommandBase): category='testing') @CommandArgument('--package', '-p', default=None, help="Specific package to test") @CommandArgument('test_name', nargs=argparse.REMAINDER, - help="Only run tests that match this pattern") + help="Only run tests that match this pattern or file path") def test_unit(self, test_name=None, package=None): if test_name is None: test_name = [] @@ -146,13 +149,35 @@ class MachCommands(CommandBase): self.ensure_bootstrapped() if package: - packages = [package] + packages = {package} else: - packages = os.listdir(path.join(self.context.topdir, "tests", "unit")) + packages = set() + + test_patterns = [] + for test in test_name: + # add package if 'tests/unit/' + match = re.search("tests/unit/(\\w+)/?$", test) + if match: + packages.add(match.group(1)) + # add package & test if '/', 'tests/unit//.rs', or similar + elif re.search("\\w/\\w", test): + tokens = test.split("/") + packages.add(tokens[-2]) + test_prefix = tokens[-1] + if test_prefix.endswith(".rs"): + test_prefix = test_prefix[:-3] + test_prefix += "::" + test_patterns.append(test_prefix) + # add test as-is otherwise + else: + test_patterns.append(test) + + if not packages: + packages = set(os.listdir(path.join(self.context.topdir, "tests", "unit"))) for crate in packages: result = subprocess.call( - ["cargo", "test", "-p", "%s_tests" % crate] + test_name, + ["cargo", "test", "-p", "%s_tests" % crate] + test_patterns, env=self.build_env(), cwd=self.servo_crate()) if result != 0: return result -- cgit v1.2.3