From 6e0d808e0f5683de942d912231fa10211b6d1377 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 18:08:21 +0000 Subject: Put test builders in a vec --- dhall/build.rs | 112 +++++++++++++++++---------------------------------------- 1 file changed, 33 insertions(+), 79 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 3021f03..9d97839 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -51,8 +51,7 @@ fn dhall_files_in_dir<'a>( }) } -#[derive(Debug, Clone)] -struct TestFeature { +struct TestFeature { /// Name of the module, used in the output of `cargo test` module_name: &'static str, /// Directory containing the tests files @@ -60,7 +59,7 @@ struct TestFeature { /// Relevant variant of `dhall::tests::Test` variant: &'static str, /// Given a file name, whether to exclude it - path_filter: F, + path_filter: Box bool>, /// Type of the input file input_type: FileType, /// Type of the output file, if any @@ -69,7 +68,7 @@ struct TestFeature { fn make_test_module( w: &mut impl Write, // Where to output the generated code - mut feature: TestFeature bool>, + mut feature: TestFeature, ) -> std::io::Result<()> { let tests_dir = feature.directory; writeln!(w, "mod {} {{", feature.module_name)?; @@ -113,15 +112,13 @@ fn generate_tests() -> std::io::Result<()> { let parser_tests_path = Path::new(&out_dir).join("spec_tests.rs"); let spec_tests_dir = Path::new("../dhall-lang/tests/"); - let mut file = File::create(parser_tests_path)?; - make_test_module( - &mut file, + let tests = vec![ TestFeature { module_name: "parser_success", directory: spec_tests_dir.join("parser/success/"), variant: "ParserSuccess", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false // Too slow in debug mode || path == "largeExpression" @@ -131,31 +128,23 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" - }, + }), input_type: FileType::Text, output_type: Some(FileType::Binary), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "parser_failure", directory: spec_tests_dir.join("parser/failure/"), variant: "ParserFailure", - path_filter: |_path: &str| false, + path_filter: Box::new(|_path: &str| false), input_type: FileType::Text, output_type: None, }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "printer", directory: spec_tests_dir.join("parser/success/"), variant: "Printer", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false // Too slow in debug mode || path == "largeExpression" @@ -163,19 +152,15 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" - }, + }), input_type: FileType::Text, output_type: Some(FileType::Binary), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "binary_encoding", directory: spec_tests_dir.join("parser/success/"), variant: "BinaryEncoding", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false // Too slow in debug mode || path == "largeExpression" @@ -189,43 +174,31 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" - }, + }), input_type: FileType::Text, output_type: Some(FileType::Binary), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "binary_decoding_success", directory: spec_tests_dir.join("binary-decode/success/"), variant: "BinaryDecodingSuccess", - path_filter: |_path: &str| false, + path_filter: Box::new(|_path: &str| false), input_type: FileType::Binary, output_type: Some(FileType::Text), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "binary_decoding_failure", directory: spec_tests_dir.join("binary-decode/failure/"), variant: "BinaryDecodingFailure", - path_filter: |_path: &str| false, + path_filter: Box::new(|_path: &str| false), input_type: FileType::Binary, output_type: None, }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "import_success", directory: spec_tests_dir.join("import/success/"), variant: "ImportSuccess", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false || path == "alternativeEnvNatural" || path == "alternativeEnvSimple" @@ -236,38 +209,30 @@ fn generate_tests() -> std::io::Result<()> { || path == "hashFromCache" || path == "headerForwarding" || path == "noHeaderForwarding" - }, + }), input_type: FileType::Text, output_type: Some(FileType::Text), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "import_failure", directory: spec_tests_dir.join("import/failure/"), variant: "ImportFailure", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false || path == "alternativeEnv" || path == "alternativeEnvMissing" || path == "hashMismatch" || path == "missing" || path == "referentiallyInsane" - }, + }), input_type: FileType::Text, output_type: None, }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "beta_normalize", directory: spec_tests_dir.join("normalization/success/"), variant: "Normalization", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { // We don't support bignums path == "simple/integerToDouble" // Too slow @@ -301,34 +266,26 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/RightBiasedMergeEquivalentArguments" || path == "unit/NestedRecordProjection" || path == "unit/NestedRecordProjectionByType" - }, + }), input_type: FileType::Text, output_type: Some(FileType::Text), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "alpha_normalize", directory: spec_tests_dir.join("alpha-normalization/success/"), variant: "AlphaNormalization", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { // This test doesn't typecheck path == "unit/FunctionNestedBindingXXFree" - }, + }), input_type: FileType::Text, output_type: Some(FileType::Text), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "type_inference_success", directory: spec_tests_dir.join("type-inference/success/"), variant: "TypeInferenceSuccess", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false // Too slow || path == "prelude" @@ -340,19 +297,15 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/ToMap" || path == "unit/ToMapAnnotated" || path == "simple/toMapEmptyNormalizeAnnotation" - }, + }), input_type: FileType::Text, output_type: Some(FileType::Text), }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "type_inference_failure", directory: spec_tests_dir.join("type-inference/failure/"), variant: "TypeInferenceFailure", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false // TODO: Enable imports in typecheck tests || path == "importBoundary" @@ -369,19 +322,15 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/MistypedToMap4" || path == "unit/NonRecordToMap" || path == "unit/ToMapWrongKind" - }, + }), input_type: FileType::Text, output_type: None, }, - )?; - - make_test_module( - &mut file, TestFeature { module_name: "type_error", directory: spec_tests_dir.join("type-inference/failure/"), variant: "TypeError", - path_filter: |path: &str| { + path_filter: Box::new(|path: &str| { false // TODO: Enable imports in typecheck tests || path == "importBoundary" @@ -398,11 +347,16 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/MistypedToMap4" || path == "unit/NonRecordToMap" || path == "unit/ToMapWrongKind" - }, + }), input_type: FileType::Text, output_type: None, }, - )?; + ]; + + let mut file = File::create(parser_tests_path)?; + for test in tests { + make_test_module(&mut file, test)?; + } Ok(()) } -- cgit v1.2.3 From fa6de4c077ab4f1c28d2ec64a33a3be8c5a9bb1c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 18:24:21 +0000 Subject: Update dhall-lang submodule --- dhall/build.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 9d97839..3e7c023 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -296,6 +296,7 @@ fn generate_tests() -> std::io::Result<()> { // TODO: toMap || path == "unit/ToMap" || path == "unit/ToMapAnnotated" + || path == "unit/ToMapInferTypeFromRecord" || path == "simple/toMapEmptyNormalizeAnnotation" }), input_type: FileType::Text, @@ -321,6 +322,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/MistypedToMap3" || path == "unit/MistypedToMap4" || path == "unit/NonRecordToMap" + || path == "unit/ToMapEmptyInvalidAnnotation" || path == "unit/ToMapWrongKind" }), input_type: FileType::Text, @@ -346,6 +348,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/MistypedToMap3" || path == "unit/MistypedToMap4" || path == "unit/NonRecordToMap" + || path == "unit/ToMapEmptyInvalidAnnotation" || path == "unit/ToMapWrongKind" }), input_type: FileType::Text, -- cgit v1.2.3 From 54d7e61ad40682ee24e36288980ee4164ea87c34 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 18:38:05 +0000 Subject: Update dhall-lang submodule --- dhall/build.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 3e7c023..e06f9b3 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -224,6 +224,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "hashMismatch" || path == "missing" || path == "referentiallyInsane" + || path == "customHeadersUsingBoundVariable" }), input_type: FileType::Text, output_type: None, @@ -308,9 +309,6 @@ fn generate_tests() -> std::io::Result<()> { variant: "TypeInferenceFailure", path_filter: Box::new(|path: &str| { false - // TODO: Enable imports in typecheck tests - || path == "importBoundary" - || path == "customHeadersUsingBoundVariable" // TODO: projection by expression || path == "unit/RecordProjectionByTypeFieldTypeMismatch" || path == "unit/RecordProjectionByTypeNotPresent" @@ -334,9 +332,6 @@ fn generate_tests() -> std::io::Result<()> { variant: "TypeError", path_filter: Box::new(|path: &str| { false - // TODO: Enable imports in typecheck tests - || path == "importBoundary" - || path == "customHeadersUsingBoundVariable" // TODO: projection by expression || path == "unit/RecordProjectionByTypeFieldTypeMismatch" || path == "unit/RecordProjectionByTypeNotPresent" -- cgit v1.2.3 From e294450e1e76491e96019b8a3695463e09d1739b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 19:02:18 +0000 Subject: Implement parsing for record completion --- 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 e06f9b3..ec06ece 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -267,6 +267,9 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/RightBiasedMergeEquivalentArguments" || path == "unit/NestedRecordProjection" || path == "unit/NestedRecordProjectionByType" + // TODO: record completion + || path == "simple/completion" + || path == "unit/Completion" }), input_type: FileType::Text, output_type: Some(FileType::Text), @@ -299,6 +302,9 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/ToMapAnnotated" || path == "unit/ToMapInferTypeFromRecord" || path == "simple/toMapEmptyNormalizeAnnotation" + // TODO: record completion + || path == "simple/completion" + || path == "unit/Completion" }), input_type: FileType::Text, output_type: Some(FileType::Text), @@ -322,6 +328,11 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/NonRecordToMap" || path == "unit/ToMapEmptyInvalidAnnotation" || path == "unit/ToMapWrongKind" + // TODO: record completion + || path == "unit/CompletionMissingRequiredField" + || path == "unit/CompletionWithWrongDefaultType" + || path == "unit/CompletionWithWrongFieldName" + || path == "unit/CompletionWithWrongOverridenType" }), input_type: FileType::Text, output_type: None, @@ -345,6 +356,11 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/NonRecordToMap" || path == "unit/ToMapEmptyInvalidAnnotation" || path == "unit/ToMapWrongKind" + // TODO: record completion + || path == "unit/CompletionMissingRequiredField" + || path == "unit/CompletionWithWrongDefaultType" + || path == "unit/CompletionWithWrongFieldName" + || path == "unit/CompletionWithWrongOverridenType" }), input_type: FileType::Text, output_type: None, -- cgit v1.2.3 From 4322d1b0b7041eb160b1baadf9f6e63f0d4e9d9c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 19:43:32 +0000 Subject: Update abnf dependency in the hopes of fixing a bug --- dhall/build.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index ec06ece..2a65f24 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -1,7 +1,7 @@ use std::env; use std::ffi::OsString; -use std::fs::File; -use std::io::{BufRead, BufReader, Read, Write}; +use std::fs::{read_to_string, File}; +use std::io::{BufRead, BufReader, Write}; use std::path::{Path, PathBuf}; use walkdir::WalkDir; @@ -383,10 +383,8 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { println!("cargo:rerun-if-changed={}", abnf_path); println!("cargo:rerun-if-changed={}", visibility_path); - let mut file = File::open(abnf_path)?; - let mut data = Vec::new(); - file.read_to_end(&mut data)?; - data.push('\n' as u8); + let mut data = read_to_string(abnf_path)?; + data.push('\n'); let mut rules = abnf_to_pest::parse_abnf(&data)?; for line in BufReader::new(File::open(visibility_path)?).lines() { -- cgit v1.2.3 From cb2097ed82c7aa23f555cb27a7e27a32863de09a Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 22 Dec 2019 20:08:42 +0000 Subject: Update dhall-lang submodule --- dhall/build.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 2a65f24..7beaa9f 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -128,6 +128,8 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" + // TODO: https://github.com/dhall-lang/dhall-lang/pull/788#issuecomment-568298973 + || path == "preferMissingNoSpaces" }), input_type: FileType::Text, output_type: Some(FileType::Binary), @@ -152,6 +154,8 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" + // TODO: https://github.com/dhall-lang/dhall-lang/pull/788#issuecomment-568298973 + || path == "preferMissingNoSpaces" }), input_type: FileType::Text, output_type: Some(FileType::Binary), @@ -174,6 +178,8 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" + // TODO: https://github.com/dhall-lang/dhall-lang/pull/788#issuecomment-568298973 + || path == "preferMissingNoSpaces" }), input_type: FileType::Text, output_type: Some(FileType::Binary), @@ -385,6 +391,7 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { let mut data = read_to_string(abnf_path)?; data.push('\n'); + let data = data.replace('∀', ""); // See https://github.com/duesee/abnf/issues/11 let mut rules = abnf_to_pest::parse_abnf(&data)?; for line in BufReader::new(File::open(visibility_path)?).lines() { @@ -401,6 +408,12 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { rules.remove("url_path"); writeln!(&mut file, "url_path = _{{ path }}")?; + rules.remove("missing"); + writeln!( + &mut file, + r#"missing = {{ "missing" ~ !simple_label_next_char }}"# + )?; + rules.remove("simple_label"); writeln!( &mut file, -- cgit v1.2.3 From a93065fce4c55188122bee02a11d8990b0d154ce Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 23 Dec 2019 22:05:23 +0000 Subject: Update dhall-lang submodule --- dhall/build.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 7beaa9f..70389bf 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -188,7 +188,13 @@ fn generate_tests() -> std::io::Result<()> { module_name: "binary_decoding_success", directory: spec_tests_dir.join("binary-decode/success/"), variant: "BinaryDecodingSuccess", - path_filter: Box::new(|_path: &str| false), + path_filter: Box::new(|path: &str| { + false + // We don't support bignums + || path == "unit/IntegerBigNegative" + || path == "unit/IntegerBigPositive" + || path == "unit/NaturalBig" + }), input_type: FileType::Binary, output_type: Some(FileType::Text), }, -- cgit v1.2.3 From 4c7deccba50cb6d46134362128e3cb25c693c153 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 23 Dec 2019 22:30:27 +0000 Subject: Update dhall-lang submodule --- dhall/build.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 70389bf..981e558 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -414,12 +414,20 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { rules.remove("url_path"); writeln!(&mut file, "url_path = _{{ path }}")?; + // Work around some greediness issue in the grammar. rules.remove("missing"); writeln!( &mut file, r#"missing = {{ "missing" ~ !simple_label_next_char }}"# )?; + // Prefer my nice error message to illegible parse errors. + rules.remove("unicode_escape"); + writeln!( + &mut file, + r#"unicode_escape = _{{ HEXDIG{{4}} | "{{" ~ HEXDIG+ ~ "}}" }}"# + )?; + rules.remove("simple_label"); writeln!( &mut file, -- cgit v1.2.3 From 5f52c5bda0277edd87323eb67dcda721cd18a9d3 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 24 Dec 2019 20:23:19 +0000 Subject: Extend merge to work on Optionals --- dhall/build.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 981e558..3d4a2eb 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -128,7 +128,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" - // TODO: https://github.com/dhall-lang/dhall-lang/pull/788#issuecomment-568298973 + // TODO: waiting for https://github.com/dhall-lang/dhall-lang/pull/871 || path == "preferMissingNoSpaces" }), input_type: FileType::Text, @@ -154,7 +154,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" - // TODO: https://github.com/dhall-lang/dhall-lang/pull/788#issuecomment-568298973 + // TODO: waiting for https://github.com/dhall-lang/dhall-lang/pull/871 || path == "preferMissingNoSpaces" }), input_type: FileType::Text, @@ -178,7 +178,7 @@ fn generate_tests() -> std::io::Result<()> { || path == "unit/import/urls/emptyPath0" || path == "unit/import/urls/emptyPath1" || path == "unit/import/urls/emptyPathSegment" - // TODO: https://github.com/dhall-lang/dhall-lang/pull/788#issuecomment-568298973 + // TODO: waiting for https://github.com/dhall-lang/dhall-lang/pull/871 || path == "preferMissingNoSpaces" }), input_type: FileType::Text, @@ -282,6 +282,9 @@ fn generate_tests() -> std::io::Result<()> { // TODO: record completion || path == "simple/completion" || path == "unit/Completion" + // TODO: waiting for https://github.com/dhall-lang/dhall-lang/pull/871 + || path == "unit/MergeNone" + || path == "unit/MergeSome" }), input_type: FileType::Text, output_type: Some(FileType::Text), @@ -317,6 +320,9 @@ fn generate_tests() -> std::io::Result<()> { // TODO: record completion || path == "simple/completion" || path == "unit/Completion" + // TODO: waiting for https://github.com/dhall-lang/dhall-lang/pull/871 + || path == "unit/MergeNone" + || path == "unit/MergeSome" }), input_type: FileType::Text, output_type: Some(FileType::Text), @@ -423,6 +429,10 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { // Prefer my nice error message to illegible parse errors. rules.remove("unicode_escape"); + rules.remove("unbraced_escape"); + rules.remove("braced_escape"); + rules.remove("braced_codepoint"); + rules.remove("unicode_suffix"); writeln!( &mut file, r#"unicode_escape = _{{ HEXDIG{{4}} | "{{" ~ HEXDIG+ ~ "}}" }}"# -- cgit v1.2.3 From 18dd5ba3ae94fd89dd27c0ae3891ac3e43ace350 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Tue, 24 Dec 2019 20:25:06 +0000 Subject: Note waiting for release of abnf --- dhall/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall/build.rs') diff --git a/dhall/build.rs b/dhall/build.rs index 3d4a2eb..9b00684 100644 --- a/dhall/build.rs +++ b/dhall/build.rs @@ -403,7 +403,7 @@ fn convert_abnf_to_pest() -> std::io::Result<()> { let mut data = read_to_string(abnf_path)?; data.push('\n'); - let data = data.replace('∀', ""); // See https://github.com/duesee/abnf/issues/11 + let data = data.replace('∀', ""); // TODO: waiting for abnf 0.6.1 let mut rules = abnf_to_pest::parse_abnf(&data)?; for line in BufReader::new(File::open(visibility_path)?).lines() { -- cgit v1.2.3