o
    ihj                     @   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$  Regression tests against real RoborunPlus-compiled output.

tests/fixtures/ holds a representative subset of the reverse-engineering
corpus (see docs/reverse_engineering.md) -- pairs of .mbs source and the
exact .hex RoborunPlus produced for it. These aren't hand-written
expectations: they're ground truth, captured directly from the real
compiler. If the byte-for-byte comparison ever fails, that means codegen.py
has drifted from confirmed, evidence-backed behavior -- treat it as a real
regression, not a test to "fix" by updating the fixture.
    N)Path)generate_bytecode)read_intel_hex)tokenize)parse)expand_macrosfixturesc                 c   s    | ]}|j V  qd S )N)stem).0p r   A/sessions/nice-awesome-ritchie/mnt/compiler/tests/test_codegen.py	<genexpr>   s    r   z*.mbsnamec           	   	   C   s   t |  d  }tt |  d  d}tt|}t|}t|}||k}|s{t	d|fd||fdt
 v s@t|rEt|nddt
 v sQt|rVt|ndd }t|  d	|d
 d|d
 d d|i }tt|d }d S )Nz.mbsz.hex   )==)z%(py0)s == %(py2)sactualexpected)py0py2z : bytecode mismatch
  ours:      z
  expected: z
>assert %(py4)spy4)FIXTURES_DIR	read_textr   rstripr   r   r   r   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_saferepr_format_assertmsghexAssertionError_format_explanation)	r   sourcer   tokensprogramr   @py_assert1@py_format3@py_format5r   r   r   !test_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FIXTURE_NAMESmarkparametrizestrr+   r   r   r   r   <module>   s    &