summaryrefslogtreecommitdiff
path: root/dhall/tests
diff options
context:
space:
mode:
authorBasile Henry2020-11-03 23:32:51 +0100
committerBasile Henry2020-11-03 23:32:51 +0100
commita56cd6021705ebfd310bc902c4f549bea9b06a5b (patch)
tree8cd7429e654d31b9fbc68a97d71db92e7571c08a /dhall/tests
parent559f64fd866fc74e930ddf8984fa11199a57ca2c (diff)
parentf87ffe7a590c9e0a3e0a57854c739a0f89c3784d (diff)
Merge remote-tracking branch 'upstream/master' into text-replace
Diffstat (limited to '')
-rw-r--r--dhall/tests/import/data/simple.dhall1
-rw-r--r--dhall/tests/import/failure/alternativeEnv.txt7
-rw-r--r--dhall/tests/import/failure/alternativeEnvMissing.txt7
-rw-r--r--dhall/tests/import/failure/cycle.txt17
-rw-r--r--dhall/tests/import/failure/importBoundary.txt7
-rw-r--r--dhall/tests/import/failure/missing.txt7
-rw-r--r--dhall/tests/import/failure/referentiallyInsane.txt13
-rw-r--r--dhall/tests/import/failure/unit/EnvUnset.txt7
-rw-r--r--dhall/tests/import/failure/unit/EnvUnsetAsText.txt7
-rw-r--r--dhall/tests/import/failure/unit/FileMissing.dhall1
-rw-r--r--dhall/tests/import/failure/unit/FileMissing.txt6
-rw-r--r--dhall/tests/import/failure/unit/HashMismatch2.dhall2
-rw-r--r--dhall/tests/import/failure/unit/HashMismatch2.txt9
-rw-r--r--dhall/tests/spec.rs93
-rw-r--r--dhall/tests/type-inference/failure/unit/WithInfersKind.dhall1
-rw-r--r--dhall/tests/type-inference/failure/unit/WithInfersKind.txt6
-rw-r--r--dhall/tests/type-inference/failure/unit/WithInvalidOverrideA.txt4
-rw-r--r--dhall/tests/type-inference/failure/unit/WithNotRecord.txt4
-rw-r--r--dhall/tests/type-inference/success/unit/WithInfersKindA.dhall1
-rw-r--r--dhall/tests/type-inference/success/unit/WithInfersKindB.dhall1
20 files changed, 145 insertions, 56 deletions
diff --git a/dhall/tests/import/data/simple.dhall b/dhall/tests/import/data/simple.dhall
new file mode 100644
index 0000000..00750ed
--- /dev/null
+++ b/dhall/tests/import/data/simple.dhall
@@ -0,0 +1 @@
+3
diff --git a/dhall/tests/import/failure/alternativeEnv.txt b/dhall/tests/import/failure/alternativeEnv.txt
index 482b68c..bb862c3 100644
--- a/dhall/tests/import/failure/alternativeEnv.txt
+++ b/dhall/tests/import/failure/alternativeEnv.txt
@@ -1 +1,6 @@
-MissingEnvVar
+Type error: error: error
+ --> <current file>:1:45
+ |
+1 | env:UNSET1 as Text ? env:UNSET2 ? missing ? env:UNSET3
+ | ^^^^^^^^^^ MissingEnvVar
+ |
diff --git a/dhall/tests/import/failure/alternativeEnvMissing.txt b/dhall/tests/import/failure/alternativeEnvMissing.txt
index 4666330..1f26462 100644
--- a/dhall/tests/import/failure/alternativeEnvMissing.txt
+++ b/dhall/tests/import/failure/alternativeEnvMissing.txt
@@ -1 +1,6 @@
-Missing
+Type error: error: error
+ --> <current file>:1:13
+ |
+1 | env:UNSET ? missing
+ | ^^^^^^^ Missing
+ |
diff --git a/dhall/tests/import/failure/cycle.txt b/dhall/tests/import/failure/cycle.txt
index f5a1abf..899484b 100644
--- a/dhall/tests/import/failure/cycle.txt
+++ b/dhall/tests/import/failure/cycle.txt
@@ -1 +1,16 @@
-ImportCycle([Local("./dhall-lang/tests/import/data/cycle.dhall"), Local("./dhall-lang/tests/import/failure/cycle.dhall")], Local("./dhall-lang/tests/import/data/cycle.dhall"))
+Type error: error: error
+ --> <current file>:1:1
+ |
+1 | ../data/cycle.dhall
+ | ^^^^^^^^^^^^^^^^^^^ Type error: error: error
+ --> <current file>:1:1
+ |
+1 | ../failure/cycle.dhall
+ | ^^^^^^^^^^^^^^^^^^^^^^ Type error: error: error
+ --> <current file>:1:1
+ |
+1 | ../data/cycle.dhall
+ | ^^^^^^^^^^^^^^^^^^^ ImportCycle([Local("./dhall-lang/tests/import/data/cycle.dhall"), Local("./dhall-lang/tests/import/failure/cycle.dhall")], Local("./dhall-lang/tests/import/data/cycle.dhall"))
+ |
+ |
+ |
diff --git a/dhall/tests/import/failure/importBoundary.txt b/dhall/tests/import/failure/importBoundary.txt
index 56810e2..6ddb326 100644
--- a/dhall/tests/import/failure/importBoundary.txt
+++ b/dhall/tests/import/failure/importBoundary.txt
@@ -1,7 +1,12 @@
-Type error: error: unbound variable `x`
+Type error: error: error
+ --> <current file>:1:15
+ |
+1 | \(x: Bool) -> ../data/importBoundary.dhall
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Type error: error: unbound variable `x`
--> <current file>:1:1
|
...
3 | x
| ^ not found in this scope
|
+ |
diff --git a/dhall/tests/import/failure/missing.txt b/dhall/tests/import/failure/missing.txt
index 4666330..a15e9e0 100644
--- a/dhall/tests/import/failure/missing.txt
+++ b/dhall/tests/import/failure/missing.txt
@@ -1 +1,6 @@
-Missing
+Type error: error: error
+ --> <current file>:1:1
+ |
+1 | missing
+ | ^^^^^^^ Missing
+ |
diff --git a/dhall/tests/import/failure/referentiallyInsane.txt b/dhall/tests/import/failure/referentiallyInsane.txt
index 9b5fe91..1c6852a 100644
--- a/dhall/tests/import/failure/referentiallyInsane.txt
+++ b/dhall/tests/import/failure/referentiallyInsane.txt
@@ -1 +1,12 @@
-SanityCheck
+Type error: error: error
+ --> <current file>:6:1
+ |
+ 1 | {- The following remote import attempts to import an environment variable, which
+ 2 | must be disallowed by the referential sanity check
+ 3 |
+ 4 | One reason for doing this is to protect against remote imports exfiltrating
+...
+12 | -}
+13 | https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/tests/import/data/referentiallyOpaque.dhall
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SanityCheck
+ |
diff --git a/dhall/tests/import/failure/unit/EnvUnset.txt b/dhall/tests/import/failure/unit/EnvUnset.txt
index 482b68c..12a8953 100644
--- a/dhall/tests/import/failure/unit/EnvUnset.txt
+++ b/dhall/tests/import/failure/unit/EnvUnset.txt
@@ -1 +1,6 @@
-MissingEnvVar
+Type error: error: error
+ --> <current file>:1:1
+ |
+1 | env:DHALL_TEST_UNSET
+ | ^^^^^^^^^^^^^^^^^^^^ MissingEnvVar
+ |
diff --git a/dhall/tests/import/failure/unit/EnvUnsetAsText.txt b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt
index 482b68c..6571560 100644
--- a/dhall/tests/import/failure/unit/EnvUnsetAsText.txt
+++ b/dhall/tests/import/failure/unit/EnvUnsetAsText.txt
@@ -1 +1,6 @@
-MissingEnvVar
+Type error: error: error
+ --> <current file>:1:1
+ |
+1 | env:DHALL_TEST_UNSET as Text
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ MissingEnvVar
+ |
diff --git a/dhall/tests/import/failure/unit/FileMissing.dhall b/dhall/tests/import/failure/unit/FileMissing.dhall
new file mode 100644
index 0000000..cba1bcc
--- /dev/null
+++ b/dhall/tests/import/failure/unit/FileMissing.dhall
@@ -0,0 +1 @@
+./not-a-file.dhall
diff --git a/dhall/tests/import/failure/unit/FileMissing.txt b/dhall/tests/import/failure/unit/FileMissing.txt
new file mode 100644
index 0000000..351909d
--- /dev/null
+++ b/dhall/tests/import/failure/unit/FileMissing.txt
@@ -0,0 +1,6 @@
+Type error: error: error
+ --> <current file>:1:1
+ |
+1 | ./not-a-file.dhall
+ | ^^^^^^^^^^^^^^^^^^ No such file or directory (os error 2)
+ |
diff --git a/dhall/tests/import/failure/unit/HashMismatch2.dhall b/dhall/tests/import/failure/unit/HashMismatch2.dhall
new file mode 100644
index 0000000..5fae772
--- /dev/null
+++ b/dhall/tests/import/failure/unit/HashMismatch2.dhall
@@ -0,0 +1,2 @@
+-- This ensures that even if the file gets imported without hash first, the hash check is not skipped later
+../../data/simple.dhall + ../../data/simple.dhall sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + ../../data/simple.dhall
diff --git a/dhall/tests/import/failure/unit/HashMismatch2.txt b/dhall/tests/import/failure/unit/HashMismatch2.txt
new file mode 100644
index 0000000..f03ab24
--- /dev/null
+++ b/dhall/tests/import/failure/unit/HashMismatch2.txt
@@ -0,0 +1,9 @@
+Type error: error: hash mismatch
+ --> <current file>:2:27
+ |
+1 | -- This ensures that even if the file gets imported without hash first, the hash check is not skipped later
+2 | ../../data/simple.dhall + ../../data/simple.dhall sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + ../../data/simple.dhall
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ hash mismatch
+ |
+ = note: Expected sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ = note: Found sha256:15f52ecf91c94c1baac02d5a4964b2ed8fa401641a2c8a95e8306ec7c1e3b8d2
diff --git a/dhall/tests/spec.rs b/dhall/tests/spec.rs
index 8d67892..357181a 100644
--- a/dhall/tests/spec.rs
+++ b/dhall/tests/spec.rs
@@ -1,4 +1,6 @@
use anyhow::Result;
+use rand::distributions::Alphanumeric;
+use rand::Rng;
use std::env;
use std::ffi::OsString;
use std::fmt::{Debug, Display};
@@ -519,10 +521,6 @@ fn define_features() -> Vec<TestFeature> {
|| path == "simple/integerToDouble"
// TODO: fix Double/show
|| path == "prelude/JSON/number/1"
- // With builtin not implemented yet
- || path == "unit/WithCreateIntermediateRecords"
- || path == "unit/WithDesugar"
- || path == "unit/WithPartiallyAbstract"
}),
..default_feature.clone()
},
@@ -542,12 +540,7 @@ fn define_features() -> Vec<TestFeature> {
variant: SpecTestKind::TypeInferenceSuccess,
// TODO: this fails because of caching shenanigans
// too_slow_path: Rc::new(|path: &str| path == "prelude"),
- exclude_path: Rc::new(|path: &str| {
- false
- || path == "prelude"
- // With builtin not implemented yet
- || path == "unit/WithCreateIntermediateRecords"
- }),
+ exclude_path: Rc::new(|path: &str| path == "prelude"),
..default_feature.clone()
},
TestFeature {
@@ -593,26 +586,6 @@ fn unwrap_err<T: Debug, E>(x: Result<T, E>) -> Result<E, TestError> {
fn run_test(test: &SpecTest) -> Result<()> {
use self::SpecTestKind::*;
- // Setup current directory to the root of the repository. Important for `as Location` tests.
- let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
- .parent()
- .unwrap()
- .to_path_buf();
- env::set_current_dir(root_dir.as_path())?;
- // Set environment variable for import tests.
- env::set_var("DHALL_TEST_VAR", "6 * 7");
-
- // Configure cache for import tests
- env::set_var(
- "XDG_CACHE_HOME",
- root_dir
- .join("dhall-lang")
- .join("tests")
- .join("import")
- .join("cache")
- .as_path(),
- );
-
let SpecTest {
input: expr,
output: expected,
@@ -670,7 +643,7 @@ fn run_test(test: &SpecTest) -> Result<()> {
}
SemanticHash => {
let expr = expr.normalize()?.to_expr_alpha();
- let hash = hex::encode(expr.hash()?);
+ let hash = hex::encode(expr.sha256_hash()?);
expected.compare_ui(format!("sha256:{}", hash))?;
}
TypeInferenceSuccess => {
@@ -690,7 +663,6 @@ fn run_test(test: &SpecTest) -> Result<()> {
expected.compare(expr)?;
}
}
-
Ok(())
}
@@ -700,17 +672,50 @@ fn main() {
.flat_map(discover_tests_for_feature)
.collect();
- libtest_mimic::run_tests(&Arguments::from_args(), tests, |test| {
- let result = std::panic::catch_unwind(move || {
- run_test_stringy_error(&test.data)
+ // Setup current directory to the root of the repository. Important for `as Location` tests.
+ let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
+ .parent()
+ .unwrap()
+ .to_path_buf();
+ env::set_current_dir(root_dir.as_path()).unwrap();
+
+ // Set environment variable for import tests.
+ env::set_var("DHALL_TEST_VAR", "6 * 7");
+
+ // Configure cache for import tests
+ let dhall_cache_dir = root_dir
+ .join("dhall-lang")
+ .join("tests")
+ .join("import")
+ .join("cache")
+ .join("dhall");
+ let random_id = rand::thread_rng()
+ .sample_iter(Alphanumeric)
+ .take(36)
+ .collect::<String>();
+ let cache_dir = format!("dhall-tests-{}", random_id);
+ let cache_dir = env::temp_dir().join(cache_dir);
+
+ std::fs::create_dir_all(&cache_dir).unwrap();
+ fs_extra::dir::copy(&dhall_cache_dir, &cache_dir, &Default::default())
+ .unwrap();
+ env::set_var("XDG_CACHE_HOME", &cache_dir);
+
+ let res =
+ libtest_mimic::run_tests(&Arguments::from_args(), tests, |test| {
+ let result = std::panic::catch_unwind(move || {
+ run_test_stringy_error(&test.data)
+ });
+ match result {
+ Ok(Ok(_)) => Outcome::Passed,
+ Ok(Err(e)) => Outcome::Failed { msg: Some(e) },
+ Err(_) => Outcome::Failed {
+ msg: Some("thread panicked".to_string()),
+ },
+ }
});
- match result {
- Ok(Ok(_)) => Outcome::Passed,
- Ok(Err(e)) => Outcome::Failed { msg: Some(e) },
- Err(_) => Outcome::Failed {
- msg: Some("thread panicked".to_string()),
- },
- }
- })
- .exit();
+
+ std::fs::remove_dir_all(&cache_dir).unwrap();
+
+ res.exit();
}
diff --git a/dhall/tests/type-inference/failure/unit/WithInfersKind.dhall b/dhall/tests/type-inference/failure/unit/WithInfersKind.dhall
new file mode 100644
index 0000000..aeed835
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/WithInfersKind.dhall
@@ -0,0 +1 @@
+Some ({=} with x = Bool)
diff --git a/dhall/tests/type-inference/failure/unit/WithInfersKind.txt b/dhall/tests/type-inference/failure/unit/WithInfersKind.txt
new file mode 100644
index 0000000..1c60eb6
--- /dev/null
+++ b/dhall/tests/type-inference/failure/unit/WithInfersKind.txt
@@ -0,0 +1,6 @@
+Type error: error: InvalidOptionalType
+ --> <current file>:1:1
+ |
+1 | Some ({=} with x = Bool)
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ InvalidOptionalType
+ |
diff --git a/dhall/tests/type-inference/failure/unit/WithInvalidOverrideA.txt b/dhall/tests/type-inference/failure/unit/WithInvalidOverrideA.txt
index c34175f..c2af394 100644
--- a/dhall/tests/type-inference/failure/unit/WithInvalidOverrideA.txt
+++ b/dhall/tests/type-inference/failure/unit/WithInvalidOverrideA.txt
@@ -1,7 +1,7 @@
-Type error: error: MustCombineRecord
+Type error: error: WithMustBeRecord
--> <current file>:1:1
|
...
6 | { a = 1 } with a.b = 2
- | ^^^^^^^^^^^^^^^^^^^^^^ MustCombineRecord
+ | ^^^^^^^^^^^^^^^^^^^^^^ WithMustBeRecord
|
diff --git a/dhall/tests/type-inference/failure/unit/WithNotRecord.txt b/dhall/tests/type-inference/failure/unit/WithNotRecord.txt
index 8574e48..cd76485 100644
--- a/dhall/tests/type-inference/failure/unit/WithNotRecord.txt
+++ b/dhall/tests/type-inference/failure/unit/WithNotRecord.txt
@@ -1,6 +1,6 @@
-Type error: error: MustCombineRecord
+Type error: error: WithMustBeRecord
--> <current file>:1:1
|
1 | 5 with a = 10
- | ^^^^^^^^^^^^^ MustCombineRecord
+ | ^^^^^^^^^^^^^ WithMustBeRecord
|
diff --git a/dhall/tests/type-inference/success/unit/WithInfersKindA.dhall b/dhall/tests/type-inference/success/unit/WithInfersKindA.dhall
new file mode 100644
index 0000000..4662447
--- /dev/null
+++ b/dhall/tests/type-inference/success/unit/WithInfersKindA.dhall
@@ -0,0 +1 @@
+Some ({ x = Bool } with x = 0)
diff --git a/dhall/tests/type-inference/success/unit/WithInfersKindB.dhall b/dhall/tests/type-inference/success/unit/WithInfersKindB.dhall
new file mode 100644
index 0000000..009f331
--- /dev/null
+++ b/dhall/tests/type-inference/success/unit/WithInfersKindB.dhall
@@ -0,0 +1 @@
+Optional { x : Natural }