mirror of
https://github.com/MorizzG/rlox.git
synced 2025-12-06 04:12:42 +00:00
autogenerate test suite
This commit is contained in:
parent
76bf3a2a07
commit
274faf1e0a
7 changed files with 332 additions and 1732 deletions
48
interpreter/build.rs
Normal file
48
interpreter/build.rs
Normal 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();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue