Skip to content

Commit

Permalink
Bug 799291 - Part 1: Move mach commands for test running into test ru…
Browse files Browse the repository at this point in the history
…nners; 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.
  • Loading branch information
indygreg committed Oct 10, 2012
1 parent 1db6b49 commit 525b23f
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@

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.
Expand Down Expand Up @@ -60,3 +71,24 @@ def run_reftest_test(self, test_file=None, suite=None):

# 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)


11 changes: 11 additions & 0 deletions mach
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ SEARCH_PATHS = [
'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:
Expand All @@ -45,4 +52,8 @@ except ImportError:
# 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:]))
58 changes: 0 additions & 58 deletions python/mozbuild/mach/commands/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,62 +29,4 @@ def run_suite(self, 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)

Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
# 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.
Expand Down Expand Up @@ -68,3 +79,34 @@ def run_mochitest_test(self, test_file=None, suite=None):
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)
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# 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."""
Expand Down Expand Up @@ -89,3 +95,17 @@ def _run_xpcshell_harness(self, test_dirs=None, manifest=None,
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)

0 comments on commit 525b23f

Please sign in to comment.