auto merge of #4229 : mttr/servo/mach_unit_test_select_component, r=Manishearth

Example usage:

`./mach test-unit -c style`
This commit is contained in:
bors-servo 2014-12-06 04:49:00 -07:00
commit 2d0e96e133

View file

@ -36,7 +36,9 @@ class MachCommands(CommandBase):
for filename in target_contents: for filename in target_contents:
if filename.startswith(prefix + "-"): if filename.startswith(prefix + "-"):
filepath = path.join( filepath = path.join(
self.context.topdir, "components", "servo", "target", filename) self.context.topdir, "components", "servo",
"target", filename)
if path.isfile(filepath) and os.access(filepath, os.X_OK): if path.isfile(filepath) and os.access(filepath, os.X_OK):
return filepath return filepath
@ -94,11 +96,11 @@ class MachCommands(CommandBase):
@Command('test-unit', @Command('test-unit',
description='Run unit tests', description='Run unit tests',
category='testing') category='testing')
@CommandArgument('test_name', default=None, nargs="...", @CommandArgument('--component', '-c', default=None,
help="Specific component to test")
@CommandArgument('test_name', nargs=argparse.REMAINDER,
help="Only run tests that match this pattern") help="Only run tests that match this pattern")
def test_unit(self, test_name=None): def test_unit(self, test_name, component=None):
if test_name is None:
test_name = []
self.ensure_bootstrapped() self.ensure_bootstrapped()
self.ensure_built_tests() self.ensure_built_tests()
@ -106,12 +108,15 @@ class MachCommands(CommandBase):
def cargo_test(component): def cargo_test(component):
return 0 != subprocess.call( return 0 != subprocess.call(
["cargo", "test", "-p", component] + test_name, ["cargo", "test", "-p", component]
env=self.build_env(), cwd=self.servo_crate()) + test_name, env=self.build_env(), cwd=self.servo_crate())
for component in os.listdir("components"): if component is not None:
if component != "servo": ret = ret or cargo_test(component)
ret = ret or cargo_test(component) else:
for c in os.listdir("components"):
if c != "servo":
ret = ret or cargo_test(c)
return ret return ret