-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
37 lines (35 loc) · 997 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use std::env;
use std::error::Error;
use std::fmt::Write;
use std::fs;
use std::path::Path;
pub fn main() -> Result<(), Box<dyn Error>> {
gen("pass")?;
gen("fail")
}
// Create a file named {tag}.rs with a integration
// test for each python file in tests/tag/
// See how the tests are run in src/integration.rs
pub fn gen(tag: &str) -> Result<(), Box<dyn Error>> {
let mut content = String::new();
for file in fs::read_dir(Path::new("tests").join(tag))? {
let file = file?.path();
if file.extension().map(|s| s != "py").unwrap_or(true) {
continue;
}
let filename = file.file_stem().unwrap();
writeln!(
&mut content,
"#[test] fn {}_{}() {{ {}({:?}) }}",
tag,
filename.to_string_lossy(),
tag,
file,
)?;
}
let out = Path::new(&env::var("OUT_DIR")?)
.join(tag)
.with_extension("rs");
fs::write(out, content)?;
Ok(())
}