summaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-07 14:42:25 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-07 14:42:25 +0100
commitf364395e1d774456500ea61bb7b931f48a62ddfa (patch)
treeb4d66bd44c619d8ff93f36686c91752910fa4768 /build.rs
parent1099330988da78c82c6e155fab88d81fb2f1d4c0 (diff)
Create parsing test harness ⚡
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/build.rs b/build.rs
new file mode 100644
index 00000000..c91db8e0
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,34 @@
+use std::fs;
+use std::ffi::OsStr;
+
+fn main() {
+ println!("cargo:rerun-if-changed=build.rs");
+ println!("cargo:rerun-if-changed=tests/parsing");
+
+ fs::create_dir_all("tests/cache").unwrap();
+
+ let paths = fs::read_dir("tests/parsing").unwrap()
+ .map(|entry| entry.unwrap().path())
+ .filter(|path| path.extension() == Some(OsStr::new("rs")));
+
+ let mut code = "vec![".to_string();
+ for path in paths {
+ let name = path.file_stem().unwrap().to_str().unwrap();
+ let file = fs::read_to_string(&path).unwrap();
+
+ println!("cargo:rerun-if-changed=tests/parsing/{}.rs", name);
+
+ code.push_str(&format!("(\"{}\", tokens!{{", name));
+
+ for (index, line) in file.lines().enumerate() {
+ let mut line = line.replace("=>", &format!("=>({})=>", index + 1));
+ line.push('\n');
+ code.push_str(&line);
+ }
+
+ code.push_str("}),");
+ }
+ code.push(']');
+
+ fs::write("tests/cache/parsing.rs", code).unwrap();
+}