Skip to content

Commit

Permalink
Merge pull request #822 from wasmx/rust-test
Browse files Browse the repository at this point in the history
rust: Add host function test in rust
  • Loading branch information
axic authored May 24, 2022
2 parents 513b073 + f5626f8 commit 8482896
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bindings/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,4 +1356,33 @@ mod tests {
Error::InvalidMemoryOffsetOrSize
);
}

#[test]
fn execute_with_missing_import() {
/* wat2wasm
(module
(func $adler32 (import "env" "adler32") (param i32 i32) (result i32))
(memory (export "memory") 1)
(data (i32.const 0) "abcd")
(func (export "test") (result i32)
i32.const 0
i32.const 4
call $adler32
)
)
*/
let input = hex::decode(
"0061736d01000000010b0260027f7f017f6000017f020f0103656e760761646c657233320000030201010503010001071102066d656d6f72790200047465737400010a0a0108004100410410000b0b0a010041000b0461626364").unwrap();

let module = parse(&input);
assert!(module.is_ok());
let instance = module.unwrap().instantiate();
assert!(instance.is_err());
assert_eq!(
instance.err().unwrap(),
Error::InstantiationFailed(
"module requires 1 imported functions, 0 provided".to_string()
)
);
}
}

0 comments on commit 8482896

Please sign in to comment.