diff options
author | Nadrieril Feneanar | 2020-02-09 20:12:13 +0000 |
---|---|---|
committer | GitHub | 2020-02-09 20:12:13 +0000 |
commit | 75889ac64e2d04dfd7c00fc59e29e4530e69cc9a (patch) | |
tree | cf28b0104879bd73802c4a21c4ca76b298d1cb04 /dhall/build.rs | |
parent | 5abc0628058a318782c46614d943c034711845c6 (diff) | |
parent | 4c2a28b844b18d7b67278a1c8f628d9a95ea37c4 (diff) |
Merge pull request #130 from Nadrieril/improve-tests
Improve the test harness
Diffstat (limited to '')
-rw-r--r-- | dhall/build.rs | 79 |
1 files changed, 46 insertions, 33 deletions
diff --git a/dhall/build.rs b/dhall/build.rs index 83c154e..8deb637 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -2,15 +2,19 @@ use std::env; use std::ffi::OsString; use std::fs::{read_to_string, File}; use std::io::{BufRead, BufReader, Write}; -use std::path::Path; +use std::path::{Path, PathBuf}; use walkdir::WalkDir; use abnf_to_pest::render_rules_to_pest; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] enum FileType { + /// Dhall source file Text, + /// Dhall binary file Binary, + /// Text file with expected text output + UI, } impl FileType { @@ -18,8 +22,23 @@ impl FileType { match self { FileType::Text => "dhall", FileType::Binary => "dhallb", + FileType::UI => "txt", } } + fn constructor(self) -> &'static str { + match self { + FileType::Text => "TestFile::Source", + FileType::Binary => "TestFile::Binary", + FileType::UI => "TestFile::UI", + } + } + fn construct(self, path: &str) -> String { + // e.g. with + // path = "tests/foor/barA" + // returns something like: + // TestFile::Source("tests/foor/barA.dhall") + format!(r#"{}("{}.{}")"#, self.constructor(), path, self.to_ext()) + } } fn dhall_files_in_dir<'a>( @@ -72,7 +91,8 @@ fn make_test_module( mut feature: TestFeature, ) -> std::io::Result<()> { writeln!(w, "mod {} {{", feature.module_name)?; - let take_ab_suffix = feature.output_type.is_some(); + let take_ab_suffix = feature.output_type.is_some() + && feature.output_type != Some(FileType::UI); for base_path in base_paths { let tests_dir = base_path.join(feature.directory); for (name, path) in @@ -85,22 +105,26 @@ fn make_test_module( let path = path.to_string_lossy(); let test = match feature.output_type { None => { - let input_file = - format!("\"{}.{}\"", path, feature.input_type.to_ext()); - format!("{}({})", feature.variant, input_file) + let input = feature.input_type.construct(&path); + format!("{}({})", feature.variant, input) } - Some(output_type) => { - let input_file = format!( - "\"{}A.{}\"", - path, - feature.input_type.to_ext() + Some(output_type @ FileType::UI) => { + let input = feature.input_type.construct(&path); + // All ui outputs are in the local `tests/` directory. + let output_file = PathBuf::from("tests/").join( + PathBuf::from(path.as_ref()) + .strip_prefix(base_path) + .unwrap(), ); - let output_file = - format!("\"{}B.{}\"", path, output_type.to_ext()); - format!( - "{}({}, {})", - feature.variant, input_file, output_file - ) + let output = + output_type.construct(&output_file.to_str().unwrap()); + format!("{}({}, {})", feature.variant, input, output) + } + Some(output_type) => { + let input = + feature.input_type.construct(&format!("{}A", path)); + let output = output_type.construct(&format!("{}B", path)); + format!("{}({}, {})", feature.variant, input, output) } }; writeln!(w, "make_spec_test!({}, {});", test, name)?; @@ -148,7 +172,7 @@ fn generate_tests() -> std::io::Result<()> { variant: "ParserFailure", path_filter: Box::new(|_path: &str| false), input_type: FileType::Text, - output_type: None, + output_type: Some(FileType::UI), }, TestFeature { module_name: "printer", @@ -208,7 +232,7 @@ fn generate_tests() -> std::io::Result<()> { variant: "BinaryDecodingFailure", path_filter: Box::new(|_path: &str| false), input_type: FileType::Binary, - output_type: None, + output_type: Some(FileType::UI), }, TestFeature { module_name: "import_success", @@ -243,7 +267,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "customHeadersUsingBoundVariable" }), input_type: FileType::Text, - output_type: None, + output_type: Some(FileType::UI), }, TestFeature { module_name: "beta_normalize", @@ -265,6 +289,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "prelude/JSON/number/1" // TODO: doesn't typecheck || path == "unit/RightBiasedRecordMergeWithinRecordProjection" + || path == "unit/Sort" // // TODO: Further record simplifications || path == "simplifications/rightBiasedMergeWithinRecordProjectionWithinFieldSelection0" || path == "simplifications/rightBiasedMergeWithinRecordProjectionWithinFieldSelection1" @@ -314,19 +339,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/MergeHandlerFreeVar" }), input_type: FileType::Text, - output_type: None, - }, - TestFeature { - module_name: "type_error", - directory: "type-inference/failure/", - variant: "TypeError", - path_filter: Box::new(|path: &str| { - false - // TODO: enable free variable checking - || path == "unit/MergeHandlerFreeVar" - }), - input_type: FileType::Text, - output_type: None, + output_type: Some(FileType::UI), }, ]; |