Bug 799291 - Part 1: Move mach commands for test running into test runners; r=jhammel
authorGregory Szorc <gps@mozilla.com>
Wed, 10 Oct 2012 11:08:09 -0700
changeset 109900 428846e73299df3194ebb8a9172429e2356704ee
parent 109899 2a0e2af364bc635500fc8fe7129b217119c5ff03
child 109901 ce9274758544625d80b43e2d5229f03a8bc8c871
push id16266
push usereakhgari@mozilla.com
push dateThu, 11 Oct 2012 00:21:19 +0000
treeherdermozilla-inbound@21e0f119b3d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhammel
bugs799291
milestone19.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 799291 - Part 1: Move mach commands for test running into test runners; r=jhammel The code interacting with the test runners now resides in closer proximity to the code it is invoking. We also purge testing functionality from mozbuild, which is where it never really belonged.
layout/tools/reftest/mach_commands.py
mach
python/mozbuild/mach/commands/testing.py
python/mozbuild/mozbuild/testing/mochitest.py
python/mozbuild/mozbuild/testing/reftest.py
python/mozbuild/mozbuild/testing/xpcshell.py
testing/mochitest/mach_commands.py
testing/xpcshell/mach_commands.py
rename from python/mozbuild/mozbuild/testing/reftest.py
rename to layout/tools/reftest/mach_commands.py
--- a/python/mozbuild/mozbuild/testing/reftest.py
+++ b/layout/tools/reftest/mach_commands.py
@@ -1,18 +1,29 @@
 # 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
 
 import os
 
+from mozbuild.base import MozbuildObject
 from mozbuild.testing.test import TestRunner
 
+from mach.base import (
+    CommandArgument,
+    CommandProvider,
+    Command,
+)
+
+
+generic_help = 'Test to run. Can be specified as a single file, a ' +\
+'directory, or omitted. If omitted, the entire test suite is executed.'
+
 
 class ReftestRunner(TestRunner):
     """Easily run reftests.
 
     This currently contains just the basics for running reftests. We may want
     to hook up result parsing, etc.
     """
 
@@ -55,8 +66,29 @@ class ReftestRunner(TestRunner):
             if not os.path.exists(path):
                 raise Exception('No manifest file was found at %s.' % path)
             env = {'TEST_PATH': path}
         else:
             env = {}
 
         # TODO hook up harness via native Python
         self._run_make(directory='.', target=suite, append_env=env)
+
+
+@CommandProvider
+class MachCommands(MozbuildObject):
+    @Command('reftest', help='Run a reftest.')
+    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
+        help=generic_help)
+    def run_reftest(self, test_file):
+        self._run_reftest(test_file, 'reftest')
+
+    @Command('crashtest', help='Run a crashtest.')
+    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
+        help=generic_help)
+    def run_crashtest(self, test_file):
+        self._run_reftest(test_file, 'crashtest')
+
+    def _run_reftest(self, test_file, flavor):
+        reftest = self._spawn(ReftestRunner)
+        reftest.run_reftest_test(test_file, flavor)
+
+
--- a/mach
+++ b/mach
@@ -28,21 +28,32 @@ SEARCH_PATHS = [
     'python/which',
     'other-licenses/ply',
     'xpcom/idl-parser',
     'testing/xpcshell',
     'testing/mozbase/mozprocess',
     'testing/mozbase/mozinfo',
 ]
 
+# Individual files providing mach commands.
+MACH_MODULES = [
+    'layout/tools/reftest/mach_commands.py',
+    'testing/mochitest/mach_commands.py',
+    'testing/xpcshell/mach_commands.py',
+]
+
 our_dir = os.path.dirname(os.path.abspath(__file__))
 
 try:
     import mach.main
 except ImportError:
     sys.path[0:0] = [os.path.join(our_dir, path) for path in SEARCH_PATHS]
 
     import mach.main
 
 # All of the code is in a module because EVERYTHING IS A LIBRARY.
 mach = mach.main.Mach(our_dir)
 mach.load_commands_from_sys_path()
+
+for path in MACH_MODULES:
+    mach.load_commands_from_file(os.path.join(our_dir, path))
+
 sys.exit(mach.run(sys.argv[1:]))
--- a/python/mozbuild/mach/commands/testing.py
+++ b/python/mozbuild/mach/commands/testing.py
@@ -24,67 +24,9 @@ class Testing(MozbuildObject):
     @CommandArgument('suite', default='all', choices=suites, nargs='?',
         help='Test suite to run.')
     def run_suite(self, suite):
         from mozbuild.testing.suite import Suite
 
         s = self._spawn(Suite)
         s.run_suite(suite)
 
-    @Command('mochitest-plain', help='Run a plain mochitest.')
-    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
-        help=generic_help)
-    def run_mochitest_plain(self, test_file):
-        self.run_mochitest(test_file, 'plain')
 
-    @Command('mochitest-chrome', help='Run a chrome mochitest.')
-    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
-        help=generic_help)
-    def run_mochitest_chrome(self, test_file):
-        self.run_mochitest(test_file, 'chrome')
-
-    @Command('mochitest-browser', help='Run a mochitest with browser chrome.')
-    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
-        help=generic_help)
-    def run_mochitest_browser(self, test_file):
-        self.run_mochitest(test_file, 'browser')
-
-    @Command('mochitest-a11y', help='Run an a11y mochitest.')
-    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
-        help=generic_help)
-    def run_mochitest_a11y(self, test_file):
-        self.run_mochitest(test_file, 'a11y')
-
-    def run_mochitest(self, test_file, flavor):
-        from mozbuild.testing.mochitest import MochitestRunner
-
-        mochitest = self._spawn(MochitestRunner)
-        mochitest.run_mochitest_test(test_file, flavor)
-
-    @Command('reftest', help='Run a reftest.')
-    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
-        help=generic_help)
-    def run_reftest(self, test_file):
-        self._run_reftest(test_file, 'reftest')
-
-    @Command('crashtest', help='Run a crashtest.')
-    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
-        help=generic_help)
-    def run_crashtest(self, test_file):
-        self._run_reftest(test_file, 'crashtest')
-
-    def _run_reftest(self, test_file, flavor):
-        from mozbuild.testing.reftest import ReftestRunner
-
-        reftest = self._spawn(ReftestRunner)
-        reftest.run_reftest_test(test_file, flavor)
-
-    @Command('xpcshell-test', help='Run an xpcshell test.')
-    @CommandArgument('test_file', default='all', nargs='?', metavar='TEST',
-        help=generic_help)
-    @CommandArgument('--debug', '-d', action='store_true',
-        help='Run test in a debugger.')
-    def run_xpcshell_test(self, **params):
-        from mozbuild.testing.xpcshell import XPCShellRunner
-
-        xpcshell = self._spawn(XPCShellRunner)
-        xpcshell.run_test(**params)
-
rename from python/mozbuild/mozbuild/testing/mochitest.py
rename to testing/mochitest/mach_commands.py
--- a/python/mozbuild/mozbuild/testing/mochitest.py
+++ b/testing/mochitest/mach_commands.py
@@ -1,18 +1,29 @@
 # 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/.
+# 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
 
 import os
 
+from mozbuild.base import MozbuildObject
 from mozbuild.testing.test import TestRunner
 
+from mach.base import (
+    CommandArgument,
+    CommandProvider,
+    Command,
+)
+
+
+generic_help = 'Test to run. Can be specified as a single file, a ' +\
+'directory, or omitted. If omitted, the entire test suite is executed.'
+
 
 class MochitestRunner(TestRunner):
     """Easily run mochitests.
 
     This currently contains just the basics for running mochitests. We may want
     to hook up result parsing, etc.
     """
     def run_plain_suite(self):
@@ -63,8 +74,39 @@ class MochitestRunner(TestRunner):
             path = self._parse_test_path(test_file)['normalized']
             if not os.path.exists(path):
                 raise Exception('No manifest file was found at %s.' % path)
             env = {'TEST_PATH': path}
         else:
             env = {}
 
         self._run_make(directory='.', target=target, append_env=env)
+
+
+@CommandProvider
+class MachCommands(MozbuildObject):
+    @Command('mochitest-plain', help='Run a plain mochitest.')
+    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
+        help=generic_help)
+    def run_mochitest_plain(self, test_file):
+        self.run_mochitest(test_file, 'plain')
+
+    @Command('mochitest-chrome', help='Run a chrome mochitest.')
+    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
+        help=generic_help)
+    def run_mochitest_chrome(self, test_file):
+        self.run_mochitest(test_file, 'chrome')
+
+    @Command('mochitest-browser', help='Run a mochitest with browser chrome.')
+    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
+        help=generic_help)
+    def run_mochitest_browser(self, test_file):
+        self.run_mochitest(test_file, 'browser')
+
+    @Command('mochitest-a11y', help='Run an a11y mochitest.')
+    @CommandArgument('test_file', default=None, nargs='?', metavar='TEST',
+        help=generic_help)
+    def run_mochitest_a11y(self, test_file):
+        self.run_mochitest(test_file, 'a11y')
+
+    def run_mochitest(self, test_file, flavor):
+        mochitest = self._spawn(MochitestRunner)
+        mochitest.run_mochitest_test(test_file, flavor)
rename from python/mozbuild/mozbuild/testing/xpcshell.py
rename to testing/xpcshell/mach_commands.py
--- a/python/mozbuild/mozbuild/testing/xpcshell.py
+++ b/testing/xpcshell/mach_commands.py
@@ -1,22 +1,28 @@
 # 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/.
+# 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/.
 
-# This modules contains code for interacting with xpcshell tests.
+# Integrates the xpcshell test runner with mach.
 
 from __future__ import unicode_literals
 
-import os.path
+import os
 
 from StringIO import StringIO
 
 from mozbuild.base import MozbuildObject
 
+from mach.base import (
+    CommandArgument,
+    CommandProvider,
+    Command,
+)
+
 
 class XPCShellRunner(MozbuildObject):
     """Run xpcshell tests."""
     def run_suite(self):
         # TODO hook up to harness runner and support things like shuffle,
         # proper progress updates, etc.
         self._run_make(directory='.', target='xpcshell-tests')
 
@@ -84,8 +90,22 @@ class XPCShellRunner(MozbuildObject):
 
         if test_path is not None:
             args['testPath'] = test_path
 
         # TODO do something with result.
         xpcshell.runTests(**args)
 
         self.log_manager.disable_unstructured()
+
+
+@CommandProvider
+class MachCommands(MozbuildObject):
+    @Command('xpcshell-test', help='Run an xpcshell test.')
+    @CommandArgument('test_file', default='all', nargs='?', metavar='TEST',
+        help='Test to run. Can be specified as a single JS file, a directory, '
+             'or omitted. If omitted, the entire test suite is executed.')
+    @CommandArgument('--debug', '-d', action='store_true',
+        help='Run test in a debugger.')
+    def run_xpcshell_test(self, **params):
+        xpcshell = self._spawn(XPCShellRunner)
+        xpcshell.run_test(**params)
+