Added emtests autogenerated tests

This commit is contained in:
Syrus
2018-12-10 18:42:23 -08:00
parent 5796b172d1
commit 43128070b7
10 changed files with 81 additions and 23 deletions

View File

@@ -12,7 +12,8 @@ use std::process::Command;
static BANNER: &str = "// Rust test file autogenerated with cargo build (build/emtests.rs).
// Please do NOT modify it by hand, as it will be reseted on next build.\n";
const TESTS: [&str; 1] = [
const TESTS: [&str; 2] = [
"emtests/puts.c",
"emtests/printf.c"
];
@@ -43,7 +44,7 @@ pub fn compile(file: &str) -> String {
let output_str = output_path.to_str().unwrap();
// Compile to wasm
Command::new("emcc")
let _wasm_compilation = Command::new("emcc")
.arg(file)
.arg("-s").arg("WASM=1")
.arg("-o")
@@ -51,6 +52,10 @@ pub fn compile(file: &str) -> String {
.output()
.expect("failed to execute process");
// panic!("{:?}", wasm_compilation);
// if output.stderr {
// panic!("{}", output.stderr);
// }
// Remove js file
fs::remove_file(output_str).unwrap();
@@ -63,6 +68,19 @@ pub fn compile(file: &str) -> String {
// Write the output to file
fs::write(output_str, output.stdout).expect("Unable to write file");
let rust_test_filepath = format!(
concat!(env!("CARGO_MANIFEST_DIR"), "/src/emtests/{}.rs"),
module_name.as_str()
);
let contents = format!("#[test]
fn test_{module_name}() {{
assert_emscripten_output!(\"../../emtests/{module_name}.wasm\", \"{module_name}\", vec![], \"../../emtests/{module_name}.output\");
}}
", module_name=module_name);
fs::write(&rust_test_filepath, contents.as_bytes()).unwrap();
module_name
// panic!("OUTPUT: {:?}", output);
@@ -78,6 +96,7 @@ pub fn build() {
modules.push(format!("mod {};", moudle_name));
}
modules.insert(0, BANNER.to_string());
modules.insert(1, "// The _common module is not autogenerated, as it provides common macros for the emtests\n#[macro_use]\nmod _common;".to_string());
// We add an empty line
modules.push("".to_string());