-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify dynamic linking imports tests #818
Conversation
@@ -432,63 +432,49 @@ impl Runner { | |||
let module = Module::from_binary(self.linker.engine(), &self.wasm)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a nit, given the description of the PR, could you rename this function reflect the intention? e.g., ensure_expected_imports
(or something along those lines)
crates/runner/src/lib.rs
Outdated
let imports = module | ||
.imports() | ||
.filter(|i| i.module() == instance_name) | ||
.collect::<Vec<_>>(); | ||
assert_eq!(4, imports.len()); | ||
|
||
let realloc = imports | ||
.iter() | ||
.find(|i| i.name() == "canonical_abi_realloc") | ||
.expect("Should have canonical_abi_realloc import"); | ||
let ty = realloc.ty(); | ||
let f = ty.unwrap_func(); | ||
assert!(f.params().all(|p| p.is_i32())); | ||
assert_eq!(4, f.params().len()); | ||
assert!(f.results().all(|p| p.is_i32())); | ||
assert_eq!(1, f.results().len()); | ||
|
||
let memory = imports | ||
.iter() | ||
.find(|i| i.name() == "memory" && i.ty().memory().is_some()); | ||
assert!(memory.is_some(), "Should have memory import"); | ||
|
||
let eval_bytecode = imports | ||
.iter() | ||
.find(|i| i.name() == "eval_bytecode") | ||
.expect("Should have eval_bytecode import"); | ||
let ty = eval_bytecode.ty(); | ||
let f = ty.unwrap_func(); | ||
assert!(f.params().all(|p| p.is_i32())); | ||
assert_eq!(2, f.params().len()); | ||
assert_eq!(0, f.results().len()); | ||
|
||
let invoke = imports | ||
.iter() | ||
.find(|i| i.name() == "invoke") | ||
.expect("Should have eval_bytecode import"); | ||
let ty = invoke.ty(); | ||
let f = ty.unwrap_func(); | ||
assert!(f.params().all(|p| p.is_i32())); | ||
assert_eq!(4, f.params().len()); | ||
assert_eq!(0, f.results().len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you replace the assert
s with bail!
or Err(anyhow::Error)
? I get that we're asserting and that the runner is mostly used in tests, however, I'd like to ensure that errors are recoverable here so that failures can bubble up with as much as context as possible to the test invoking them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Description of the change
Simplifies the test code for checking the imports that dynamically linked modules have. At the moment, we always import
canonical_abi_realloc
,memory
,eval_bytecode
, andinvoke
, so we don't need separate tests for dynamically linked modules that have named exports.Why am I making this change?
I'm going to need to adjust how we check the imports to exclude
eval_bytecode
and reduce the number of expected imports for certain dynamically linked modules in an upcoming PR and wanted to refactor the test suite outside of that PR first.Checklist
javy-cli
andjavy-plugin
do not require updating CHANGELOG files.