Skip to content

Commit

Permalink
Bug 1305695 - ./mach test --debugger=<debugger> doesn't fail if <debu…
Browse files Browse the repository at this point in the history
…gger> isn't available r=gbrown

- added checkers in python/mach/mach/main.py prior to calling registrar.py.
- added internal function to check if specified debugger is installed.
- support both ./mach test <test_name> and ./mach <test_category> styles.

Differential Revision: https://phabricator.services.mozilla.com/D7234

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Edwin Gao committed Oct 1, 2018
1 parent 6a5841d commit d7986ad
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions python/mach/mach/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,42 @@ def _run(self, argv):
# to command line handling (e.g alias, defaults) will be ignored.
self.load_settings(args.settings_file)

def _check_debugger(program):
"""Checks if debugger specified in command line is installed.
This internal function calls an in-tree library 'which'.
If the call does not raise any exceptions, mach is permitted
to continue execution.
Otherwise, mach execution is halted.
Args:
program (str): debugger program name.
"""
from which import which, WhichError
try:
which(program)
except WhichError:
print("Specified debugger '{}' is not found.\n".format(program) +
"Is it installed? Is it in your PATH?")
sys.exit(1)

# For the codepath where ./mach <test_type> --debugger=<program>,
# checks if the debugger specified is installed on system.
if (hasattr(args.command_args, "debugger") and
getattr(args.command_args, "debugger") is not None):
_check_debugger(getattr(args.command_args, "debugger"))
# For the codepath where ./mach test --debugger=<program> <test_type>,
# checks if the debugger specified is installed on system.
elif (hasattr(args.command_args, "extra_args") and
getattr(args.command_args, "extra_args")):
extra_args = getattr(args.command_args, "extra_args")
# This supports common use case where one debugger is specified.
debugger = [ea.split("=")[1] for ea in extra_args if "debugger" in ea]
if debugger:
_check_debugger(''.join(debugger))

if not hasattr(args, 'mach_handler'):
raise MachError('ArgumentParser result missing mach handler info.')

Expand Down

0 comments on commit d7986ad

Please sign in to comment.