summaryrefslogtreecommitdiff
path: root/dhall/build.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-24 17:59:57 +0100
committerNadrieril2019-03-24 18:00:55 +0100
commita6f61ec4843f4ec91eb9651b79c8b843fb995b46 (patch)
tree1c082c2e820f117fb86c69f7ba9b659b8af7ac2f /dhall/build.rs
parent8bae9a8fab523668e9aea96e4f32cec21e22998a (diff)
Generate parser tests list automatically
Diffstat (limited to 'dhall/build.rs')
-rw-r--r--dhall/build.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/dhall/build.rs b/dhall/build.rs
new file mode 100644
index 0000000..c8ad6ad
--- /dev/null
+++ b/dhall/build.rs
@@ -0,0 +1,42 @@
+use std::env;
+use std::ffi::OsString;
+use std::fs::{self, File};
+use std::io::Write;
+use std::path::Path;
+
+fn dhall_files_in_dir<'a>(dir: &'a Path) -> impl Iterator<Item = String> + 'a {
+ fs::read_dir(dir).unwrap().filter_map(move |path| {
+ let path = path.unwrap().path();
+ let path = path.strip_prefix(dir).unwrap();
+ if path.extension() != Some(&OsString::from("dhall")) {
+ return None;
+ }
+ let path = path.to_string_lossy();
+ let path = path[..path.len() - 6].to_owned();
+ Some(path)
+ })
+}
+
+fn main() -> std::io::Result<()> {
+ let out_dir = env::var("OUT_DIR").unwrap();
+ let tests_dir = Path::new("../dhall-lang/tests/");
+
+ let parser_tests_path = Path::new(&out_dir).join("parser_tests.rs");
+ let mut file = File::create(parser_tests_path)?;
+
+ for path in dhall_files_in_dir(&tests_dir.join("parser/success/")) {
+ let name = &path[..path.len() - 1];
+ // Skip this test; parser is way too slow indebug mode
+ if name == "largeExpression" {
+ continue;
+ }
+ writeln!(file, r#"make_spec_test!(ParserSuccess, spec_parser_success_{0}, "{0}");"#, name)?;
+ }
+
+ for path in dhall_files_in_dir(&tests_dir.join("parser/failure/")) {
+ let name = &path;
+ writeln!(file, r#"make_spec_test!(ParserFailure, spec_parser_failure_{0}, "{0}");"#, name)?;
+ }
+
+ Ok(())
+}