()
| 373 | #[test] |
| 374 | #[cfg_attr(miri, ignore)] |
| 375 | fn test_trapping_unknown_import() -> Result<()> { |
| 376 | const WAT: &str = r#" |
| 377 | (module |
| 378 | (type $t0 (func)) |
| 379 | (import "" "imp" (func $.imp (type $t0))) |
| 380 | (func $run call $.imp) |
| 381 | (func $other) |
| 382 | (export "run" (func $run)) |
| 383 | (export "other" (func $other)) |
| 384 | ) |
| 385 | "#; |
| 386 | |
| 387 | let mut store = Store::<()>::default(); |
| 388 | let module = Module::new(store.engine(), WAT).expect("failed to create module"); |
| 389 | let mut linker = Linker::new(store.engine()); |
| 390 | |
| 391 | linker.define_unknown_imports_as_traps(&module)?; |
| 392 | let instance = linker.instantiate(&mut store, &module)?; |
| 393 | |
| 394 | // "run" calls an import function which will not be defined, so it should trap |
| 395 | let run_func = instance |
| 396 | .get_func(&mut store, "run") |
| 397 | .expect("expected a run func in the module"); |
| 398 | |
| 399 | let err = run_func.call(&mut store, &[], &mut []).unwrap_err(); |
| 400 | assert!(err.is::<UnknownImportError>()); |
| 401 | |
| 402 | // "other" does not call the import function, so it should not trap |
| 403 | let other_func = instance |
| 404 | .get_func(&mut store, "other") |
| 405 | .expect("expected an other func in the module"); |
| 406 | |
| 407 | other_func.call(&mut store, &[], &mut [])?; |
| 408 | |
| 409 | Ok(()) |
| 410 | } |
| 411 | |
| 412 | #[test] |
| 413 | #[cfg_attr(miri, ignore)] |
nothing calls this directly
no test coverage detected