tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

io_dependencies.py (2317B)


      1 #!/usr/bin/env python3
      2 """Opt-in current-source IO dependency regression with the packaged compiler.
      3 
      4 No patterns source, ambient workspace, recovery frontend, or fixture publication.
      5 Usage: python3 test/io_dependencies.py result/bin/tricu
      6 """
      7 import argparse
      8 from pathlib import Path
      9 import shutil
     10 import subprocess
     11 import tempfile
     12 
     13 ROOT = Path(__file__).resolve().parent.parent
     14 
     15 
     16 def main():
     17     parser = argparse.ArgumentParser(description=__doc__)
     18     parser.add_argument('tricu', type=Path)
     19     args = parser.parse_args()
     20     host = str(args.tricu.resolve())
     21     with tempfile.TemporaryDirectory(prefix='tricu-io-dependencies-') as temporary:
     22         workspace = Path(temporary)
     23         for name, relative in [('base', 'lib/base.tri'), ('io', 'lib/io.tri'),
     24                                ('native_math', 'lib/math/native.tri')]:
     25             shutil.copyfile(ROOT / relative, workspace / (name + '.tri'))
     26         source = workspace / 'main.tri'
     27         # Exercise actual IO definitions in a workspace lacking patterns.
     28         source.write_text('''!import base *
     29 !import io as IO
     30 !export main
     31 main = if (and? (equal? (IO.pure 7) (pair 0 7))
     32   (and? (equal? (IO.when true (IO.pure 9)) (IO.pure 9))
     33     (and? (equal? (IO.unless true (IO.pure 9)) (IO.pure t))
     34       (equal? (IO.putStr "hello") (pair 10 "hello"))))) 42 0
     35 ''')
     36         command = [host, 'eval', str(source), '--store', str(workspace / 'store'),
     37                    '--format', 'number', '+RTS', '-N1', '-M2048m', '-RTS']
     38         reply = subprocess.run(command, cwd=workspace, capture_output=True,
     39                                text=True, timeout=180)
     40         assert reply.returncode == 0, (reply.stdout, reply.stderr)
     41         assert reply.stdout.strip() == '42', (reply.stdout, reply.stderr)
     42         # A used missing dependency must still fail: this is not a relaxed
     43         # resolver or an ambient-source fallback.
     44         source.write_text('!import patterns *\n!export main\nmain = otherwise t\n')
     45         reply = subprocess.run(command, cwd=workspace, capture_output=True,
     46                                text=True, timeout=180)
     47         assert reply.returncode != 0, (reply.stdout, reply.stderr)
     48     print('Current IO compiles without patterns; constructor/conditional and missing-dependency controls pass.')
     49 
     50 
     51 if __name__ == '__main__':
     52     main()