From ca93f39201f6f8be9bc1466eed7323d0426e135c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 9 Feb 2020 15:50:58 +0000 Subject: Track output of import errors --- dhall/build.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 83c154e..7733581 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -245,6 +245,22 @@ fn generate_tests() -> std::io::Result<()> { input_type: FileType::Text, output_type: None, }, + TestFeature { + module_name: "import_error", + directory: "import/failure/", + variant: "ImportError", + path_filter: Box::new(|path: &str| { + false + || path == "alternativeEnv" + || path == "alternativeEnvMissing" + || path == "hashMismatch" + || path == "missing" + || path == "referentiallyInsane" + || path == "customHeadersUsingBoundVariable" + }), + input_type: FileType::Text, + output_type: None, + }, TestFeature { module_name: "beta_normalize", directory: "normalization/success/", -- cgit v1.2.3 From 81504a7ee24f22820c6bc85823c879d488710d11 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 9 Feb 2020 17:39:01 +0000 Subject: Massively deduplicate test harness --- dhall/build.rs | 63 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 7733581..3955b3a 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 @ FileType::UI) => { + let input = feature.input_type.construct(&path); + let output_file = PathBuf::from(path.as_ref()) + .strip_prefix(base_path) + .unwrap() + .strip_prefix(feature.directory) + .unwrap() + .to_string_lossy() + .into_owned(); + let output = output_type.construct(&output_file); + format!("{}({}, {})", feature.variant, input, output) } Some(output_type) => { - let input_file = format!( - "\"{}A.{}\"", - path, - feature.input_type.to_ext() - ); - let output_file = - format!("\"{}B.{}\"", path, output_type.to_ext()); - format!( - "{}({}, {})", - feature.variant, input_file, output_file - ) + 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)?; @@ -259,7 +283,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", @@ -281,6 +305,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" @@ -342,7 +367,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/MergeHandlerFreeVar" }), input_type: FileType::Text, - output_type: None, + output_type: Some(FileType::UI), }, ]; -- cgit v1.2.3 From 8abb6c24cd26b64d708a74faaa28cc9294dc3466 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 9 Feb 2020 17:47:58 +0000 Subject: Move ui outputs to a sensible place --- dhall/build.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 3955b3a..67f11e2 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -110,14 +110,14 @@ fn make_test_module( } Some(output_type @ FileType::UI) => { let input = feature.input_type.construct(&path); - let output_file = PathBuf::from(path.as_ref()) - .strip_prefix(base_path) - .unwrap() - .strip_prefix(feature.directory) - .unwrap() - .to_string_lossy() - .into_owned(); - let output = output_type.construct(&output_file); + // 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 = + output_type.construct(&output_file.to_str().unwrap()); format!("{}({}, {})", feature.variant, input, output) } Some(output_type) => { -- cgit v1.2.3 From 02cacfd0360a0acea959c5a9b6d1b7fb0241db81 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 9 Feb 2020 18:35:16 +0000 Subject: Remove distinction between failure and error tests --- dhall/build.rs | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 67f11e2..552966b 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -267,22 +267,6 @@ fn generate_tests() -> std::io::Result<()> { || path == "customHeadersUsingBoundVariable" }), input_type: FileType::Text, - output_type: None, - }, - TestFeature { - module_name: "import_error", - directory: "import/failure/", - variant: "ImportError", - path_filter: Box::new(|path: &str| { - false - || path == "alternativeEnv" - || path == "alternativeEnvMissing" - || path == "hashMismatch" - || path == "missing" - || path == "referentiallyInsane" - || path == "customHeadersUsingBoundVariable" - }), - input_type: FileType::Text, output_type: Some(FileType::UI), }, TestFeature { @@ -355,18 +339,6 @@ 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: Some(FileType::UI), }, ]; -- cgit v1.2.3 From 4c2a28b844b18d7b67278a1c8f628d9a95ea37c4 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 9 Feb 2020 18:40:15 +0000 Subject: Track error output of parsing and binary decoding tests --- dhall/build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 552966b..8deb637 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -172,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", @@ -232,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", -- cgit v1.2.3