mach_test_package_commands.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/.
  4. from __future__ import unicode_literals
  5. import os
  6. import sys
  7. from argparse import Namespace
  8. from functools import partial
  9. import mozlog
  10. from xpcshellcommandline import parser_desktop
  11. from mach.decorators import (
  12. CommandProvider,
  13. Command,
  14. )
  15. def run_xpcshell(context, **kwargs):
  16. args = Namespace(**kwargs)
  17. args.appPath = args.appPath or os.path.dirname(context.firefox_bin)
  18. args.e10s = context.mozharness_config.get('e10s', args.e10s)
  19. args.utility_path = context.bin_dir
  20. args.testingModulesDir = context.modules_dir
  21. if not args.xpcshell:
  22. args.xpcshell = os.path.join(args.appPath, 'xpcshell')
  23. if not args.pluginsPath:
  24. for path in context.ancestors(args.appPath, depth=2):
  25. test = os.path.join(path, 'plugins')
  26. if os.path.isdir(test):
  27. args.pluginsPath = test
  28. break
  29. log = mozlog.commandline.setup_logging("XPCShellTests",
  30. args,
  31. {"mach": sys.stdout},
  32. {"verbose": True})
  33. if args.testPaths:
  34. test_root = os.path.join(context.package_root, 'xpcshell', 'tests')
  35. normalize = partial(context.normalize_test_path, test_root)
  36. args.testPaths = map(normalize, args.testPaths)
  37. import runxpcshelltests
  38. xpcshell = runxpcshelltests.XPCShellTests(log=log)
  39. return xpcshell.runTests(**vars(args))
  40. @CommandProvider
  41. class MochitestCommands(object):
  42. def __init__(self, context):
  43. self.context = context
  44. @Command('xpcshell-test', category='testing',
  45. description='Run the xpcshell harness.',
  46. parser=parser_desktop)
  47. def xpcshell(self, **kwargs):
  48. return run_xpcshell(self.context, **kwargs)