summaryrefslogtreecommitdiff
path: root/dhall/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dhall/tests/common/mod.rs105
-rw-r--r--dhall/tests/normalization.rs1
-rw-r--r--dhall/tests/parser.rs1
-rw-r--r--dhall/tests/traits.rs (renamed from dhall/tests/dhall_type.rs)14
-rw-r--r--dhall/tests/typecheck.rs13
5 files changed, 90 insertions, 44 deletions
diff --git a/dhall/tests/common/mod.rs b/dhall/tests/common/mod.rs
index 397a8ee..5f16d2c 100644
--- a/dhall/tests/common/mod.rs
+++ b/dhall/tests/common/mod.rs
@@ -44,14 +44,21 @@ pub enum Feature {
TypeInferenceFailure,
}
-pub fn read_dhall_file<'i>(file_path: &str) -> Result<Expr<X, X>, DhallError> {
- load_dhall_file(&PathBuf::from(file_path), true)
+// Deprecated
+fn read_dhall_file<'i>(file_path: &str) -> Result<Expr<X, X>, ImportError> {
+ dhall::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<ParsedExpr, DhallError> {
- load_dhall_file_no_resolve_imports(&PathBuf::from(file_path))
+) -> Result<dhall::expr::Parsed, ImportError> {
+ dhall::expr::Parsed::load_from_file(&PathBuf::from(file_path))
+}
+
+fn load_from_binary_file_str<'i>(
+ file_path: &str,
+) -> Result<dhall::expr::Parsed, ImportError> {
+ dhall::expr::Parsed::load_from_binary_file(&PathBuf::from(file_path))
}
pub fn run_test(base_path: &str, feature: Feature) {
@@ -71,63 +78,99 @@ 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 =
+ dhall::expr::Parsed::load_from_str(&expr.to_string()).unwrap();
assert_eq!(expr, expected);
}
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 {
- DhallError::ParseError(_) => {}
+ ImportError::ParseError(_) => {}
e => panic!("Expected parse error, got: {:?}", e),
}
}
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 => {
- 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(dhall::subexpr!(expr: expected))
+ .unwrap();
+ })
+ .unwrap()
+ .join()
+ .unwrap();
}
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);
}
}
}
diff --git a/dhall/tests/normalization.rs b/dhall/tests/normalization.rs
index 5ecc02f..a36a6ac 100644
--- a/dhall/tests/normalization.rs
+++ b/dhall/tests/normalization.rs
@@ -1,3 +1,4 @@
+#![feature(proc_macro_hygiene)]
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
mod common;
diff --git a/dhall/tests/parser.rs b/dhall/tests/parser.rs
index 0b5e2d6..3969dc9 100644
--- a/dhall/tests/parser.rs
+++ b/dhall/tests/parser.rs
@@ -1,3 +1,4 @@
+#![feature(proc_macro_hygiene)]
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
mod common;
diff --git a/dhall/tests/dhall_type.rs b/dhall/tests/traits.rs
index 941e3a4..ac6b5e6 100644
--- a/dhall/tests/dhall_type.rs
+++ b/dhall/tests/traits.rs
@@ -1,5 +1,5 @@
#![feature(proc_macro_hygiene)]
-use dhall::Type;
+use dhall::StaticType;
use dhall_generator::dhall_expr;
#[test]
@@ -11,18 +11,18 @@ fn test_dhall_type() {
dhall_expr!({ _1: Bool, _2: Optional Text })
);
- #[derive(dhall::Type)]
+ #[derive(dhall::StaticType)]
#[allow(dead_code)]
struct A {
field1: bool,
field2: Option<bool>,
}
assert_eq!(
- <A as dhall::Type>::get_type(),
+ <A as dhall::StaticType>::get_type(),
dhall_expr!({ field1: Bool, field2: Optional Bool })
);
- #[derive(Type)]
+ #[derive(StaticType)]
#[allow(dead_code)]
struct B<'a, T: 'a> {
field1: &'a T,
@@ -30,12 +30,12 @@ fn test_dhall_type() {
}
assert_eq!(<B<'static, bool>>::get_type(), A::get_type());
- #[derive(Type)]
+ #[derive(StaticType)]
#[allow(dead_code)]
struct C<T>(T, Option<String>);
assert_eq!(<C<bool>>::get_type(), <(bool, Option<String>)>::get_type());
- #[derive(Type)]
+ #[derive(StaticType)]
#[allow(dead_code)]
struct D();
assert_eq!(
@@ -43,7 +43,7 @@ fn test_dhall_type() {
dhall_expr!({ _1: {}, _2: Optional Text })
);
- #[derive(Type)]
+ #[derive(StaticType)]
#[allow(dead_code)]
enum E<T> {
A(T),
diff --git a/dhall/tests/typecheck.rs b/dhall/tests/typecheck.rs
index 367765c..8d72313 100644
--- a/dhall/tests/typecheck.rs
+++ b/dhall/tests/typecheck.rs
@@ -1,3 +1,4 @@
+#![feature(proc_macro_hygiene)]
#![feature(custom_inner_attributes)]
#![rustfmt::skip]
mod common;
@@ -7,11 +8,11 @@ macro_rules! tc_success {
make_spec_test!(TypecheckSuccess, $name, $path);
};
}
-macro_rules! tc_failure {
- ($name:ident, $path:expr) => {
- make_spec_test!(TypecheckFailure, $name, $path);
- };
-}
+// macro_rules! tc_failure {
+// ($name:ident, $path:expr) => {
+// make_spec_test!(TypecheckFailure, $name, $path);
+// };
+// }
macro_rules! ti_success {
($name:ident, $path:expr) => {
@@ -176,7 +177,7 @@ tc_success!(spec_typecheck_success_prelude_Text_concat_1, "prelude/Text/concat/1
// tc_failure!(spec_typecheck_failure_combineMixedRecords, "combineMixedRecords");
// tc_failure!(spec_typecheck_failure_duplicateFields, "duplicateFields");
-tc_failure!(spec_typecheck_failure_hurkensParadox, "hurkensParadox");
+// tc_failure!(spec_typecheck_failure_hurkensParadox, "hurkensParadox");
// ti_success!(spec_typeinference_success_simple_alternativesAreTypes, "simple/alternativesAreTypes");
// ti_success!(spec_typeinference_success_simple_kindParameter, "simple/kindParameter");