This uses a build.rs file to collect all the wast tests and create individual `#[test]` lines for them, so that `cargo test` can run them in parallel.
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
use std::env;
|
|
use std::fs::{read_dir, File};
|
|
use std::io::Write;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let out_dir =
|
|
PathBuf::from(env::var("OUT_DIR").expect("The OUT_DIR environment variable must be set"));
|
|
let mut out =
|
|
File::create(out_dir.join("run_wast_files.rs")).expect("error creating run_wast_files.rs");
|
|
|
|
let mut paths: Vec<_> = read_dir("spec_testsuite")
|
|
.unwrap()
|
|
.map(|r| r.unwrap())
|
|
.filter(|p| {
|
|
// Ignore files starting with `.`, which could be editor temporary files
|
|
if let Some(stem) = p.path().file_stem() {
|
|
if let Some(stemstr) = stem.to_str() {
|
|
return !stemstr.starts_with('.');
|
|
}
|
|
}
|
|
false
|
|
}).collect();
|
|
|
|
paths.sort_by_key(|dir| dir.path());
|
|
for path in paths {
|
|
let path = path.path();
|
|
writeln!(out, "#[test]");
|
|
writeln!(
|
|
out,
|
|
"fn {}() {{",
|
|
path.file_stem()
|
|
.expect("file_stem")
|
|
.to_str()
|
|
.expect("to_str")
|
|
);
|
|
writeln!(
|
|
out,
|
|
" wast_file(Path::new(\"{}\"), &*native_isa()).expect(\"error loading wast file {}\");",
|
|
path.display(),
|
|
path.display()
|
|
);
|
|
writeln!(out, "}}");
|
|
writeln!(out);
|
|
}
|
|
}
|