omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / attachments.py
| 1 | """Compile and run independent C and Python host programs.""" |
| 2 | import os, pathlib, subprocess, sys |
| 3 | root=pathlib.Path(__file__).resolve().parents[1] |
| 4 | os.chdir(root) |
| 5 | b=root/'build/attachments'; b.mkdir(exist_ok=True) |
| 6 | def run(args): |
| 7 | p=subprocess.run([str(x) for x in args],capture_output=True,timeout=20) |
| 8 | assert p.returncode==0,(args,p.returncode,p.stderr[:600]) |
| 9 | return p.stdout |
| 10 | for target,ext in [('c','c'),('python','py')]: |
| 11 | out=run(['tools/bridge',target,'examples/attachment.om']) |
| 12 | assert out |
| 13 | (b/f'attachment.{ext}').write_bytes(out) |
| 14 | try: |
| 15 | run(['gcc','-O1','-std=gnu11','-fsanitize=undefined','-fno-sanitize-recover=all','-I',b,'examples/caller.c','-o',b/'caller']) |
| 16 | print(run([b/'caller']).decode().strip()) |
| 17 | (b/'caller.py').write_bytes(pathlib.Path('examples/caller.py').read_bytes()) |
| 18 | print(run([sys.executable,b/'caller.py']).decode().strip()) |
| 19 | except Exception as exc: |
| 20 | print('FAIL',exc);sys.exit(1) |
| 21 | print('attachment cases=2 failures=0 RC=0') |