diff options
Diffstat (limited to 'dhall/src')
-rw-r--r-- | dhall/src/tests.rs | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs index b98489f..9790b95 100644 --- a/dhall/src/tests.rs +++ b/dhall/src/tests.rs @@ -21,7 +21,7 @@ right: `{}`"#, } use std::fs::File; -use std::io::Read; +use std::io::{Read, Write}; use std::path::PathBuf; use crate::error::{Error, Result}; @@ -40,6 +40,7 @@ pub enum Test<'a> { ImportFailure(&'a str), TypeInferenceSuccess(&'a str, &'a str), TypeInferenceFailure(&'a str), + TypeError(&'a str), Normalization(&'a str, &'a str), AlphaNormalization(&'a str, &'a str), } @@ -144,13 +145,38 @@ pub fn run_test(test: Test<'_>) -> Result<()> { assert_eq_display!(ty, expected); } TypeInferenceFailure(file_path) => { - let res = parse_file_str(&file_path)?.skip_resolve()?.typecheck(); - match res { - Err(_) => {} - // If e did typecheck, check that it doesn't have a type - Ok(e) => { - e.get_type().unwrap_err(); - } + let mut res = + parse_file_str(&file_path)?.skip_resolve()?.typecheck(); + if let Ok(e) = &res { + // If e did typecheck, check that get_type fails + res = e.get_type(); + } + res.unwrap_err(); + } + TypeError(file_path) => { + let mut res = + parse_file_str(&file_path)?.skip_resolve()?.typecheck(); + let file_path = PathBuf::from(file_path); + let error_file_path = file_path + .strip_prefix("../dhall-lang/tests/type-inference/failure/") + .unwrap(); + let error_file_path = + PathBuf::from("tests/type-errors/").join(error_file_path); + let error_file_path = error_file_path.with_extension("txt"); + if let Ok(e) = &res { + // If e did typecheck, check that get_type fails + res = e.get_type(); + } + let err: Error = res.unwrap_err().into(); + + if error_file_path.is_file() { + let expected_msg = std::fs::read_to_string(error_file_path)?; + let msg = format!("{}\n", err); + assert_eq_pretty!(msg, expected_msg); + } else { + std::fs::create_dir_all(error_file_path.parent().unwrap())?; + let mut file = File::create(error_file_path)?; + writeln!(file, "{}", err)?; } } Normalization(expr_file_path, expected_file_path) => { |