-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
52 lines (43 loc) · 1.29 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Test generation build tool is inspired by this blog post
// https://blog.cyplo.dev/posts/2018/12/generate-rust-tests-from-data/
use std::env;
use std::fs::read_dir;
use std::fs::DirEntry;
use std::fs::File;
use std::io::Write;
use std::path::Path;
// build script's entry point
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let destination = Path::new(&out_dir).join("transpilation_tests.rs");
let mut test_file = File::create(&destination).unwrap();
// write test file header, put `use`, `const` etc there
write_header(&mut test_file);
let test_data_files = read_dir("./tests/transpilations/").unwrap();
for entry in test_data_files {
write_test(&mut test_file, &entry.unwrap());
}
}
fn write_test(test_file: &mut File, entry: &DirEntry) {
let directory = entry.path().canonicalize().unwrap();
let path = directory.display();
let test_name = format!(
"transpile_{}",
directory.file_stem().unwrap().to_string_lossy()
);
write!(
test_file,
include_str!("./tests/transpile_template.txt"),
name = test_name,
path = path
)
.unwrap();
}
fn write_header(test_file: &mut File) {
write!(
test_file,
r#"use taro::ir::test_utils::utils::final_codegen;
"#
)
.unwrap();
}