diff build.rs @ 24:199ba034e4af

Generate tests dynamically based on tests/test_parse_files/ content.
author Bastien Orivel <eijebong@bananium.fr>
date Fri, 03 Jun 2016 22:18:15 +0200
parents
children e0368bea06a6
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,19 @@
+use std::env;
+use std::path::Path;
+use std::io::prelude::*;
+use std::fs::{File, read_dir};
+
+fn main() {
+    let out_dir = env::var("OUT_DIR").unwrap();
+    let path = Path::new(&out_dir).join("generated_parse_tests.rs");
+    let mut f = File::create(&path).unwrap();
+
+    for file in read_dir("tests/test_parse_files").unwrap() {
+        let path = file.unwrap().path();
+        let test_name = path.file_stem().unwrap().to_str().unwrap();
+        let _ = f.write_all(format!("#[test]
+fn {}() {{
+    test_parse_file(\"{}\");
+}}\n", test_name, path.to_str().unwrap()).as_bytes()).unwrap();
+    }
+}