summaryrefslogtreecommitdiff
path: root/dhall/tests
diff options
context:
space:
mode:
authorNadrieril2020-11-01 18:50:09 +0000
committerGitHub2020-11-01 18:50:09 +0000
commit2ae979a22ee4b79590f74110d61164383c7b5182 (patch)
tree5286606d6d59f5d5d4b9ecb7f651c97d201a092e /dhall/tests
parent48037367933085ca9c1c67c8c59f311e2b21be6d (diff)
parente5381c9b76f1d88dedb4a453cd026c8e98be5533 (diff)
Merge pull request #192 from Nadrieril/rework-caching
Diffstat (limited to '')
-rw-r--r--dhall/tests/import/data/simple.dhall1
-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.rs82
4 files changed, 60 insertions, 34 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/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..36cbd81 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};
@@ -593,26 +595,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 +652,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 +672,6 @@ fn run_test(test: &SpecTest) -> Result<()> {
expected.compare(expr)?;
}
}
-
Ok(())
}
@@ -700,17 +681,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();
}