From 9741e3280ed03920732430e7994e1f8482c9ddd6 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 6 Apr 2019 17:48:13 +0200 Subject: s/DhallError/ImportError/ --- dhall/tests/common/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dhall/tests/common/mod.rs') diff --git a/dhall/tests/common/mod.rs b/dhall/tests/common/mod.rs index 397a8ee..e748cf0 100644 --- a/dhall/tests/common/mod.rs +++ b/dhall/tests/common/mod.rs @@ -44,13 +44,13 @@ pub enum Feature { TypeInferenceFailure, } -pub fn read_dhall_file<'i>(file_path: &str) -> Result, DhallError> { +pub fn read_dhall_file<'i>(file_path: &str) -> Result, ImportError> { load_dhall_file(&PathBuf::from(file_path), true) } pub fn read_dhall_file_no_resolve_imports<'i>( file_path: &str, -) -> Result { +) -> Result { load_dhall_file_no_resolve_imports(&PathBuf::from(file_path)) } @@ -93,7 +93,7 @@ pub fn run_test(base_path: &str, feature: Feature) { let err = read_dhall_file_no_resolve_imports(&file_path).unwrap_err(); match err { - DhallError::ParseError(_) => {} + ImportError::ParseError(_) => {} e => panic!("Expected parse error, got: {:?}", e), } } -- cgit v1.2.3 From 396ec334bac1e8d10a2d2b2d683c93e3b2ff4d8d Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 6 Apr 2019 20:04:04 +0200 Subject: Massage import loading into new API Closes #9 --- dhall/tests/common/mod.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'dhall/tests/common/mod.rs') diff --git a/dhall/tests/common/mod.rs b/dhall/tests/common/mod.rs index e748cf0..70b7d81 100644 --- a/dhall/tests/common/mod.rs +++ b/dhall/tests/common/mod.rs @@ -54,6 +54,12 @@ pub fn read_dhall_file_no_resolve_imports<'i>( load_dhall_file_no_resolve_imports(&PathBuf::from(file_path)) } +pub fn load_from_file_str<'i>( + file_path: &str, +) -> Result { + load_from_file(&PathBuf::from(file_path)) +} + pub fn run_test(base_path: &str, feature: Feature) { use self::Feature::*; let base_path_prefix = match feature { @@ -90,8 +96,7 @@ pub fn run_test(base_path: &str, feature: Feature) { } ParserFailure => { let file_path = base_path + ".dhall"; - let err = - read_dhall_file_no_resolve_imports(&file_path).unwrap_err(); + let err = load_from_file_str(&file_path).unwrap_err(); match err { ImportError::ParseError(_) => {} e => panic!("Expected parse error, got: {:?}", e), -- cgit v1.2.3 From 412d0fac51b7b51aabcb049e3d6ba52f3dda1529 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 6 Apr 2019 20:32:25 +0200 Subject: Move binary decoding to new API --- dhall/tests/common/mod.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'dhall/tests/common/mod.rs') diff --git a/dhall/tests/common/mod.rs b/dhall/tests/common/mod.rs index 70b7d81..861df63 100644 --- a/dhall/tests/common/mod.rs +++ b/dhall/tests/common/mod.rs @@ -44,20 +44,20 @@ pub enum Feature { TypeInferenceFailure, } -pub fn read_dhall_file<'i>(file_path: &str) -> Result, ImportError> { +fn read_dhall_file<'i>(file_path: &str) -> Result, ImportError> { load_dhall_file(&PathBuf::from(file_path), true) } -pub fn read_dhall_file_no_resolve_imports<'i>( +fn load_from_file_str<'i>( file_path: &str, -) -> Result { - load_dhall_file_no_resolve_imports(&PathBuf::from(file_path)) +) -> Result { + Parsed::load_from_file(&PathBuf::from(file_path)) } -pub fn load_from_file_str<'i>( +fn load_from_binary_file_str<'i>( file_path: &str, ) -> Result { - load_from_file(&PathBuf::from(file_path)) + Parsed::load_from_binary_file(&PathBuf::from(file_path)) } pub fn run_test(base_path: &str, feature: Feature) { @@ -77,21 +77,18 @@ pub fn run_test(base_path: &str, feature: Feature) { ParserSuccess => { let expr_file_path = base_path.clone() + "A.dhall"; let expected_file_path = base_path + "B.dhallb"; - let expr = read_dhall_file_no_resolve_imports(&expr_file_path) + let expr = load_from_file_str(&expr_file_path) .map_err(|e| println!("{}", e)) .unwrap(); - use std::fs::File; - use std::io::Read; - let mut file = File::open(expected_file_path).unwrap(); - let mut data = Vec::new(); - file.read_to_end(&mut data).unwrap(); - let expected = dhall::binary::decode(&data).unwrap(); + let expected = load_from_binary_file_str(&expected_file_path) + .map_err(|e| println!("{}", e)) + .unwrap(); assert_eq_pretty!(expr, expected); // Round-trip pretty-printer - let expr = parse_expr(&expr.to_string()).unwrap(); + let expr = Parsed::load_from_str(&expr.to_string()).unwrap(); assert_eq!(expr, expected); } ParserFailure => { -- cgit v1.2.3 From 619290e208f59bb15fc4f9d4b6dae2c19bb7b711 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 7 Apr 2019 01:41:08 +0200 Subject: Augment stack size for typecheck tests --- dhall/tests/common/mod.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'dhall/tests/common/mod.rs') diff --git a/dhall/tests/common/mod.rs b/dhall/tests/common/mod.rs index 861df63..3c2fc3c 100644 --- a/dhall/tests/common/mod.rs +++ b/dhall/tests/common/mod.rs @@ -113,11 +113,21 @@ pub fn run_test(base_path: &str, feature: Feature) { typecheck::type_of(expr).unwrap_err(); } TypecheckSuccess => { - let expr_file_path = base_path.clone() + "A.dhall"; - let expected_file_path = base_path + "B.dhall"; - let expr = rc(read_dhall_file(&expr_file_path).unwrap()); - let expected = rc(read_dhall_file(&expected_file_path).unwrap()); - typecheck::type_of(rc(ExprF::Annot(expr, expected))).unwrap(); + // Many tests stack overflow in debug mode + std::thread::Builder::new() + .stack_size(4 * 1024 * 1024) + .spawn(|| { + let expr_file_path = base_path.clone() + "A.dhall"; + let expected_file_path = base_path + "B.dhall"; + let expr = rc(read_dhall_file(&expr_file_path).unwrap()); + let expected = + rc(read_dhall_file(&expected_file_path).unwrap()); + typecheck::type_of(rc(ExprF::Annot(expr, expected))) + .unwrap(); + }) + .unwrap() + .join() + .unwrap(); } TypeInferenceFailure => { let file_path = base_path + ".dhall"; -- cgit v1.2.3 From c461548c32f8cb3ee2db5ade88ae4f91b3838ab5 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 7 Apr 2019 11:09:57 +0200 Subject: Avoid constructing exprs manually when possible --- dhall/tests/common/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dhall/tests/common/mod.rs') diff --git a/dhall/tests/common/mod.rs b/dhall/tests/common/mod.rs index 3c2fc3c..fc5aa5b 100644 --- a/dhall/tests/common/mod.rs +++ b/dhall/tests/common/mod.rs @@ -122,7 +122,7 @@ pub fn run_test(base_path: &str, feature: Feature) { let expr = rc(read_dhall_file(&expr_file_path).unwrap()); let expected = rc(read_dhall_file(&expected_file_path).unwrap()); - typecheck::type_of(rc(ExprF::Annot(expr, expected))) + typecheck::type_of(dhall::subexpr!(expr: expected)) .unwrap(); }) .unwrap() -- cgit v1.2.3 From 4bebcd96b6e76b9b8ae7877af91d2ae571e617a9 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sun, 7 Apr 2019 16:45:30 +0200 Subject: Restrict public API Closes #20 --- dhall/tests/common/mod.rs | 63 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 16 deletions(-) (limited to 'dhall/tests/common/mod.rs') diff --git a/dhall/tests/common/mod.rs b/dhall/tests/common/mod.rs index fc5aa5b..5f16d2c 100644 --- a/dhall/tests/common/mod.rs +++ b/dhall/tests/common/mod.rs @@ -44,20 +44,21 @@ pub enum Feature { TypeInferenceFailure, } +// Deprecated fn read_dhall_file<'i>(file_path: &str) -> Result, ImportError> { - load_dhall_file(&PathBuf::from(file_path), true) + dhall::load_dhall_file(&PathBuf::from(file_path), true) } fn load_from_file_str<'i>( file_path: &str, -) -> Result { - Parsed::load_from_file(&PathBuf::from(file_path)) +) -> Result { + dhall::expr::Parsed::load_from_file(&PathBuf::from(file_path)) } fn load_from_binary_file_str<'i>( file_path: &str, -) -> Result { - Parsed::load_from_binary_file(&PathBuf::from(file_path)) +) -> Result { + dhall::expr::Parsed::load_from_binary_file(&PathBuf::from(file_path)) } pub fn run_test(base_path: &str, feature: Feature) { @@ -88,7 +89,8 @@ pub fn run_test(base_path: &str, feature: Feature) { assert_eq_pretty!(expr, expected); // Round-trip pretty-printer - let expr = Parsed::load_from_str(&expr.to_string()).unwrap(); + let expr = + dhall::expr::Parsed::load_from_str(&expr.to_string()).unwrap(); assert_eq!(expr, expected); } ParserFailure => { @@ -102,15 +104,29 @@ pub fn run_test(base_path: &str, feature: Feature) { Normalization => { let expr_file_path = base_path.clone() + "A.dhall"; let expected_file_path = base_path + "B.dhall"; - let expr = rc(read_dhall_file(&expr_file_path).unwrap()); - let expected = rc(read_dhall_file(&expected_file_path).unwrap()); + let expr = load_from_file_str(&expr_file_path) + .unwrap() + .resolve() + .unwrap() + .skip_typecheck() + .normalize(); + let expected = load_from_file_str(&expected_file_path) + .unwrap() + .resolve() + .unwrap() + .skip_typecheck() + .normalize(); - assert_eq_display!(normalize(expr), normalize(expected)); + assert_eq_display!(expr, expected); } TypecheckFailure => { let file_path = base_path + ".dhall"; - let expr = rc(read_dhall_file(&file_path).unwrap()); - typecheck::type_of(expr).unwrap_err(); + load_from_file_str(&file_path) + .unwrap() + .skip_resolve() + .unwrap() + .typecheck() + .unwrap_err(); } TypecheckSuccess => { // Many tests stack overflow in debug mode @@ -131,15 +147,30 @@ pub fn run_test(base_path: &str, feature: Feature) { } TypeInferenceFailure => { let file_path = base_path + ".dhall"; - let expr = rc(read_dhall_file(&file_path).unwrap()); - typecheck::type_of(expr).unwrap_err(); + load_from_file_str(&file_path) + .unwrap() + .skip_resolve() + .unwrap() + .typecheck() + .unwrap_err(); } TypeInferenceSuccess => { let expr_file_path = base_path.clone() + "A.dhall"; let expected_file_path = base_path + "B.dhall"; - let expr = rc(read_dhall_file(&expr_file_path).unwrap()); - let expected = rc(read_dhall_file(&expected_file_path).unwrap()); - assert_eq_display!(typecheck::type_of(expr).unwrap(), expected); + let expr = load_from_file_str(&expr_file_path) + .unwrap() + .skip_resolve() + .unwrap() + .typecheck() + .unwrap(); + let ty = expr.get_type().as_normalized().unwrap(); + let expected = load_from_file_str(&expected_file_path) + .unwrap() + .skip_resolve() + .unwrap() + .skip_typecheck() + .skip_normalize(); + assert_eq_display!(ty, &expected); } } } -- cgit v1.2.3