forked from wasmerio/wasmer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c541521
commit dfb7432
Showing
3 changed files
with
106 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
//! Here we define the processors usable for each test genrator | ||
use crate::{Test, Testsuite, extract_name}; | ||
use std::path::PathBuf; | ||
|
||
/// Given a Testsuite and a path, process the path in case is a wast | ||
/// file. | ||
pub fn wast_processor(out: &mut Testsuite, p: PathBuf) -> Option<Test> { | ||
let ext = p.extension()?; | ||
// Only look at wast files. | ||
if ext != "wast" { | ||
return None; | ||
} | ||
|
||
// Ignore files starting with `.`, which could be editor temporary files | ||
if p.file_stem()?.to_str()?.starts_with(".") { | ||
return None; | ||
} | ||
|
||
let testname = extract_name(&p); | ||
let compiler = out.path.get(0).unwrap(); | ||
|
||
// The implementation of `run_wast` lives in /tests/spectest.rs | ||
let body = format!("crate::run_wast(r#\"{}\"#, \"{}\")", p.display(), compiler); | ||
|
||
Some(Test { | ||
name: testname.to_string(), | ||
body: body.to_string(), | ||
}) | ||
} | ||
|
||
/// Given a Testsuite and a path, process the path in case is a Emscripten | ||
/// wasm file. | ||
pub fn emscripten_processor(out: &mut Testsuite, p: PathBuf) -> Option<Test> { | ||
let ext = p.extension()?; | ||
// Only look at wast files. | ||
if ext != "wasm" { | ||
return None; | ||
} | ||
|
||
let outfile = { | ||
let mut out_ext = p.clone(); | ||
out_ext.set_extension("out"); | ||
if out_ext.exists() { | ||
out_ext | ||
} else { | ||
return None; | ||
} | ||
}; | ||
|
||
let testname = extract_name(&p); | ||
let compiler = out.path.get(0).unwrap(); | ||
|
||
// The implementation of `run_emscripten` lives in /tests/emtest.rs | ||
let body = format!( | ||
"crate::run_emscripten(r#\"{}\"#, r#\"{}\"#, \"{}\")", | ||
p.display(), | ||
outfile.display(), | ||
compiler | ||
); | ||
|
||
Some(Test { | ||
name: testname.to_string(), | ||
body: body.to_string(), | ||
}) | ||
} | ||
|
||
/// Given a Testsuite and a path, process the path in case is a WASI | ||
/// wasm file. | ||
pub fn wasi_processor(out: &mut Testsuite, p: PathBuf) -> Option<Test> { | ||
let ext = p.extension()?; | ||
// Only look at wast files. | ||
if ext != "wasm" { | ||
return None; | ||
} | ||
|
||
let outfile = { | ||
let mut out_ext = p.clone(); | ||
out_ext.set_extension("out"); | ||
if out_ext.exists() { | ||
out_ext | ||
} else { | ||
return None; | ||
} | ||
}; | ||
|
||
let testname = extract_name(&p); | ||
let compiler = out.path.get(0).unwrap(); | ||
|
||
// The implementation of `run_wasi` lives in /tests/wasitest.rs | ||
let body = format!( | ||
"crate::run_wasi(r#\"{}\"#, r#\"{}\"#, \"{}\")", | ||
p.display(), | ||
outfile.display(), | ||
compiler | ||
); | ||
|
||
Some(Test { | ||
name: testname.to_string(), | ||
body: body.to_string(), | ||
}) | ||
} |