Test for Trap::OutOfFuel instead of strings (#5297)

Update a few locations to test for a specific error code
This commit is contained in:
Alex Crichton
2022-11-18 14:02:14 -06:00
committed by GitHub
parent 54207d343e
commit 9b7c5e316d
2 changed files with 6 additions and 16 deletions

View File

@@ -306,13 +306,10 @@ pub fn instantiate_with_dummy(store: &mut Store<StoreLimits>, module: &Module) -
} }
let string = e.to_string(); let string = e.to_string();
// Also allow errors related to fuel consumption // Currently we instantiate with a `Linker` which can't instantiate
if string.contains("all fuel consumed") // every single module under the sun due to using name-based resolution
// Currently we instantiate with a `Linker` which can't instantiate // rather than positional-based resolution
// every single module under the sun due to using name-based resolution if string.contains("incompatible import type") {
// rather than positional-based resolution
|| string.contains("incompatible import type")
{
log::debug!("failed to instantiate: {}", string); log::debug!("failed to instantiate: {}", string);
return None; return None;
} }

View File

@@ -116,11 +116,7 @@ fn iloop() {
let mut store = Store::new(&engine, ()); let mut store = Store::new(&engine, ());
store.add_fuel(10_000).unwrap(); store.add_fuel(10_000).unwrap();
let error = Instance::new(&mut store, &module, &[]).err().unwrap(); let error = Instance::new(&mut store, &module, &[]).err().unwrap();
assert!( assert_eq!(error.downcast::<Trap>().unwrap(), Trap::OutOfFuel);
format!("{:?}", error).contains("all fuel consumed"),
"bad error: {}",
error
);
} }
} }
@@ -172,10 +168,7 @@ fn host_function_consumes_all() {
let instance = Instance::new(&mut store, &module, &[func.into()]).unwrap(); let instance = Instance::new(&mut store, &module, &[func.into()]).unwrap();
let export = instance.get_typed_func::<(), ()>(&mut store, "").unwrap(); let export = instance.get_typed_func::<(), ()>(&mut store, "").unwrap();
let trap = export.call(&mut store, ()).unwrap_err(); let trap = export.call(&mut store, ()).unwrap_err();
assert!( assert_eq!(trap.downcast::<Trap>().unwrap(), Trap::OutOfFuel);
format!("{trap:?}").contains("all fuel consumed"),
"bad error: {trap:?}"
);
} }
#[test] #[test]