blob: 06e33f4c4c2f3859cddc810c24432ff125f8ba53 [file] [log] [blame]
costypetrisor8ed317f2018-07-31 20:55:14 +00001import os
2import textwrap
3import unittest
4
Hai Shibb0424b2020-08-04 00:47:42 +08005from test.support import os_helper
costypetrisor8ed317f2018-07-31 20:55:14 +00006from test.support.script_helper import assert_python_ok
7
8
9class TestLLTrace(unittest.TestCase):
10
11 def test_lltrace_does_not_crash_on_subscript_operator(self):
12 # If this test fails, it will reproduce a crash reported as
13 # bpo-34113. The crash happened at the command line console of
14 # debug Python builds with __ltrace__ enabled (only possible in console),
Christian Clausscfca4a62021-10-07 17:49:47 +020015 # when the internal Python stack was negatively adjusted
Inada Naokifb786922021-04-06 11:18:41 +090016 with open(os_helper.TESTFN, 'w', encoding='utf-8') as fd:
Hai Shibb0424b2020-08-04 00:47:42 +080017 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
costypetrisor8ed317f2018-07-31 20:55:14 +000018 fd.write(textwrap.dedent("""\
19 import code
20
21 console = code.InteractiveConsole()
22 console.push('__ltrace__ = 1')
23 console.push('a = [1, 2, 3]')
24 console.push('a[0] = 1')
25 print('unreachable if bug exists')
26 """))
27
Hai Shibb0424b2020-08-04 00:47:42 +080028 assert_python_ok(os_helper.TESTFN)
costypetrisor8ed317f2018-07-31 20:55:14 +000029
30if __name__ == "__main__":
31 unittest.main()