1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__
import print_function
, unicode_literals
9 from mach
.decorators
import (
15 from mozbuild
.base
import MachCommandBase
18 HANDLE_FILE_ERROR
= '''
20 However, I do not yet know how to run tests from files. You'll need to run
21 the mach command for the test type you are trying to run. e.g.
22 $ mach xpcshell-test path/to/file
25 HANDLE_DIR_ERROR
= '''
27 However, I do not yet know how to run tests from directories. You can try
28 running the mach command for the tests in that directory. e.g.
29 $ mach xpcshell-test path/to/directory
33 I don't know how to run the test: %s
35 You need to specify a test suite name or abbreviation. It's possible I just
36 haven't been told about this test suite yet. If you suspect that's the issue,
37 please file a bug at https://bugzilla.mozilla.org/enter_bug.cgi?product=Testing&component=General
38 and request support be added.
41 MOCHITEST_CHUNK_BY_DIR
= 4
42 MOCHITEST_TOTAL_CHUNKS
= 5
46 'aliases': ('C', 'Rc', 'RC', 'rc'),
47 'mach_command': 'crashtest',
48 'kwargs': {'test_file': None},
51 'aliases': ('Cipc', 'cipc'),
52 'mach_command': 'crashtest-ipc',
53 'kwargs': {'test_file': None},
57 'mach_command': 'jetpack-test',
61 'mach_command': 'mochitest-a11y',
62 'kwargs': {'test_file': None},
64 'mochitest-browser': {
65 'aliases': ('bc', 'BC', 'Bc'),
66 'mach_command': 'mochitest-browser',
67 'kwargs': {'test_file': None},
70 'mach_command': 'mochitest-chrome',
71 'kwargs': {'test_file': None},
73 'mochitest-ipcplugins': {
74 'make_target': 'mochitest-ipcplugins',
77 'mach_command': 'mochitest-plain',
78 'kwargs': {'test_file': None},
81 'aliases': ('RR', 'rr', 'Rr'),
82 'mach_command': 'reftest',
83 'kwargs': {'test_file': None},
87 'mach_command': 'reftest-ipc',
88 'kwargs': {'test_file': None},
91 'aliases': ('X', 'x'),
92 'mach_command': 'xpcshell-test',
93 'kwargs': {'test_file': 'all'},
97 for i
in range(1, MOCHITEST_TOTAL_CHUNKS
+ 1):
98 TEST_SUITES
['mochitest-%d' %i] = {
99 'aliases': ('M%d' % i
, 'm%d' % i
),
100 'mach_command': 'mochitest-plain',
102 'chunk_by_dir': MOCHITEST_CHUNK_BY_DIR
,
103 'total_chunks': MOCHITEST_TOTAL_CHUNKS
,
110 Test or tests to run. Tests can be specified by test suite name or alias.
111 The following test suites and aliases are supported: %s
112 ''' % ', '.join(sorted(TEST_SUITES
))
113 TEST_HELP
= TEST_HELP
.strip()
117 class Test(MachCommandBase
):
118 @Command('test', category
='testing', description
='Run tests.')
119 @CommandArgument('what', default
=None, nargs
='*', help=TEST_HELP
)
120 def test(self
, what
):
123 status
= self
._run
_test
(entry
)
130 def _run_test(self
, what
):
132 if what
in TEST_SUITES
:
133 suite
= TEST_SUITES
[what
]
135 for v
in TEST_SUITES
.values():
136 if what
in v
.get('aliases', []):
141 if 'mach_command' in suite
:
142 return self
._mach
_context
.commands
.dispatch(
143 suite
['mach_command'], self
._mach
_context
, **suite
['kwargs'])
145 if 'make_target' in suite
:
146 return self
._run
_make
(target
=suite
['make_target'],
149 raise Exception('Do not know how to run suite. This is a logic '
150 'error in this mach command.')
152 if os
.path
.isfile(what
):
153 print(HANDLE_FILE_ERROR
% what
)
156 if os
.path
.isdir(what
):
157 print(HANDLE_DIR_ERROR
% what
)
160 print(UNKNOWN_TEST
% what
)