summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-12-11 00:18:36 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-12-11 00:18:36 (GMT)
commitca3263c50c3b3a3719d2ec3ee7b30b8c669dcb19 (patch)
treee18938b9e8d57f43e11c013c5d633fd64d9aca65 /Lib/test
parentb94eef2ae3737b1f03452a30d5c96640c838dc46 (diff)
downloadcpython-ca3263c50c3b3a3719d2ec3ee7b30b8c669dcb19.zip
cpython-ca3263c50c3b3a3719d2ec3ee7b30b8c669dcb19.tar.gz
cpython-ca3263c50c3b3a3719d2ec3ee7b30b8c669dcb19.tar.bz2
Issue #25677: Correct syntax error caret for indented blocks.
Based on patch by Michael Layzell.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_cmd_line_script.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line_script.py b/Lib/test/test_cmd_line_script.py
index befe0e4..919f361 100644
--- a/Lib/test/test_cmd_line_script.py
+++ b/Lib/test/test_cmd_line_script.py
@@ -10,6 +10,7 @@ import os
import os.path
import py_compile
import subprocess
+import io
import textwrap
from test import support
@@ -540,6 +541,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)