1import os
2import textwrap
3import unittest
4
5from test import support
6from 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),
15        # when the interal Python stack was negatively adjusted
16        with open(support.TESTFN, 'w') as fd:
17            self.addCleanup(os.unlink, support.TESTFN)
18            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
28            assert_python_ok(support.TESTFN)
29
30if __name__ == "__main__":
31    unittest.main()
32