Files
wasmer/tests/compilers/wasi.rs
Ivan Enderlin 971915a8c1 test(wasi) Run the WASI test suites with the in-memory FS.
This PR updates how we generate the WASI test suites to test against
the `wasmer_vfs::host_fs` (the default), and `wasmer_vfs::mem_fs`
(that's new).
2021-08-31 11:26:14 +02:00

43 lines
1.1 KiB
Rust

use std::fs::File;
use std::io::Read;
use wasmer_wast::{WasiFileSystemKind, WasiTest};
// The generated tests (from build.rs) look like:
// #[cfg(test)]
// mod [compiler] {
// mod [spec] {
// mod [vfs] {
// #[test]
// fn [test_name]() -> anyhow::Result<()> {
// crate::run_wasi("tests/spectests/[test_name].wast", "[compiler]", WasiFileSystemKind::[vfs])
// }
// }
// }
// }
include!(concat!(env!("OUT_DIR"), "/generated_wasitests.rs"));
pub fn run_wasi(
config: crate::Config,
wast_path: &str,
base_dir: &str,
filesystem_kind: WasiFileSystemKind,
) -> anyhow::Result<()> {
println!("Running wasi wast `{}`", wast_path);
let store = config.store();
let source = {
let mut out = String::new();
let mut f = File::open(wast_path)?;
f.read_to_string(&mut out)?;
out
};
let tokens = WasiTest::lex_string(&source)?;
let wasi_test = WasiTest::parse_tokens(&tokens)?;
let succeeded = wasi_test.run(&store, base_dir, filesystem_kind)?;
assert!(succeeded);
Ok(())
}