mirror of
https://github.com/python/cpython.git
synced 2026-05-06 04:37:33 -04:00
gh-148615: Handle -- separator in pdb argument parsing (#148624)
This commit is contained in:
@@ -3809,6 +3809,10 @@ def parse_args():
|
||||
opt_module = parser.parse_args(args[:2])
|
||||
opts.module = opt_module.module
|
||||
args = args[2:]
|
||||
elif args[0] == '--':
|
||||
args.pop(0)
|
||||
if not args:
|
||||
parser.error("missing script or module to run")
|
||||
elif args[0].startswith('-'):
|
||||
# Invalid argument before the script name.
|
||||
invalid_args = list(itertools.takewhile(lambda a: a.startswith('-'), args))
|
||||
|
||||
@@ -4718,6 +4718,27 @@ def bœr():
|
||||
]))
|
||||
self.assertIn('break in bar', stdout)
|
||||
|
||||
def test_end_of_options_separator(self):
|
||||
# gh-148615: Test parsing when '--' separator is used
|
||||
script = "import sys; print(f'ARGS: {sys.argv[1:]}')"
|
||||
with open(os_helper.TESTFN, 'w', encoding='utf-8') as f:
|
||||
f.write(script)
|
||||
stdout, _ = self._run_pdb(['--', os_helper.TESTFN, '-foo'], 'c\nq')
|
||||
self.assertIn("ARGS: ['-foo']", stdout)
|
||||
stdout, _ = self._run_pdb(['-c', 'continue', '--', os_helper.TESTFN, '-c', 'foo'], 'q')
|
||||
self.assertIn("ARGS: ['-c', 'foo']", stdout)
|
||||
stdout, stderr = self._run_pdb(['--'], 'q', expected_returncode=2)
|
||||
self.assertIn("missing script or module to run", stderr)
|
||||
stdout, stderr = self._run_pdb(['-x', '--', os_helper.TESTFN], 'q', expected_returncode=2)
|
||||
self.assertIn("unrecognized arguments: -x", stderr)
|
||||
stdout, _ = self._run_pdb([os_helper.TESTFN, '--', 'arg'], 'c\nq')
|
||||
self.assertIn("ARGS: ['--', 'arg']", stdout)
|
||||
with os_helper.temp_cwd():
|
||||
with open('mymod.py', 'w', encoding='utf-8') as f:
|
||||
f.write(script)
|
||||
stdout, _ = self._run_pdb(['-m', 'mymod', '--', 'arg'], 'c\nq')
|
||||
self.assertIn("ARGS: ['--', 'arg']", stdout)
|
||||
|
||||
@unittest.skipIf(SKIP_CORO_TESTS, "Coroutine tests are skipped")
|
||||
def test_async_break(self):
|
||||
script = """
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Fix :mod:`pdb` to accept standard -- end of options separator. Reported by haampie. Patched by Shrey Naithani.
|
||||
Reference in New Issue
Block a user