wasmer/lib/wasi-tests/tests/wasitests/_common.rs

38 lines
1.3 KiB
Rust
Raw Normal View History

2019-05-17 19:09:31 +00:00
macro_rules! assert_wasi_output {
($file:expr, $name:expr, $po_dir_args: expr, $mapdir_args:expr, $envvar_args:expr, $expected:expr) => {{
use wasmer_dev_utils::stdio::StdioCapturer;
2019-11-21 21:36:44 +00:00
use wasmer_runtime::Func;
2019-05-17 19:09:31 +00:00
use wasmer_wasi::generate_import_object;
let wasm_bytes = include_bytes!($file);
2019-11-21 21:36:44 +00:00
let module = wasmer_runtime::compile(&wasm_bytes[..])
2019-05-17 19:09:31 +00:00
.expect("WASM can't be compiled");
2019-07-17 22:47:59 +00:00
let import_object = generate_import_object(vec![], vec![], $po_dir_args, $mapdir_args);
2019-05-17 19:09:31 +00:00
let instance = module
.instantiate(&import_object)
.map_err(|err| format!("Can't instantiate the WebAssembly module: {:?}", err))
.unwrap(); // NOTE: Need to figure what the unwrap is for ??
let capturer = StdioCapturer::new();
let start: Func<(), ()> = instance
.func("_start")
.map_err(|e| format!("{:?}", e))
.expect("start function in wasi module");
start.call().expect("execute the wasm");
2019-05-17 19:09:31 +00:00
let output = capturer.end().unwrap().0;
let expected_output = include_str!($expected);
assert!(
output.contains(expected_output),
"Output: `{}` does not contain expected output: `{}`",
output,
expected_output
);
}};
}