Commit 2fcab3d1 authored by Jeff Smits's avatar Jeff Smits

Yay, generating tests from the dir listing of tests/strc_tests/

parent be22f84a
......@@ -241,7 +241,7 @@ fn write_primitives(file: &mut BufWriter<File>,
}
builder.build(file).unwrap();
}
write!(file, ";\n")?;
writeln!(file, ";")?;
write!(file,
"\
......@@ -273,8 +273,39 @@ fn {}<'a>(offset: usize,
}
fn gen_strc_tests() {
use std::fs::read_dir;
use std::io::Result;
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("strc_tests.rs");
let mut file = BufWriter::new(File::create(&path).unwrap());
for entry in read_dir("tests/strc_tests").unwrap() {
let path = entry.unwrap().path();
if path.is_file() && Some("ctree".as_ref()) == path.extension() {
// TODO: sanatise file_stem so it's likely to be a valid test name?
let test_name = path.file_stem().unwrap().to_str().unwrap().replace('-', "_");
let path_string = path.to_str().unwrap();
write!(file,
r#"
#[test]
fn {}() {{
let str_path = io::find_str_path(None);
let f = ATermFactory::new();
let libraries = iter::once(String::from("libstratego-lib"))
.map(|lib_path| io::read_lib(&f, str_path.as_ref(), &lib_path))
.collect::<Result<_>>();
assert!(libraries.is_ok());
let libraries = libraries.unwrap();
let program = io::read_aterm(&f, &"{}");
assert!(program.is_ok());
let program = program.unwrap();
let term = interpret_main(&f, program, libraries);
assert!(term.is_ok());
let term = term.unwrap();
let mut result = String::new();
assert!(term.to_ascii(&mut result).is_ok());
}}
"#, test_name, path_string).unwrap();
}
}
}
......@@ -10,23 +10,4 @@ use aterm::print::ATermWrite;
use std::iter;
// include!(concat!(env!("OUT_DIR"), "/strc_tests.rs"));
#[test]
fn test01() {
let str_path = io::find_str_path(None);
let f = ATermFactory::new();
let libraries = iter::once(String::from("libstratego-lib"))
.map(|lib_path| io::read_lib(&f, str_path.as_ref(), &lib_path))
.collect::<Result<_>>();
assert!(libraries.is_ok());
let libraries = libraries.unwrap();
let program = io::read_aterm(&f, &"tests/strc_tests/test01.ctree");
assert!(program.is_ok());
let program = program.unwrap();
let term = interpret_main(&f, program, libraries);
assert!(term.is_ok());
let term = term.unwrap();
let mut result = String::new();
assert!(term.to_ascii(&mut result).is_ok());
}
include!(concat!(env!("OUT_DIR"), "/strc_tests.rs"));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment