Refactor mgmt of misc testsuite (#101)
Changes: * use [tempfile] crate for auto mgmt of temp dirs * use concrete types in place of generics in `utils` module [tempfile]: https://github.com/Stebalien/tempfile
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
use cranelift_codegen::settings;
|
||||
use std::path::Path;
|
||||
use wasmtime_jit::Context;
|
||||
|
||||
pub fn instantiate<S: AsRef<str>>(
|
||||
data: &[u8],
|
||||
bin_name: S,
|
||||
workspace: Option<S>,
|
||||
) -> Result<(), String> {
|
||||
pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> Result<(), String> {
|
||||
// Prepare runtime
|
||||
let isa_builder =
|
||||
cranelift_native::builder().map_err(|_| "host machine is not a supported target")?;
|
||||
@@ -14,12 +11,12 @@ pub fn instantiate<S: AsRef<str>>(
|
||||
let mut context = Context::with_isa(isa);
|
||||
let global_exports = context.get_global_exports();
|
||||
|
||||
let get_preopens = |workspace: Option<S>| -> Result<Vec<_>, String> {
|
||||
let get_preopens = |workspace: Option<&Path>| -> Result<Vec<_>, String> {
|
||||
if let Some(workspace) = workspace {
|
||||
let preopen_dir = wasi_common::preopen_dir(workspace.as_ref()).map_err(|e| {
|
||||
let preopen_dir = wasi_common::preopen_dir(workspace).map_err(|e| {
|
||||
format!(
|
||||
"error while preopening directory '{}': {}",
|
||||
workspace.as_ref(),
|
||||
workspace.display(),
|
||||
e
|
||||
)
|
||||
})?;
|
||||
@@ -36,7 +33,7 @@ pub fn instantiate<S: AsRef<str>>(
|
||||
"",
|
||||
global_exports,
|
||||
&get_preopens(workspace)?,
|
||||
&[bin_name.as_ref().to_owned(), ".".to_owned()],
|
||||
&[bin_name.to_owned(), ".".to_owned()],
|
||||
&[],
|
||||
)
|
||||
.map_err(|e| format!("error instantiating WASI: {}", e))?,
|
||||
@@ -46,11 +43,5 @@ pub fn instantiate<S: AsRef<str>>(
|
||||
context
|
||||
.instantiate_module(None, &data)
|
||||
.map(|_| ())
|
||||
.map_err(|e| {
|
||||
format!(
|
||||
"error while processing main module '{}': {}",
|
||||
bin_name.as_ref(),
|
||||
e
|
||||
)
|
||||
})
|
||||
.map_err(|e| format!("error while processing main module '{}': {}", bin_name, e))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user