"""Run every cross-language contract, both directions, from built beams. python3 test/contract/run.py [contract ...] The Gleam-driven properties run in one `erl` (`albedo/contract/runner.main`) against one Python peer (`peer.py`). The Python-driven properties are the `*_test.py` files here, each against one Gleam peer. Neither starts a process per case. With no names, every contract runs. The beams come from `test/beams.py`: the gate's daemon snapshot, or else the checkout built first, so a run never loads beams older than its source. See robot-docs/testing.md#cross-language-contracts. """ import argparse import os from pathlib import Path import subprocess import sys HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) sys.path.insert(0, str(HERE.parent)) import beams # noqa: E402 from support import ROOT # noqa: E402 def main() -> int: parser = argparse.ArgumentParser() parser.add_argument("contracts", nargs="*") args = parser.parse_args() ebins = beams.ebins() env = dict( os.environ, ALBEDO_CONTRACT_EBIN=os.pathsep.join(ebins), ALBEDO_CONTRACT_PYTHON=sys.executable, ALBEDO_CONTRACT_PEER=str(HERE / "peer.py"), ALBEDO_CONTRACTS=",".join(args.contracts), ) erl = ["erl"] for directory in ebins: erl += ["-pa", directory] gleam = subprocess.Popen( [*erl, "-noshell", "-noinput", "-eval", "albedo@contract@runner:main()"], env=env, ) tests = sorted( str(path) for path in HERE.glob("*_test.py") if not args.contracts or path.name.removesuffix("_test.py") in args.contracts ) python = 0 if tests: python = subprocess.run( [ sys.executable, str(ROOT / "test" / "python_test_runner.py"), "--jobs", str(len(tests)), *tests, ], env=env, ).returncode return 1 if gleam.wait() or python else 0 if __name__ == "__main__": sys.exit(main())