Skip to content

Commit

Permalink
Add a wit-bindgen test subcommand
Browse files Browse the repository at this point in the history
As I've read more and more of the Rust async runtime support and other
various bits and pieces I've wanted more and more the ability to easily
write tests for guest interactions with the host. While I don't think
it's feasible to generate arbitrary hosts I do think it's possible to do
this much more easily than is done today with the testing support in
this repository. In essence this commit is an implementation of bytecodealliance#1161.

The goal of this commit is to add a `wit-bindgen test` test suite
runner. This test suite will be used to migrate all existing tests in
this repository to this new framework. In the limit this is expected to
make it easier to write tests (no Rust knowledge necessary), make it
more flexible to write tests (now you can use raw `*.wat`), and
additionally improve the quality of the test suite by making it more
reusable. The reusability isn't the highest priority at this time as
it's not clear what else would want to reuse this, but my hope is that
this refactoring is at least a large-ish leap forward towards having a
component model test suite of some kind eventually.
  • Loading branch information
alexcrichton committed Mar 5, 2025
1 parent ccebf1d commit d825e4f
Show file tree
Hide file tree
Showing 67 changed files with 2,732 additions and 606 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,16 @@ jobs:
- run: |
cargo test \
-p wit-bindgen-cli \
-p wit-bindgen-${{ matrix.lang }} \
--no-default-features \
--features ${{ matrix.lang }}
- run: |
cargo run test --languages rust,${{ matrix.lang }} tests/codegen \
--artifacts target/artifacts \
--rust-wit-bindgen-path ./crates/guest-rust
- run: |
cargo run test --languages rust,${{ matrix.lang }} tests/runtime-new \
--artifacts target/artifacts \
--rust-wit-bindgen-path ./crates/guest-rust
test_unit:
name: Crate Unit Tests
Expand Down
190 changes: 181 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ prettyplease = "0.2.20"
syn = { version = "2.0.89", features = ["printing"] }
futures = "0.3.31"

wat = "1.226.0"
wasmparser = "0.226.0"
wasm-encoder = "0.226.0"
wasm-metadata = "0.226.0"
wit-parser = "0.226.0"
wit-component = "0.226.0"
wasm-compose = "0.226.0"

wit-bindgen-core = { path = 'crates/core', version = '0.39.0' }
wit-bindgen-c = { path = 'crates/c', version = '0.39.0' }
Expand All @@ -48,13 +50,14 @@ wit-bindgen-csharp = { path = 'crates/csharp', version = '0.39.0' }
wit-bindgen-markdown = { path = 'crates/markdown', version = '0.39.0' }
wit-bindgen-moonbit = { path = 'crates/moonbit', version = '0.39.0' }
wit-bindgen = { path = 'crates/guest-rust', version = '0.39.0', default-features = false }
wit-bindgen-test = { path = 'crates/test', version = '0.39.0' }

[[bin]]
name = "wit-bindgen"

[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
clap = { workspace = true, features = ['wrap_help'] }
wit-bindgen-core = { workspace = true }
wit-bindgen-rust = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-c = { workspace = true, features = ['clap'], optional = true }
Expand All @@ -63,6 +66,7 @@ wit-bindgen-moonbit = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-teavm-java = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-go = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-csharp = { workspace = true, features = ['clap'], optional = true }
wit-bindgen-test = { workspace = true }
wit-component = { workspace = true }
wasm-encoder = { workspace = true }

Expand Down
Loading

0 comments on commit d825e4f

Please sign in to comment.