Skip to content

Commit

Permalink
Add a spec testsuite submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Dec 5, 2018
1 parent 04b7f0c commit e06b99b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/wast/spec_testsuite"]
path = lib/wast/spec_testsuite
url = https://github.com/WebAssembly/testsuite
73 changes: 52 additions & 21 deletions lib/wast/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,63 @@ fn main() {
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")
test_directory(&mut out, "misc_testsuite");
test_directory(&mut out, "spec_testsuite");
}

fn test_directory(out: &mut File, testsuite: &str) {
let mut dir_entries: Vec<_> = read_dir(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('.');
.filter(|dir_entry| {
let p = dir_entry.path();
if let Some(ext) = p.extension() {
// Only look at wast files.
if ext == "wast" {
// Ignore files starting with `.`, which could be editor temporary files
if let Some(stem) = p.file_stem() {
if let Some(stemstr) = stem.to_str() {
if !stemstr.starts_with('.') {
return true;
}
}
}
}
}
false
}).collect();

paths.sort_by_key(|dir| dir.path());
for path in paths {
let path = path.path();
writeln!(out, "#[test]");
dir_entries.sort_by_key(|dir| dir.path());

writeln!(out, "mod {} {{", testsuite);
writeln!(out, " use super::{{native_isa, wast_file, Path}};");
for dir_entry in dir_entries {
let path = dir_entry.path();
let stemstr = path
.file_stem()
.expect("file_stem")
.to_str()
.expect("to_str");

writeln!(out, " #[test]");
if ignore(testsuite, stemstr) {
writeln!(out, " #[ignore]");
}
writeln!(
out,
"fn {}() {{",
avoid_keywords(
&path
.file_stem()
.expect("file_stem")
.to_str()
.expect("to_str")
.replace("-", "_")
)
" fn {}() {{",
avoid_keywords(&stemstr.replace("-", "_"))
);
writeln!(
out,
" wast_file(Path::new(\"{}\"), &*native_isa()).expect(\"error loading wast file {}\");",
" wast_file(Path::new(\"{}\"), &*native_isa()).expect(\"error loading wast file {}\");",
path.display(),
path.display()
);
writeln!(out, "}}");
writeln!(out, " }}");
writeln!(out);
}
writeln!(out, "}}");
}

fn avoid_keywords(name: &str) -> &str {
Expand All @@ -59,3 +78,15 @@ fn avoid_keywords(name: &str) -> &str {
other => other,
}
}

fn ignore(testsuite: &str, name: &str) -> bool {
match testsuite {
"spec_testsuite" => match name {
// These are the remaining spec testsuite failures.
"call_indirect" | "data" | "elem" | "exports" | "func" | "func_ptrs" | "globals"
| "imports" | "linking" | "names" | "start" => true,
_ => false,
},
_ => false,
}
}
1 change: 1 addition & 0 deletions lib/wast/spec_testsuite
Submodule spec_testsuite added at b28006

0 comments on commit e06b99b

Please sign in to comment.