Bug 1289444 - Forward extra arguments in |mach test| to the underlying test commands, r=chmanchester
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 29 Aug 2017 16:20:47 -0400
changeset 378007 dcfe07e76532f5bf63cfb1794f36fc5042c96117
parent 378006 9db0cec976bb86a73dd2e500e4692d3ec3478b32
child 378008 a7db9780ad982c8cf3c3581ec25b47d9e8ef003b
push id32421
push userarchaeopteryx@coole-files.de
push dateFri, 01 Sep 2017 08:31:26 +0000
treeherdermozilla-central@583e73fb8e3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1289444
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1289444 - Forward extra arguments in |mach test| to the underlying test commands, r=chmanchester MozReview-Commit-ID: 631K2n0wB1a
python/mach/mach/registrar.py
testing/mach_commands.py
--- a/python/mach/mach/registrar.py
+++ b/python/mach/mach/registrar.py
@@ -111,16 +111,22 @@ class MachRegistrar(object):
 
         if handler.parser:
             parser = handler.parser
 
             # save and restore existing defaults so **kwargs don't persist across
             # subsequent invocations of Registrar.dispatch()
             old_defaults = parser._defaults.copy()
             parser.set_defaults(**kwargs)
-            kwargs, _ = parser.parse_known_args(argv or [])
+            kwargs, unknown = parser.parse_known_args(argv or [])
             kwargs = vars(kwargs)
             parser._defaults = old_defaults
 
+            if unknown:
+                if subcommand:
+                    name = '{} {}'.format(name, subcommand)
+                parser.error("unrecognized arguments for {}: {}".format(
+                    name, ', '.join(["'{}'".format(arg) for arg in unknown])))
+
         return self._run_command_handler(handler, context=context, **kwargs)
 
 
 Registrar = MachRegistrar()
--- a/testing/mach_commands.py
+++ b/testing/mach_commands.py
@@ -196,17 +196,21 @@ The following test suites and aliases ar
 TEST_HELP = TEST_HELP.strip()
 
 
 @CommandProvider
 class Test(MachCommandBase):
     @Command('test', category='testing',
              description='Run tests (detects the kind of test and runs it).')
     @CommandArgument('what', default=None, nargs='*', help=TEST_HELP)
-    def test(self, what):
+    @CommandArgument('extra_args', default=None, nargs=argparse.REMAINDER,
+                     help="Extra arguments to pass to the underlying test command(s). "
+                          "If an underlying command doesn't recognize the argument, it "
+                          "will fail.")
+    def test(self, what, extra_args):
         """Run tests from names or paths.
 
         mach test accepts arguments specifying which tests to run. Each argument
         can be:
 
         * The path to a test file
         * A directory containing tests
         * A test suite name
@@ -300,17 +304,17 @@ class Test(MachCommandBase):
 
         status = None
         for suite_name in run_suites:
             suite = TEST_SUITES[suite_name]
 
             if 'mach_command' in suite:
                 res = self._mach_context.commands.dispatch(
                     suite['mach_command'], self._mach_context,
-                    **suite['kwargs'])
+                    argv=extra_args, **suite['kwargs'])
                 if res:
                     status = res
 
         buckets = {}
         for test in run_tests:
             key = (test['flavor'], test.get('subsuite', ''))
             buckets.setdefault(key, []).append(test)
 
@@ -326,17 +330,17 @@ class Test(MachCommandBase):
                 status = 1
                 continue
 
             kwargs = dict(m['kwargs'])
             kwargs['subsuite'] = subsuite
 
             res = self._mach_context.commands.dispatch(
                 m['mach_command'], self._mach_context,
-                test_objects=tests, **kwargs)
+                argv=extra_args, test_objects=tests, **kwargs)
             if res:
                 status = res
 
         return status
 
 
 @CommandProvider
 class MachCommands(MachCommandBase):