I've setup an integration test to test a function called fn read()
. The code compiles with no warnings with cargo component build
, but when I run cargo test
it panics with below message. The test run through fine if I for instance rename the function to fn readf()
. I don't encounter the same issue with fn read() when having a "regular" lib project without wit-bindgen. I'm not sure if the issues are related to wit-bindgen or if there are certain words that can't be used as function names.
cargo test
Compiling read_test v0.1.0 (/home/user/projects/read_test)
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.26s
Running unittests src/lib.rs (target/debug/deps/read_test-95b95b2d2f708962)
thread 'main' panicked at src/lib.rs:8:9:
attempt to add with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at core/src/panicking.rs:221:5:
panic in a function that cannot unwind
stack backtrace:
panicked at std/src/io/mod.rs:429:49:
thread panicked while processing panic. aborting.
error: test failed, to rerun pass `--lib`
Caused by:
process didn't exit successfully: `/home/projects/read_test/target/debug/deps/read_test-95b95b2d2f708962` (signal: 6, SIGABRT: process abort signal)
Code
//structure
read_test/
│
├── src/
│ ├── bindings.rs
│ └── lib.rs
│
├── tests/
│ └── integration_test.rs
│
├── wit/
│ └── world.wit
└── Cargo.toml
//lib.rs
mod bindings;
pub use bindings::Guest;
pub struct ReadTest;
impl Guest for ReadTest {
fn read(left: u64, right: u64) -> u64 {
left + right
}
}
bindings::export!(ReadTest with_types_in bindings);
//world.wit
package wasm:test;
world read-test {
export read: func(letf: u64, right: u64) -> u64;
}
//integration_test.rs
use read_test::{Guest, ReadTest};
#[test]
fn test_add() {
let result = ReadTest::read(2, 2);
assert_eq!(4, result);
}
//Cargo.toml
[package]
name = "read_test"
version = "0.1.0"
edition = "2021"
[dependencies]
wit-bindgen = { version = "0.24.0", default-features = false, features = [
"realloc",
] }
wit-bindgen-rt = "0.24.0"
wit-cli = "0.0.0"
[lib]
crate-type = ["cdylib", "rlib"]
[package.metadata.component]
package = "wasm:test"
[package.metadata.component.dependencies]
´´´
My guess is that cargo test compiles and runs on native, so you would need a cargo component test (if that exists) or pass a wasm target and run it manually with a runtime.
Last updated: Dec 23 2024 at 12:05 UTC