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(); output += &build_test_case(lox_file); } std::fs::write("tests/all_tests.rs", output).unwrap(); }