mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #25677: Merge SyntaxError caret positioning from 3.5
This commit is contained in:
commit
619555d77b
5 changed files with 39 additions and 5 deletions
|
@ -10,6 +10,7 @@ import os
|
|||
import os.path
|
||||
import py_compile
|
||||
import subprocess
|
||||
import io
|
||||
|
||||
import textwrap
|
||||
from test import support
|
||||
|
@ -539,6 +540,38 @@ class CmdLineTest(unittest.TestCase):
|
|||
text = stderr.decode('ascii')
|
||||
self.assertEqual(text, "some text")
|
||||
|
||||
def test_syntaxerror_unindented_caret_position(self):
|
||||
script = "1 + 1 = 2\n"
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'script', script)
|
||||
exitcode, stdout, stderr = assert_python_failure(script_name)
|
||||
text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
|
||||
# Confirm that the caret is located under the first 1 character
|
||||
self.assertIn("\n 1 + 1 = 2\n ^", text)
|
||||
|
||||
def test_syntaxerror_indented_caret_position(self):
|
||||
script = textwrap.dedent("""\
|
||||
if True:
|
||||
1 + 1 = 2
|
||||
""")
|
||||
with support.temp_dir() as script_dir:
|
||||
script_name = _make_test_script(script_dir, 'script', script)
|
||||
exitcode, stdout, stderr = assert_python_failure(script_name)
|
||||
text = io.TextIOWrapper(io.BytesIO(stderr), 'ascii').read()
|
||||
# Confirm that the caret is located under the first 1 character
|
||||
self.assertIn("\n 1 + 1 = 2\n ^", text)
|
||||
|
||||
# Try the same with a form feed at the start of the indented line
|
||||
script = (
|
||||
"if True:\n"
|
||||
"\f 1 + 1 = 2\n"
|
||||
)
|
||||
script_name = _make_test_script(script_dir, "script", script)
|
||||
exitcode, stdout, stderr = assert_python_failure(script_name)
|
||||
text = io.TextIOWrapper(io.BytesIO(stderr), "ascii").read()
|
||||
self.assertNotIn("\f", text)
|
||||
self.assertIn("\n 1 + 1 = 2\n ^", text)
|
||||
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(CmdLineTest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue