o
    HXîh‚  ã                   @   s„   d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	 e
edƒZe ed¡G dd„ dejƒƒZedkr@e ¡  dS dS )	é    N)Ú	os_helperÚverbose)Úassert_python_okZgettotalrefcountzlltrace requires Py_DEBUGc                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestLLTracec                 C   s`   t tjddd}|  tjtj¡ | t d¡¡ ttjƒ W d   ƒ d S 1 s)w   Y  d S )NÚwúutf-8©Úencodingzþ            import code

            console = code.InteractiveConsole()
            console.push('__ltrace__ = 1')
            console.push('a = [1, 2, 3]')
            console.push('a[0] = 1')
            print('unreachable if bug exists')
            )	Úopenr   ÚTESTFNÚ
addCleanupÚunlinkÚwriteÚtextwrapÚdedentr   )ÚselfÚfd© r   ú;/opt/python-3.10.19/usr/lib/python3.10/test/test_lltrace.pyÚ1test_lltrace_does_not_crash_on_subscript_operator   s
   
"ôz=TestLLTrace.test_lltrace_does_not_crash_on_subscript_operatorc                 C   s¸   t  |¡ ¡ }ttjddd}|  tjtj¡ | |¡ W d   ƒ n1 s'w   Y  t	tjƒ\}}}|  
|d¡ |  
|d¡ | d¡}trZtdƒ t|ƒ tdƒ t|ƒ tƒ  |S )Nr   r   r   ó    r   z

--- code ---z
--- stdout ---)r   r   Ústripr
   r   r   r   r   r   r   ZassertEqualÚdecoder   Úprint)r   Úcoder   ÚstatusÚstdoutÚstderrÚresultr   r   r   Úrun_code#   s    þ
zTestLLTrace.run_codec                 C   sh   t j| }t d|› dtj¡}|r#|  | |¡d|› d|› ¡ d S |  | |¡d|› d|› ¡ d S )Nz: z($|, )z": z" not found in: z" found in: )ÚopcodeZopmapÚreÚcompileÚ	MULTILINEZ
assertTrueÚsearchZassertFalse)r   Úopr   ZpresentZregexr   r   r   Úcheck_op4   s   
ÿÿzTestLLTrace.check_opc                 C   ó   |   ||d¡ d S )NT©r&   ©r   r%   r   r   r   r   Úcheck_op_in>   ó   zTestLLTrace.check_op_inc                 C   r'   )NFr(   r)   r   r   r   Úcheck_op_not_inA   r+   zTestLLTrace.check_op_not_inc                 C   sV   |   d¡}|  d|¡ |  d|¡ |  d|¡ |  d|¡ |  d|¡ |  d|¡ d S )Naƒ  
            def dont_trace_1():
                a = "a"
                a = 10 * a
            def trace_me():
                for i in range(3):
                    +i
            def dont_trace_2():
                x = 42
                y = -x
            dont_trace_1()
            __ltrace__ = 1
            trace_me()
            del __ltrace__
            dont_trace_2()
        ZGET_ITERZFOR_ITERZUNARY_POSITIVEZPOP_TOPZBINARY_MULTIPLYZUNARY_NEGATIVE)r   r*   r,   )r   r   r   r   r   Útest_lltraceD   s   
zTestLLTrace.test_lltraceN)	Ú__name__Ú
__module__Ú__qualname__r   r   r&   r*   r,   r-   r   r   r   r   r      s    
r   Ú__main__)r    r!   Úsysr   ZunittestZtest.supportr   r   Ztest.support.script_helperr   ÚhasattrZPy_DEBUGZ
skipUnlessZTestCaser   r.   Úmainr   r   r   r   Ú<module>   s    

Sÿ