PkmnLib_rs/build.rs

50 lines
1.3 KiB
Rust

use std::io::Write;
fn main() {
let files = std::fs::read_dir("tests/test_cases").unwrap();
let mut output_file = std::fs::File::create("tests/datatests/mod.rs").unwrap();
output_file
.write_all(
b"// This file is generated by build.rs
use super::common::TestCase;
use super::get_library;
use std::fs::File;
use std::io::Read;
use std::path::Path;
fn integration_tests(input: &Path) {
let mut str: String = \"\".to_string();
let mut file = File::open(input).unwrap();
file.read_to_string(&mut str).unwrap();
let test_case = serde_yaml::from_str::<TestCase>(&str).unwrap();
println!(\"\tRunning integration test {}\", test_case.name);
test_case.run_test(get_library());
}
",
)
.unwrap();
for file in files {
let file = file.unwrap();
let path = file.path();
let path_str = path.to_str().unwrap();
if path_str.ends_with(".yaml") {
println!("cargo:rerun-if-changed={}", path_str);
}
let file_name = path.file_stem().unwrap().to_str().unwrap();
write!(
output_file,
"
#[test]
fn {}() {{
integration_tests(Path::new(\"{}\"));
}}
",
file_name,
path.to_str().unwrap(),
)
.unwrap();
}
}