diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-09-30 20:30:26 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-09-30 20:30:26 -0600 |
commit | 5d04f8dc8e59fea8ef49beb89af26089421ef748 (patch) | |
tree | b51d303c3a9302da3627f799f4912336a65a8bd4 /python/servo/testing_commands.py | |
parent | 520c907742afbb94085c6b5e62156a5457530010 (diff) | |
parent | a844ce74f9089b4efcdf0ea2af6ab113392d3179 (diff) | |
download | servo-5d04f8dc8e59fea8ef49beb89af26089421ef748.tar.gz servo-5d04f8dc8e59fea8ef49beb89af26089421ef748.zip |
Auto merge of #7809 - 6112:master, r=frewsxcv
Make `./mach test` work with unit tests
Fixes #7618.
Allows running a specific Rust test with one of:
```
./mach test tests/unit/net/http_loader.rs
./mach test-unit tests/unit/net/http_loader.rs
./mach test-unit tests/unit/net/http_loader
./mach test-unit net/http_loader
```
Allows running a whole package's tests with one of:
```
./mach test tests/unit/net
./mach test-unit tests/unit/net
```
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7809)
<!-- Reviewable:end -->
Diffstat (limited to 'python/servo/testing_commands.py')
-rw-r--r-- | python/servo/testing_commands.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/python/servo/testing_commands.py b/python/servo/testing_commands.py index a1f0899b7c3..e4c36236bd0 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/<package>' + match = re.search("tests/unit/(\\w+)/?$", test) + if match: + packages.add(match.group(1)) + # add package & test if '<package>/<test>', 'tests/unit/<package>/<test>.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 |