RunMat
GitHub

Testing Strategy

RunMat tests are organized by ownership boundary. Parser and lowering crates test language structure, VM tests exercise bytecode and interpreter behavior, runtime tests cover builtins and providers, integration tests cover cross-crate execution behavior, and WASM tests cover browser and JavaScript-hosted behavior.

There are 8,000+ tests in the RunMat codebase, systematically covering the language pipeline, execution engines, runtime builtins, acceleration layer, plotting, CLI, LSP, snapshotting, filesystem, and WASM bindings.

Baseline Checks

To run the baseline tests, run the following commands:

cargo fmt -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo check --all-targets --all-features
RUST_TEST_THREADS=1 cargo test --all-targets --all-features

CI serializes tests with RUST_TEST_THREADS=1 because several suites touch global runtime state: filesystem providers, GPU providers, registries, process environment, and plotting/runtime hooks.

Crate-Level Tests

Use crate tests when a change is localized. For example:

Change areaUseful commands
Lexer/parser syntaxcargo test -p runmat-lexer, cargo test -p runmat-parser
HIR/MIR loweringcargo test -p runmat-hir, cargo test -p runmat-mir
VM bytecode/interpretercargo test -p runmat-vm, cargo test -p runmat-vm --test indexing
Runtime builtinscargo test -p runmat-runtime
CLI behaviorcargo test -p runmat-cli
Config loadingcargo test -p runmat-config
Builtin registrycargo test -p runmat-builtins
Macro expansioncargo test -p runmat-macros

VM tests use shared helpers that parse MATLAB source, lower through HIR and MIR, compile bytecode, and interpret the result. Those helpers also run tests on a larger stack for deep compile or interpreter cases.

Runtime tests include helper utilities for provider setup, GPU provider locking, filesystem wrappers, and gather operations. Prefer those helpers over open-coded global setup in new tests.

Runtime Integration Tests

Cross-crate runtime behavior lives in crates/runmat-runtime-integration-tests. This crate is intentionally separate from unit tests because it exercises dispatch, GPU handle behavior, dtype behavior, provider wiring, and residency assumptions across multiple crates.

cargo test -p runmat-runtime-integration-tests

Run this suite when a change affects builtin dispatch, GPU values, provider registration, dtype conversion, or execution behavior that crosses crate boundaries.

GPU Tests

The acceleration crate has focused tests for fusion, provider initialization, residency, reductions, matmul paths, precision boundaries, telemetry, and backend behavior.

cargo test -p runmat-accelerate
cargo test -p runmat-accelerate --features wgpu
cargo test -p runmat-accelerate --features wgpu --test provider_init

Runtime GPU tests use either the deterministic in-process provider or WGPU behind the wgpu feature:

cargo test -p runmat-runtime --features wgpu
cargo test -p runmat-runtime-integration-tests --test bench_residency_smoke

Use the in-process provider for semantic tests that should not depend on a physical GPU. Use WGPU tests when validating backend initialization, residency, shader dispatch, or device behavior.

WASM Tests

WASM CI builds the runtime for wasm32-unknown-unknown, then runs the headless browser script:

rustup target add wasm32-unknown-unknown
RUNMAT_GENERATE_WASM_REGISTRY=1 cargo build -p runmat-wasm --target wasm32-unknown-unknown
scripts/test-wasm-headless.sh

scripts/test-wasm-headless.sh regenerates the WASM registry, checks runmat-core for wasm compatibility, and runs browser-based WASM tests. To include runtime browser tests:

RUNMAT_WASM_INCLUDE_RUNTIME=1 scripts/test-wasm-headless.sh

Focused WASM regression suites are available for symptom and replay coverage:

scripts/test-wasm-regression-suite.sh symptom-closure
scripts/test-wasm-regression-suite.sh replay-smoke

Those wrappers run the appropriate wasm-pack test --node and wasm-pack test --chrome --headless targets under crates/runmat-wasm/tests.

Macro UI Tests

runmat-macros uses compile-fail fixtures for macro diagnostics.

cargo test -p runmat-macros --test compile

The fixtures live under crates/runmat-macros/tests/ui. Each failing Rust input has a matching .stderr expectation. Update those expectations only when the diagnostic change is intentional.

Choosing What To Run

ChangeStart withExpand to
Parser or syntaxTouched parser test filecargo test -p runmat-parser
Lowering or bytecodeTouched HIR/MIR/VM testcargo test -p runmat-vm
Builtin implementationcargo test -p runmat-runtimeRuntime integration tests
GPU or fusioncargo test -p runmat-accelerate --features wgpuRuntime GPU integration tests
CLI commandcargo test -p runmat-cliFull workspace tests
WASM or TypeScript APIscripts/test-wasm-headless.shWASM regression suite and npm test in bindings/ts
Macro changescargo test -p runmat-macros --test compileFull macro crate tests

Before merging a broad runtime change, run the full baseline or let CI confirm it on the target runners.