mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
48 lines
988 B
Rust
48 lines
988 B
Rust
|
|
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();
|
||
|
|
}
|