use std::fmt::Write;
use std::fs;
use std::path::Path;
use indoc::indoc;
fn main() {
update_tests();
}
const TEST_PREFIX: &str = "// autogenerated file, do not edit manually
//! Runner for the `.test` integration test format
#![cfg_attr(rustfmt, rustfmt_skip)] // FIXME: generate these in `OUTPUT_DIR` rather than `src`
use test_util::TestManager;
";
fn update_tests() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let suite_dir = root.join("tests/suite");
let test_paths = fs::read_dir(suite_dir).unwrap();
let mut to_write = TEST_PREFIX.to_owned();
for path in test_paths {
let path = path.unwrap().path();
let fname = path.file_name().unwrap().to_string_lossy();
let test_name = fname
.strip_suffix(".test")
.unwrap()
.trim_start_matches(char::is_numeric)
.trim_start_matches('_');
if test_name == "example" {
continue;
}
write!(
to_write,
indoc! {"
#[test]
fn test_{test_name}() {{
let path = concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/tests/suite/{fname}\");
let mgr = TestManager::new_from_file(path);
let dict = mgr.build_dict();
mgr.check_all(&dict);
}}
"},
test_name = test_name,
fname = fname,
)
.unwrap();
}
let out_path = root.join("tests/auto_suite.rs");
fs::write(out_path, to_write).unwrap();
}