summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
Diffstat (limited to 'dhall')
-rw-r--r--dhall/build.rs16
-rw-r--r--dhall/src/tests.rs26
-rw-r--r--dhall/tests/errors/import/cycle.txt1
-rw-r--r--dhall/tests/errors/import/importBoundary.txt1
4 files changed, 44 insertions, 0 deletions
diff --git a/dhall/build.rs b/dhall/build.rs
index 83c154e..7733581 100644
--- a/dhall/build.rs
+++ b/dhall/build.rs
@@ -246,6 +246,22 @@ fn generate_tests() -> std::io::Result<()> {
output_type: None,
},
TestFeature {
+ module_name: "import_error",
+ directory: "import/failure/",
+ variant: "ImportError",
+ path_filter: Box::new(|path: &str| {
+ false
+ || path == "alternativeEnv"
+ || path == "alternativeEnvMissing"
+ || path == "hashMismatch"
+ || path == "missing"
+ || path == "referentiallyInsane"
+ || path == "customHeadersUsingBoundVariable"
+ }),
+ input_type: FileType::Text,
+ output_type: None,
+ },
+ TestFeature {
module_name: "beta_normalize",
directory: "normalization/success/",
variant: "Normalization",
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()?;
diff --git a/dhall/tests/errors/import/cycle.txt b/dhall/tests/errors/import/cycle.txt
new file mode 100644
index 0000000..0a20503
--- /dev/null
+++ b/dhall/tests/errors/import/cycle.txt
@@ -0,0 +1 @@
+Recursive(Import { mode: Code, location: Local(Parent, FilePath { file_path: ["data", "cycle.dhall"] }), hash: None }, Resolve(Recursive(Import { mode: Code, location: Local(Parent, FilePath { file_path: ["failure", "cycle.dhall"] }), hash: None }, Resolve(ImportCycle([Import { mode: Code, location: Local(Parent, FilePath { file_path: ["data", "cycle.dhall"] }), hash: None }, Import { mode: Code, location: Local(Parent, FilePath { file_path: ["failure", "cycle.dhall"] }), hash: None }], Import { mode: Code, location: Local(Parent, FilePath { file_path: ["data", "cycle.dhall"] }), hash: None })))))
diff --git a/dhall/tests/errors/import/importBoundary.txt b/dhall/tests/errors/import/importBoundary.txt
new file mode 100644
index 0000000..8f78e48
--- /dev/null
+++ b/dhall/tests/errors/import/importBoundary.txt
@@ -0,0 +1 @@
+Recursive(Import { mode: Code, location: Local(Parent, FilePath { file_path: ["data", "importBoundary.dhall"] }), hash: None }, Typecheck(TypeError { message: Custom("error: unbound variable `x`\n --> <current file>:1:0\n |\n...\n3 | x\n | ^ not found in this scope\n |") }))