Bug 751795 - Part 3: Testing module; r=jhammel DONTBUILD (NPOTB)
authorGregory Szorc <gps@mozilla.com>
Wed, 26 Sep 2012 09:46:27 -0700
changeset 114406 2359243ee2b1abe3fdef4c9ceebce262912466ef
parent 114405 c9294c9df7c1b2b04a04d333728c0956be18f7e9
child 114407 212cf709135c0379d254036e7437c933b57fb607
child 114455 ff22c54142371c4e34f06d975df7f4494072f448
child 118902 2dd64ab621fc70fef90438a1497baf85ba41d5b1
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhammel
bugs751795
milestone18.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 751795 - Part 3: Testing module; r=jhammel DONTBUILD (NPOTB) mach can now run some tests.
python/mach/mach/main.py
python/mach/mach/testing.py
--- a/python/mach/mach/main.py
+++ b/python/mach/mach/main.py
@@ -15,20 +15,22 @@ import sys
 from mozbuild.base import BuildConfig
 from mozbuild.config import ConfigSettings
 from mozbuild.logger import LoggingManager
 
 # Import sub-command modules
 # TODO Bug 794509 do this via auto-discovery. Update README once this is
 # done.
 from mach.settings import Settings
+from mach.testing import Testing
 
 # Classes inheriting from ArgumentProvider that provide commands.
 HANDLERS = [
     Settings,
+    Testing,
 ]
 
 # Classes inheriting from ConfigProvider that provide settings.
 # TODO this should come from auto-discovery somehow.
 SETTINGS_PROVIDERS = [
     BuildConfig,
 ]
 
@@ -51,16 +53,17 @@ class Mach(object):
     USAGE = """%(prog)s subcommand [arguments]
 
 mach provides an interface to performing common developer tasks. You specify
 an action/sub-command and it performs it.
 
 Some common actions are:
 
     %(prog)s help      Show full help, including the list of all commands.
+    %(prog)s test      Run tests.
 
 To see more help for a specific action, run:
 
   %(prog)s <command> --help
 """
 
     def __init__(self, cwd):
         assert os.path.isdir(cwd)
new file mode 100644
--- /dev/null
+++ b/python/mach/mach/testing.py
@@ -0,0 +1,78 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import unicode_literals
+
+from mach.base import ArgumentProvider
+from mozbuild.base import MozbuildObject
+
+
+generic_help = 'Test to run. Can be specified as a single JS file, a ' +\
+'directory, or omitted. If omitted, the entire test suite is executed.'
+
+
+class Testing(MozbuildObject, ArgumentProvider):
+    """Provides commands for running tests."""
+
+    def run_suite(self, suite):
+        from mozbuild.testing.suite import Suite
+
+        s = self._spawn(Suite)
+        s.run_suite(suite)
+
+    def run_mochitest(self, test_file, flavor):
+        from mozbuild.testing.mochitest import MochitestRunner
+
+        mochitest = self._spawn(MochitestRunner)
+        mochitest.run_mochitest_test(test_file, flavor)
+
+    def run_xpcshell_test(self, **params):
+        from mozbuild.testing.xpcshell import XPCShellRunner
+
+        xpcshell = self._spawn(XPCShellRunner)
+        xpcshell.run_test(**params)
+
+    @staticmethod
+    def populate_argparse(parser):
+        # Whole suites.
+        group = parser.add_parser('test', help="Perform tests.")
+
+        suites = set(['xpcshell', 'mochitest-plain', 'mochitest-chrome',
+            'mochitest-browser', 'all'])
+
+        group.add_argument('suite', default='all', choices=suites, nargs='?',
+            help="Test suite to run.")
+
+        group.set_defaults(cls=Testing, method='run_suite', suite='all')
+
+        mochitest_plain = parser.add_parser('mochitest-plain',
+            help='Run a plain mochitest.')
+        mochitest_plain.add_argument('test_file', default='all', nargs='?',
+            metavar='TEST', help=generic_help)
+        mochitest_plain.set_defaults(cls=Testing, method='run_mochitest',
+            flavor='plain')
+
+        mochitest_chrome = parser.add_parser('mochitest-chrome',
+            help='Run a chrome mochitest.')
+        mochitest_chrome.add_argument('test_file', default='all', nargs='?',
+            metavar='TEST', help=generic_help)
+        mochitest_chrome.set_defaults(cls=Testing, method='run_mochitest',
+            flavor='chrome')
+
+        mochitest_browser = parser.add_parser('mochitest-browser',
+            help='Run a mochitest with browser chrome.')
+        mochitest_browser.add_argument('test_file', default='all', nargs='?',
+            metavar='TEST', help=generic_help)
+        mochitest_browser.set_defaults(cls=Testing, method='run_mochitest',
+            flavor='browser')
+
+        xpcshell = parser.add_parser('xpcshell-test',
+            help="Run an individual xpcshell test.")
+
+        xpcshell.add_argument('test_file', default='all', nargs='?',
+            metavar='TEST', help=generic_help)
+        xpcshell.add_argument('--debug', '-d', action='store_true',
+            help='Run test in debugger.')
+
+        xpcshell.set_defaults(cls=Testing, method='run_xpcshell_test')