2013-04-19 16:19:54 +04:00
|
|
|
# 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/.
|
|
|
|
|
2015-06-22 03:39:09 +03:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2014-01-16 18:58:56 +04:00
|
|
|
|
2013-04-19 16:19:54 +04:00
|
|
|
import os
|
2014-01-16 18:58:56 +04:00
|
|
|
import sys
|
2014-07-18 05:28:45 +04:00
|
|
|
import argparse
|
2014-01-16 18:58:56 +04:00
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
MachCommandConditions as conditions,
|
|
|
|
)
|
2013-04-19 16:19:54 +04:00
|
|
|
|
|
|
|
from mach.decorators import (
|
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
2016-07-05 21:09:33 +03:00
|
|
|
def is_firefox_or_android(cls):
|
|
|
|
"""Must have Firefox build or Android build."""
|
|
|
|
return conditions.is_firefox(cls) or conditions.is_android(cls)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2016-05-31 20:15:37 +03:00
|
|
|
def setup_marionette_argument_parser():
|
2016-07-27 07:52:42 +03:00
|
|
|
from marionette.runtests import MarionetteArguments
|
|
|
|
from mozlog.structured import commandline
|
|
|
|
parser = MarionetteArguments()
|
|
|
|
commandline.add_logging_group(parser)
|
|
|
|
return parser
|
2014-07-18 05:28:45 +04:00
|
|
|
|
2016-07-05 21:09:33 +03:00
|
|
|
def run_marionette(tests, binary=None, topsrcdir=None, **kwargs):
|
2015-09-03 01:57:25 +03:00
|
|
|
from mozlog.structured import commandline
|
2014-10-10 20:58:10 +04:00
|
|
|
|
2015-03-04 04:37:19 +03:00
|
|
|
from marionette.runtests import (
|
2013-10-15 23:54:21 +04:00
|
|
|
MarionetteTestRunner,
|
2015-11-09 17:07:52 +03:00
|
|
|
MarionetteHarness
|
2013-10-15 23:54:21 +04:00
|
|
|
)
|
|
|
|
|
2016-07-27 07:52:42 +03:00
|
|
|
parser = setup_marionette_argument_parser()
|
2013-10-15 23:54:21 +04:00
|
|
|
|
|
|
|
if not tests:
|
|
|
|
tests = [os.path.join(topsrcdir,
|
2016-12-12 15:05:34 +03:00
|
|
|
'testing/marionette/harness/marionette_harness/tests/unit-tests.ini')]
|
2016-02-29 20:39:28 +03:00
|
|
|
|
2016-06-29 19:55:32 +03:00
|
|
|
args = argparse.Namespace(tests=tests)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2016-05-20 00:38:38 +03:00
|
|
|
args.binary = binary
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2014-10-20 16:55:28 +04:00
|
|
|
for k, v in kwargs.iteritems():
|
2015-08-18 23:27:04 +03:00
|
|
|
setattr(args, k, v)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2015-08-18 23:27:04 +03:00
|
|
|
parser.verify_usage(args)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2015-08-18 23:27:04 +03:00
|
|
|
args.logger = commandline.setup_logging("Marionette Unit Tests",
|
|
|
|
args,
|
|
|
|
{"mach": sys.stdout})
|
2016-03-19 05:33:08 +03:00
|
|
|
failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
|
2015-11-10 21:09:13 +03:00
|
|
|
if failed > 0:
|
2015-11-09 17:07:52 +03:00
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
2013-04-19 16:19:54 +04:00
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
@CommandProvider
|
|
|
|
class MachCommands(MachCommandBase):
|
|
|
|
@Command('marionette-test', category='testing',
|
2014-08-09 17:37:29 +04:00
|
|
|
description='Run a Marionette test (Check UI or the internal JavaScript using marionette).',
|
2016-07-05 21:09:33 +03:00
|
|
|
conditions=[is_firefox_or_android],
|
2016-05-31 20:15:37 +03:00
|
|
|
parser=setup_marionette_argument_parser,
|
2014-07-18 05:28:45 +04:00
|
|
|
)
|
2014-10-20 16:55:28 +04:00
|
|
|
def run_marionette_test(self, tests, **kwargs):
|
2015-09-18 16:53:37 +03:00
|
|
|
if 'test_objects' in kwargs:
|
|
|
|
tests = []
|
|
|
|
for obj in kwargs['test_objects']:
|
|
|
|
tests.append(obj['file_relpath'])
|
|
|
|
del kwargs['test_objects']
|
|
|
|
|
2016-08-30 11:53:07 +03:00
|
|
|
if not kwargs.get('binary') and conditions.is_firefox(self):
|
|
|
|
kwargs['binary'] = self.get_binary_path('app')
|
2015-09-03 01:57:25 +03:00
|
|
|
return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
|