interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / tests / attachments.py

21 lines · 984 bytes Raw Blame History
1"""Compile and run independent C and Python host programs."""
2import os, pathlib, subprocess, sys
3root=pathlib.Path(__file__).resolve().parents[1]
4os.chdir(root)
5b=root/'build/attachments'; b.mkdir(exist_ok=True)
6def 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
10for 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)
14try:
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())
19except Exception as exc:
20 print('FAIL',exc);sys.exit(1)
21print('attachment cases=2 failures=0 RC=0')