autogenerate test suite

This commit is contained in:
Moritz Gmeiner 2024-09-02 15:35:28 +02:00
commit 274faf1e0a
7 changed files with 332 additions and 1732 deletions

48
interpreter/build.rs Normal file
View file

@ -0,0 +1,48 @@
use std::path::PathBuf;
use glob::glob;
fn main() {
generate_tests();
}
fn build_test_case(path: PathBuf) -> String {
let mut test_name = path.clone();
test_name.set_extension("");
let mut components = test_name.components();
components.next();
components.next();
let mut test_name = components.as_path().to_str().unwrap().to_owned();
test_name = test_name.replace('/', "_");
format!(
"\n\n#[test]
fn test_{}() {{
run_test(\"{}\");
}}",
test_name,
path.to_str().unwrap()
)
}
fn generate_tests() {
let preamble = "mod common;\n\nuse common::run_test;";
let mut output = preamble.to_owned();
for lox_file in glob("tests/lox/**/*.lox").unwrap() {
let lox_file = lox_file.unwrap();
println!("found lox file: {}", lox_file.to_str().unwrap());
output += &build_test_case(lox_file);
}
println!("{output}");
std::fs::write("tests/all_tests.rs", output).unwrap();
}