8000 gh-95285: py.exe launcher fails with short argv0 · zooba/cpython@4716934 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4716934

Browse files
committed
pythongh-95285: py.exe launcher fails with short argv0
1 parent b8c5286 commit 4716934

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Lib/test/test_launcher.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def find_py(cls):
187187
)
188188
return py_exe
189189

190-
def run_py(self, args, env=None, allow_fail=False, expect_returncode=0):
190+
def run_py(self, args, env=None, allow_fail=False, expect_returncode=0, short_argv0=False):
191191
if not self.py_exe:
192192
self.py_exe = self.find_py()
193193

@@ -198,9 +198,14 @@ def run_py(self, args, env=None, allow_fail=False, expect_returncode=0):
198198
"PYLAUNCHER_DEBUG": "1",
199199
"PYLAUNCHER_DRYRUN": "1",
200200
}
201+
cwd, py_exe = None, self.py_exe
202+
if short_argv0:
203+
cwd, py_exe = str(py_exe.parent), f'"{py_exe.name}"'
201204
with subprocess.Popen(
202-
[self.py_exe, *args],
205+
[py_exe, *args],
203206
env=env,
207+
cwd=cwd,
208+
executable=self.py_exe,
204209
stdin=subprocess.PIPE,
205210
stdout=subprocess.PIPE,
206211
stderr=subprocess.PIPE,
@@ -539,6 +544,14 @@ def test_py3_shebang_nl(self):
539544
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
540545
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())
541546

547+
def test_py_shebang_short_argv0(self):
548+
with self.py_ini(TEST_PY_COMMANDS):
549+
with self.script("#! /usr/bin/env python -prearg") as script:
550+
data = self.run_py([script, "-postarg"], short_argv0=True)
551+
self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
552+
self.assertEqual("3.100", data["SearchInfo.tag"])
553+
self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
554+
542555
def test_install(self):
543556
data = self.run_py(["-V:3.10"], env={"PYLAUNCHER_ALWAYS_INSTALL": "1"}, expect_returncode=111)
544557
cmd = data["stdout"].strip()

0 commit comments

Comments
 (0)
0