summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
authorNadrieril2020-02-09 15:50:58 +0000
committerNadrieril2020-02-09 19:58:28 +0000
commitca93f39201f6f8be9bc1466eed7323d0426e135c (patch)
treeb6d61c2932a7f846ab5b4390995156c7cb08c4e1 /dhall/src
parent5abc0628058a318782c46614d943c034711845c6 (diff)
Track output of import errors
Diffstat (limited to '')
-rw-r--r--dhall/src/tests.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/dhall/src/tests.rs b/dhall/src/tests.rs
index 8136625..449e7ee 100644
--- a/dhall/src/tests.rs
+++ b/dhall/src/tests.rs
@@ -61,6 +61,7 @@ pub enum Test<'a> {
BinaryDecodingFailure(&'a str),
ImportSuccess(&'a str, &'a str),
ImportFailure(&'a str),
+ ImportError(&'a str),
TypeInferenceSuccess(&'a str, &'a str),
TypeInferenceFailure(&'a str),
TypeError(&'a str),
@@ -157,6 +158,31 @@ pub fn run_test(test: Test<'_>) -> Result<()> {
ImportFailure(file_path) => {
parse_file_str(&file_path)?.resolve().unwrap_err();
}
+ // Checks the output of the type error against a text file. If the text file doesn't exist,
+ // we instead write to it the output we got. This makes it easy to update those files: just
+ // `rm -r dhall/tests/type-errors` and run the tests again.
+ ImportError(file_path) => {
+ let err: Error =
+ parse_file_str(&file_path)?.resolve().unwrap_err().into();
+ let file_path = PathBuf::from(file_path);
+ let error_file_path = file_path
+ .strip_prefix("../dhall-lang/tests/import/failure/")
+ .or_else(|_| file_path.strip_prefix("tests/import/failure/"))
+ .unwrap();
+ let error_file_path =
+ PathBuf::from("tests/errors/import/").join(error_file_path);
+ let error_file_path = error_file_path.with_extension("txt");
+
+ 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_str!(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)?;
+ }
+ }
TypeInferenceSuccess(expr_file_path, expected_file_path) => {
let expr =
parse_file_str(&expr_file_path)?.resolve()?.typecheck()?;