phasm/tests/integration/test_lang/test_imports.py
Johan B.W. de Vries 5c537f712e Project update
Various updates to bring the project uptodate.

- Updated required packages
- Removed runtimes that are not being updated
- wasmtime is for now the only supported runtime
- Implements imports for wasmtime runtime
- Fixes a memory access bug for wasmtime runtime
- compile_wasm is now optional - runtimes have to
  implement and call this themselves
- Typing fixes
- Linting fixes
2025-04-05 15:43:49 +02:00

78 lines
1.3 KiB
Python

import pytest
from phasm.type3.entry import Type3Exception
from ..helpers import Suite
@pytest.mark.integration_test
def test_imported_ok():
code_py = """
@imported
def helper(mul: i32) -> i32:
pass
@exported
def testEntry() -> i32:
return helper(2)
"""
def helper(mul: int) -> int:
return 4238 * mul
result = Suite(code_py).run_code(
imports={
'helper': helper,
}
)
assert 8476 == result.returned_value
@pytest.mark.integration_test
def test_imported_side_effect_no_return():
code_py = """
@imported
def helper(mul: u8) -> None:
pass
@exported
def testEntry() -> None:
return helper(3)
"""
prop = None
def helper(mul: int) -> None:
nonlocal prop
prop = mul
result = Suite(code_py).run_code(
imports={
'helper': helper,
}
)
assert None is result.returned_value
assert 3 == prop
@pytest.mark.integration_test
def test_imported_type_mismatch():
code_py = """
@imported
def helper(mul: u8) -> u8:
pass
@exported
def testEntry(x: u32) -> u8:
return helper(x)
"""
def helper(mul: int) -> int:
return 4238 * mul
with pytest.raises(Type3Exception, match=r'u32 must be u8 instead'):
Suite(code_py).run_code(
imports={
'helper': helper,
}
)