diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-31 21:31:26 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-31 21:31:26 (GMT) |
| commit | 46a3cf4fe3380b5d4560589cce8f602ba949832d (patch) | |
| tree | d4c9935b59a1a18bb370d081c1e3907345fc6984 /Lib/test/test_launcher.py | |
| parent | 2b0cbb90c311ccfed291c3b0f4f8268fdac214ee (diff) | |
| download | cpython-46a3cf4fe3380b5d4560589cce8f602ba949832d.zip cpython-46a3cf4fe3380b5d4560589cce8f602ba949832d.tar.gz cpython-46a3cf4fe3380b5d4560589cce8f602ba949832d.tar.bz2 | |
gh-98692: Enable treating shebang lines as executables in py.exe launcher (GH-98732)
(cherry picked from commit 88297e2a8a75898228360ee369628a4a6111e2ee)
Co-authored-by: Steve Dower <steve.dower@python.org>
Diffstat (limited to 'Lib/test/test_launcher.py')
| -rw-r--r-- | Lib/test/test_launcher.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_launcher.py b/Lib/test/test_launcher.py index ba6856b..be6d002 100644 --- a/Lib/test/test_launcher.py +++ b/Lib/test/test_launcher.py @@ -517,6 +517,14 @@ class TestLauncher(unittest.TestCase, RunPyMixin): self.assertEqual("3.100", data["SearchInfo.tag"]) self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip()) + def test_python_shebang(self): + with self.py_ini(TEST_PY_COMMANDS): + with self.script("#! python -prearg") as script: + data = self.run_py([script, "-postarg"]) + self.assertEqual("PythonTestSuite", data["SearchInfo.company"]) + self.assertEqual("3.100", data["SearchInfo.tag"]) + self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip()) + def test_py2_shebang(self): with self.py_ini(TEST_PY_COMMANDS): with self.script("#! /usr/bin/python2 -prearg") as script: @@ -618,3 +626,42 @@ class TestLauncher(unittest.TestCase, RunPyMixin): self.assertIn("winget.exe", cmd) # Both command lines include the store ID self.assertIn("9PJPW5LDXLZ5", cmd) + + def test_literal_shebang_absolute(self): + with self.script(f"#! C:/some_random_app -witharg") as script: + data = self.run_py([script]) + self.assertEqual( + f"C:\\some_random_app -witharg {script}", + data["stdout"].strip(), + ) + + def test_literal_shebang_relative(self): + with self.script(f"#! ..\\some_random_app -witharg") as script: + data = self.run_py([script]) + self.assertEqual( + f"{script.parent.parent}\\some_random_app -witharg {script}", + data["stdout"].strip(), + ) + + def test_literal_shebang_quoted(self): + with self.script(f'#! "some random app" -witharg') as script: + data = self.run_py([script]) + self.assertEqual( + f'"{script.parent}\\some random app" -witharg {script}', + data["stdout"].strip(), + ) + + with self.script(f'#! some" random "app -witharg') as script: + data = self.run_py([script]) + self.assertEqual( + f'"{script.parent}\\some random app" -witharg {script}', + data["stdout"].strip(), + ) + + def test_literal_shebang_quoted_escape(self): + with self.script(f'#! some\\" random "app -witharg') as script: + data = self.run_py([script]) + self.assertEqual( + f'"{script.parent}\\some\\ random app" -witharg {script}', + data["stdout"].strip(), + ) |
