o
    hj                     @   s   d Z ddlZddlm  mZ ddlmZ ddl	Z	ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ eejd	 Zed
d edD Ze	jdedefddZdS )a%  The ultimate regression test: the actual production PumpController*.mbs
scripts, compiled and compared byte-for-byte against their real RoborunPlus
.hex output.

Unlike tests/fixtures/ (small, single-purpose minimal-pair test programs
built specifically to pin down individual opcodes), these are real-world
scripts nobody wrote for reverse-engineering purposes -- they're what this
compiler actually needs to produce correctly. A failure here means the
compiler cannot yet be trusted on real hardware, regardless of how the
synthetic corpus looks.
    N)Path)generate_bytecode)read_intel_hex)tokenize)parse)expand_macrosreal_scriptsc                 c   s    | ]}|j V  qd S )N)stem).0p r   F/sessions/nice-awesome-ritchie/mnt/compiler/tests/test_real_scripts.py	<genexpr>   s    r   z*.mbsnamec           	      C   s   t |  d  }tt |  d  d}tt|}t|}t|}||k}|szt	d|fd||fdt
 v s@t|rEt|nddt
 v sQt|rVt|ndd }t|  d	t| d
t| dd d|i }tt|d }d S )Nz.mbsz.hex   )==)z%(py0)s == %(py2)sactualexpected)py0py2z?: compiled output does not match real RoborunPlus .hex (actual z bytes, expected z bytes)z
>assert %(py4)spy4)REAL_SCRIPTS_DIR	read_textr   rstripr   r   r   r   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_saferepr_format_assertmsglenAssertionError_format_explanation)	r   sourcer   tokensprogramr   @py_assert1@py_format3@py_format5r   r   r   -test_real_script_matches_real_compiler_output   sT   r*   )__doc__builtinsr   _pytest.assertion.rewrite	assertionrewriter   pathlibr   pytestmicrobasic_compiler.codegenr   microbasic_compiler.hexfiler   microbasic_compiler.lexerr   microbasic_compiler.parserr    microbasic_compiler.preprocessorr   __file__parentr   sortedglobSCRIPT_NAMESmarkparametrizestrr*   r   r   r   r   <module>   s    &