Files
kryon/tests/browser_behavior.py
T
waozi 9e4af21b6d Name the web target in the page tests and repair two stale test builds
The Canvas host is selected by OS == .WEB, so a page build that only defines
PLATFORM_WEB fails on unresolved Canvas names. The Canvas backend, audio and
text tests, the shared browser behavior helper, and the Lanczos, asset cache,
bitmap image and document storage tests now pass --target-os web
--target-cpu wasm32 (with --target=c when saving IR).

The host keys test builds as part of the project: the key modules import
widgets by name, which bare module paths no longer resolve. The toast test
drops its binding of the platform keyboard capability, which a toast program
never calls, so binding it was refused.

canvas-test, document-storage-test, lanczos-goldens-test,
canvas-asset-cache-test, bitmap-image-test, host-keys-test and
toast-action-test pass again.
2026-11-14 01:20:35 -03:00

32 lines
1.5 KiB
Python

"""Shared compiler setup for private browser behavior tests."""
import os
from pathlib import Path
import subprocess
from toolchain import BIN, ZIRAN_ROOT as ZIRAN
ROOT = Path(__file__).resolve().parents[1]
EMCC = os.environ.get('EMCC', str(Path.home() / 'emsdk/upstream/emscripten/emcc'))
environment = dict(os.environ)
for name in ('DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'GDK_DISPLAY'):
environment.pop(name, None)
environment.setdefault('EM_CACHE', str(ROOT / 'build/emscripten-cache'))
def run(args, **options):
return subprocess.run(list(map(str, args)), env=environment, check=True, **options)
def build_behavior(work, name, module_paths=()):
generated = work / 'generated'
extra = [argument for path in module_paths for argument in ('--module-path', path)]
run([BIN / 'zi2c', '--no-main', '--target-os', 'web', '--target-cpu', 'wasm32',
'--define', 'PLATFORM_WEB', '--root', ROOT / 'tests',
'--module-path', ROOT / 'src/backend', '--module-path', ZIRAN / 'std', *extra,
'-o', generated, ROOT / 'tests' / (name + '_browser_behavior.zi')])
shell = work / 'shell.html'
shell.write_text('<!doctype html><html><head><meta charset="utf-8"></head><body>'
'<pre id="result">pending</pre>{{{ SCRIPT }}}</body></html>')
run([EMCC, '-O1', '-I' + str(ZIRAN / 'include'), '-iquote', generated, *sorted(generated.rglob('*.c')),
'--js-library', ZIRAN / 'web/ziran_web.js', '-sASYNCIFY', '-sSINGLE_FILE=1',
'-sENVIRONMENT=web', '--shell-file', shell, '-o', work / 'test.html'])