From 58f10a2a274fe858da6cc73d4a33718bfc46d52b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 10 Apr 2019 19:17:34 +0200 Subject: s/load_from/parse/ --- dhall/src/tests.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'dhall/src/tests.rs') diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index ebb8855..737a8a4 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -51,16 +51,16 @@ fn read_dhall_file<'i>(file_path: &str) -> Result, ImportError> { crate::imports::load_dhall_file(&PathBuf::from(file_path), true) } -fn load_from_file_str<'i>( +fn parse_file_str<'i>( file_path: &str, ) -> Result { - crate::expr::Parsed::load_from_file(&PathBuf::from(file_path)) + crate::expr::Parsed::parse_file(&PathBuf::from(file_path)) } -fn load_from_binary_file_str<'i>( +fn parse_binary_file_str<'i>( file_path: &str, ) -> Result { - crate::expr::Parsed::load_from_binary_file(&PathBuf::from(file_path)) + crate::expr::Parsed::parse_binary_file(&PathBuf::from(file_path)) } pub fn run_test(base_path: &str, feature: Feature) { @@ -80,24 +80,24 @@ 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 = load_from_file_str(&expr_file_path) + let expr = parse_file_str(&expr_file_path) .map_err(|e| println!("{}", e)) .unwrap(); - let expected = load_from_binary_file_str(&expected_file_path) + let expected = parse_binary_file_str(&expected_file_path) .map_err(|e| println!("{}", e)) .unwrap(); assert_eq_pretty!(expr, expected); // Round-trip pretty-printer - let expr = - crate::expr::Parsed::load_from_str(&expr.to_string()).unwrap(); + let expr: crate::expr::Parsed = + crate::from_str(&expr.to_string(), None).unwrap(); assert_eq!(expr, expected); } ParserFailure => { let file_path = base_path + ".dhall"; - let err = load_from_file_str(&file_path).unwrap_err(); + let err = parse_file_str(&file_path).unwrap_err(); match err { ImportError::ParseError(_) => {} e => panic!("Expected parse error, got: {:?}", e), @@ -106,13 +106,13 @@ 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 = load_from_file_str(&expr_file_path) + let expr = parse_file_str(&expr_file_path) .unwrap() .resolve() .unwrap() .skip_typecheck() .normalize(); - let expected = load_from_file_str(&expected_file_path) + let expected = parse_file_str(&expected_file_path) .unwrap() .resolve() .unwrap() @@ -123,7 +123,7 @@ pub fn run_test(base_path: &str, feature: Feature) { } TypecheckFailure => { let file_path = base_path + ".dhall"; - load_from_file_str(&file_path) + parse_file_str(&file_path) .unwrap() .skip_resolve() .unwrap() @@ -149,7 +149,7 @@ pub fn run_test(base_path: &str, feature: Feature) { } TypeInferenceFailure => { let file_path = base_path + ".dhall"; - load_from_file_str(&file_path) + parse_file_str(&file_path) .unwrap() .skip_resolve() .unwrap() @@ -159,14 +159,14 @@ pub fn run_test(base_path: &str, feature: Feature) { TypeInferenceSuccess => { let expr_file_path = base_path.clone() + "A.dhall"; let expected_file_path = base_path + "B.dhall"; - let expr = load_from_file_str(&expr_file_path) + let expr = parse_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) + let expected = parse_file_str(&expected_file_path) .unwrap() .skip_resolve() .unwrap() -- cgit v1.2.3 From c7184b841279a55bdfb39bde429896d221aa666c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 10 Apr 2019 21:46:25 +0200 Subject: Cleanup error handling Closes #41 --- dhall/src/tests.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'dhall/src/tests.rs') diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 737a8a4..9e78c2f 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -29,7 +29,8 @@ macro_rules! make_spec_test { }; } -use crate::imports::ImportError; +use crate::error::{Error, Result}; +use crate::expr::Parsed; use crate::*; use dhall_core::*; use dhall_generator as dhall; @@ -47,20 +48,16 @@ pub enum Feature { } // Deprecated -fn read_dhall_file<'i>(file_path: &str) -> Result, ImportError> { +fn read_dhall_file<'i>(file_path: &str) -> Result> { crate::imports::load_dhall_file(&PathBuf::from(file_path), true) } -fn parse_file_str<'i>( - file_path: &str, -) -> Result { - crate::expr::Parsed::parse_file(&PathBuf::from(file_path)) +fn parse_file_str<'i>(file_path: &str) -> Result { + Parsed::parse_file(&PathBuf::from(file_path)) } -fn parse_binary_file_str<'i>( - file_path: &str, -) -> Result { - crate::expr::Parsed::parse_binary_file(&PathBuf::from(file_path)) +fn parse_binary_file_str<'i>(file_path: &str) -> Result { + Parsed::parse_binary_file(&PathBuf::from(file_path)) } pub fn run_test(base_path: &str, feature: Feature) { @@ -91,7 +88,7 @@ pub fn run_test(base_path: &str, feature: Feature) { assert_eq_pretty!(expr, expected); // Round-trip pretty-printer - let expr: crate::expr::Parsed = + let expr: Parsed = crate::from_str(&expr.to_string(), None).unwrap(); assert_eq!(expr, expected); } @@ -99,7 +96,7 @@ pub fn run_test(base_path: &str, feature: Feature) { let file_path = base_path + ".dhall"; let err = parse_file_str(&file_path).unwrap_err(); match err { - ImportError::ParseError(_) => {} + Error::Parse(_) => {} e => panic!("Expected parse error, got: {:?}", e), } } -- cgit v1.2.3 From 88ac184e7e967c4a5e257c91598f647b8294d71c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 10 Apr 2019 22:17:13 +0200 Subject: Mild cleanup imports --- dhall/src/tests.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'dhall/src/tests.rs') diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 9e78c2f..dede639 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -48,8 +48,8 @@ pub enum Feature { } // Deprecated -fn read_dhall_file<'i>(file_path: &str) -> Result> { - crate::imports::load_dhall_file(&PathBuf::from(file_path), true) +fn read_dhall_file<'i>(file_path: &str) -> Result> { + crate::imports::load_dhall_file(&PathBuf::from(file_path)) } fn parse_file_str<'i>(file_path: &str) -> Result { @@ -134,9 +134,9 @@ pub fn run_test(base_path: &str, feature: Feature) { .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 expr = read_dhall_file(&expr_file_path).unwrap(); let expected = - rc(read_dhall_file(&expected_file_path).unwrap()); + read_dhall_file(&expected_file_path).unwrap(); typecheck::type_of(dhall::subexpr!(expr: expected)) .unwrap(); }) -- cgit v1.2.3 From 7740ec004c6d7e073358bf2be00b6c0006e4dd06 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 10 Apr 2019 22:32:07 +0200 Subject: Allow providing type for typechecking in API --- dhall/src/tests.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'dhall/src/tests.rs') diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index dede639..6b1c426 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -31,9 +31,6 @@ macro_rules! make_spec_test { use crate::error::{Error, Result}; use crate::expr::Parsed; -use crate::*; -use dhall_core::*; -use dhall_generator as dhall; use std::path::PathBuf; #[allow(dead_code)] @@ -47,11 +44,6 @@ pub enum Feature { TypeInferenceFailure, } -// Deprecated -fn read_dhall_file<'i>(file_path: &str) -> Result> { - crate::imports::load_dhall_file(&PathBuf::from(file_path)) -} - fn parse_file_str<'i>(file_path: &str) -> Result { Parsed::parse_file(&PathBuf::from(file_path)) } @@ -134,11 +126,18 @@ pub fn run_test(base_path: &str, feature: Feature) { .spawn(|| { let expr_file_path = base_path.clone() + "A.dhall"; let expected_file_path = base_path + "B.dhall"; - let expr = read_dhall_file(&expr_file_path).unwrap(); - let expected = - read_dhall_file(&expected_file_path).unwrap(); - typecheck::type_of(dhall::subexpr!(expr: expected)) + let expr = parse_file_str(&expr_file_path) + .unwrap() + .resolve() .unwrap(); + let expected = parse_file_str(&expected_file_path) + .unwrap() + .resolve() + .unwrap() + .skip_typecheck() + .skip_normalize() + .into_type(); + expr.typecheck_with(&expected).unwrap(); }) .unwrap() .join() -- cgit v1.2.3 From 9a060908aae564e7155259a4e12d63be3fb97d9b Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 10 Apr 2019 23:58:12 +0200 Subject: Simplify test harness --- dhall/src/tests.rs | 206 ++++++++++++++++++++++++----------------------------- 1 file changed, 92 insertions(+), 114 deletions(-) (limited to 'dhall/src/tests.rs') diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index 6b1c426..23ec1f4 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -19,12 +19,22 @@ right: `{}`"#, #[macro_export] macro_rules! make_spec_test { - ($type:ident, $name:ident, $path:expr) => { + ($type:ident, $status:ident, $name:ident, $path:expr) => { #[test] #[allow(non_snake_case)] fn $name() { use crate::tests::*; - run_test($path, Feature::$type); + // Many tests stack overflow in debug mode + std::thread::Builder::new() + .stack_size(4 * 1024 * 1024) + .spawn(|| { + run_test($path, Feature::$type, Status::$status) + .map_err(|e| println!("{}", e)) + .unwrap(); + }) + .unwrap() + .join() + .unwrap(); } }; } @@ -33,15 +43,18 @@ use crate::error::{Error, Result}; use crate::expr::Parsed; use std::path::PathBuf; -#[allow(dead_code)] +#[derive(Copy, Clone)] pub enum Feature { - ParserSuccess, - ParserFailure, + Parser, Normalization, - TypecheckSuccess, - TypecheckFailure, - TypeInferenceSuccess, - TypeInferenceFailure, + Typecheck, + TypeInference, +} + +#[derive(Copy, Clone)] +pub enum Status { + Success, + Failure, } fn parse_file_str<'i>(file_path: &str) -> Result { @@ -52,123 +65,88 @@ fn parse_binary_file_str<'i>(file_path: &str) -> Result { Parsed::parse_binary_file(&PathBuf::from(file_path)) } -pub fn run_test(base_path: &str, feature: Feature) { +pub fn run_test( + base_path: &str, + feature: Feature, + status: Status, +) -> Result<()> { use self::Feature::*; - let base_path_prefix = match feature { - ParserSuccess => "parser/success/", - ParserFailure => "parser/failure/", - Normalization => "normalization/success/", - TypecheckSuccess => "typecheck/success/", - TypecheckFailure => "typecheck/failure/", - TypeInferenceSuccess => "type-inference/success/", - TypeInferenceFailure => "type-inference/failure/", + use self::Status::*; + let feature_prefix = match feature { + Parser => "parser/", + Normalization => "normalization/", + Typecheck => "typecheck/", + TypeInference => "type-inference/", + }; + let status_prefix = match status { + Success => "success/", + Failure => "failure/", }; - let base_path = - "../dhall-lang/tests/".to_owned() + base_path_prefix + base_path; - match feature { - ParserSuccess => { + let base_path = "../dhall-lang/tests/".to_owned() + + feature_prefix + + status_prefix + + base_path; + match status { + Success => { let expr_file_path = base_path.clone() + "A.dhall"; - let expected_file_path = base_path + "B.dhallb"; - let expr = parse_file_str(&expr_file_path) - .map_err(|e| println!("{}", e)) - .unwrap(); + let expr = parse_file_str(&expr_file_path)?; - let expected = parse_binary_file_str(&expected_file_path) - .map_err(|e| println!("{}", e)) - .unwrap(); + if let Parser = feature { + let expected_file_path = base_path + "B.dhallb"; + let expected = parse_binary_file_str(&expected_file_path)?; - assert_eq_pretty!(expr, expected); + assert_eq_pretty!(expr, expected); - // Round-trip pretty-printer - let expr: Parsed = - crate::from_str(&expr.to_string(), None).unwrap(); - assert_eq!(expr, expected); - } - ParserFailure => { - let file_path = base_path + ".dhall"; - let err = parse_file_str(&file_path).unwrap_err(); - match err { - Error::Parse(_) => {} - e => panic!("Expected parse error, got: {:?}", e), + // Round-trip pretty-printer + let expr: Parsed = crate::from_str(&expr.to_string(), None)?; + assert_eq!(expr, expected); + + return Ok(()); } - } - Normalization => { - let expr_file_path = base_path.clone() + "A.dhall"; + + let expr = expr.resolve()?; + let expected_file_path = base_path + "B.dhall"; - let expr = parse_file_str(&expr_file_path) - .unwrap() - .resolve() - .unwrap() + let expected = parse_file_str(&expected_file_path)? + .resolve()? .skip_typecheck() - .normalize(); - let expected = parse_file_str(&expected_file_path) - .unwrap() - .resolve() - .unwrap() - .skip_typecheck() - .normalize(); + .skip_normalize(); - assert_eq_display!(expr, expected); - } - TypecheckFailure => { - let file_path = base_path + ".dhall"; - parse_file_str(&file_path) - .unwrap() - .skip_resolve() - .unwrap() - .typecheck() - .unwrap_err(); - } - TypecheckSuccess => { - // 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 = parse_file_str(&expr_file_path) - .unwrap() - .resolve() - .unwrap(); - let expected = parse_file_str(&expected_file_path) - .unwrap() - .resolve() - .unwrap() - .skip_typecheck() - .skip_normalize() - .into_type(); - expr.typecheck_with(&expected).unwrap(); - }) - .unwrap() - .join() - .unwrap(); + match feature { + Parser => unreachable!(), + Typecheck => { + expr.typecheck_with(&expected.into_type())?; + } + TypeInference => { + let expr = expr.typecheck()?; + let ty = expr.get_type().as_normalized()?; + assert_eq_display!(ty, &expected); + } + Normalization => { + let expr = expr.skip_typecheck().normalize(); + assert_eq_display!(expr, expected); + } + } } - TypeInferenceFailure => { + Failure => { let file_path = base_path + ".dhall"; - parse_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 = parse_file_str(&expr_file_path) - .unwrap() - .skip_resolve() - .unwrap() - .typecheck() - .unwrap(); - let ty = expr.get_type().as_normalized().unwrap(); - let expected = parse_file_str(&expected_file_path) - .unwrap() - .skip_resolve() - .unwrap() - .skip_typecheck() - .skip_normalize(); - assert_eq_display!(ty, &expected); + match feature { + Parser => { + let err = parse_file_str(&file_path).unwrap_err(); + match err { + Error::Parse(_) => {} + e => panic!("Expected parse error, got: {:?}", e), + } + } + Normalization => unreachable!(), + Typecheck | TypeInference => { + parse_file_str(&file_path)? + .skip_resolve()? + .typecheck() + .unwrap_err(); + } + } } } + Ok(()) } -- cgit v1.2.3