mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Add test for "args" shell expansion.
This commit is contained in:
parent
65168dd784
commit
50bf46cf9d
3 changed files with 43 additions and 10 deletions
|
|
@ -4,9 +4,5 @@
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
|
|
||||||
# Expose Session directly.
|
# Expose Session directly.
|
||||||
def Session(*args, **kwargs):
|
from tests.debug.session import Session # noqa
|
||||||
from tests.debug import session
|
|
||||||
|
|
||||||
return session.Session(*args, **kwargs)
|
|
||||||
|
|
|
||||||
|
|
@ -484,6 +484,12 @@ class Session(object):
|
||||||
pid, fmt("{0}-subprocess-{1}", self.debuggee_id, pid)
|
pid, fmt("{0}-subprocess-{1}", self.debuggee_id, pid)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def run_in_terminal(self, args, cwd, env):
|
||||||
|
exe = args.pop(0)
|
||||||
|
self.spawn_debuggee.env.update(env)
|
||||||
|
self.spawn_debuggee(args, cwd, exe=exe)
|
||||||
|
return {}
|
||||||
|
|
||||||
def _process_request(self, request):
|
def _process_request(self, request):
|
||||||
self.timeline.record_request(request, block=False)
|
self.timeline.record_request(request, block=False)
|
||||||
if request.command == "runInTerminal":
|
if request.command == "runInTerminal":
|
||||||
|
|
@ -491,11 +497,8 @@ class Session(object):
|
||||||
cwd = request("cwd", ".")
|
cwd = request("cwd", ".")
|
||||||
env = request("env", json.object(unicode))
|
env = request("env", json.object(unicode))
|
||||||
try:
|
try:
|
||||||
exe = args.pop(0)
|
return self.run_in_terminal(args, cwd, env)
|
||||||
self.spawn_debuggee.env.update(env)
|
except Exception as exc:
|
||||||
self.spawn_debuggee(args, cwd, exe=exe)
|
|
||||||
return {}
|
|
||||||
except OSError as exc:
|
|
||||||
log.swallow_exception('"runInTerminal" failed:')
|
log.swallow_exception('"runInTerminal" failed:')
|
||||||
raise request.cant_handle(str(exc))
|
raise request.cant_handle(str(exc))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,37 @@ def test_args(pyfile, target, run):
|
||||||
pass
|
pass
|
||||||
argv = backchannel.receive()
|
argv = backchannel.receive()
|
||||||
assert argv == [some.str] + args
|
assert argv == [some.str] + args
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("target", targets.all)
|
||||||
|
@pytest.mark.parametrize("run", runners.all_launch)
|
||||||
|
def test_shell_expansion(pyfile, target, run):
|
||||||
|
@pyfile
|
||||||
|
def code_to_debug():
|
||||||
|
import sys
|
||||||
|
import debuggee
|
||||||
|
from debuggee import backchannel
|
||||||
|
|
||||||
|
debuggee.setup()
|
||||||
|
backchannel.send(sys.argv)
|
||||||
|
|
||||||
|
def expand(args):
|
||||||
|
for i, arg in enumerate(args):
|
||||||
|
if arg.startswith("$"):
|
||||||
|
args[i] = arg[1:]
|
||||||
|
|
||||||
|
class Session(debug.Session):
|
||||||
|
def run_in_terminal(self, args, cwd, env):
|
||||||
|
expand(args)
|
||||||
|
return super(Session, self).run_in_terminal(args, cwd, env)
|
||||||
|
|
||||||
|
args = ["0", "$1", "2"]
|
||||||
|
with Session() as session:
|
||||||
|
backchannel = session.open_backchannel()
|
||||||
|
with run(session, target(code_to_debug, args=args)):
|
||||||
|
pass
|
||||||
|
argv = backchannel.receive()
|
||||||
|
|
||||||
|
if session.config["console"] != "internalConsole":
|
||||||
|
expand(args)
|
||||||
|
assert argv == [some.str] + args
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue