interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / quantity / test / run.py

27 lines · 1207 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Native contract test for om/quantity. Python compiles and compares; the checks are Omega."""
3import subprocess
4import sys
5from pathlib import Path
6
7ROOT = Path(__file__).resolve().parents[3]
8UNIT = ROOT / "om/quantity"
9OUT = ROOT / "build/quantity"
10COMPILER = subprocess.check_output([str(ROOT / "tools/omc.sh")], text=True).strip()
11
12source = (UNIT / "quantity.om").read_text() + "\n" + (UNIT / "test/driver.om").read_text()
13result = subprocess.run([COMPILER], input=source.encode(), capture_output=True)
14if result.returncode:
15 OUT.mkdir(parents=True, exist_ok=True)
16 (OUT / "driver.om").write_text(source)
17 sys.exit(f"quantity: compile failed: {result.stderr.decode()}")
18OUT.mkdir(parents=True, exist_ok=True)
19binary = OUT / "driver"
20binary.write_bytes(result.stdout)
21binary.chmod(0o700)
22run = subprocess.run([str(binary)], capture_output=True, timeout=120)
23if run.returncode != 0:
24 sys.exit(f"quantity: driver exit {run.returncode}: {run.stderr.decode()}")
25if run.stdout != bytes([0]):
26 sys.exit(f"quantity: contract case {run.stdout[0]} failed (0 means every case passed)")
27print("PASS quantity: checked-quantity contract cases, refusal leaves output unchanged")