summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2020-11-01 18:00:07 +0000
committerNadrieril2020-11-01 18:00:07 +0000
commit9b67852327aff5263a3c119c068170b2edef69f8 (patch)
treeb5398eeddd6e7633ecaa99d7df6e979ac3fba4ae /dhall
parenta4332cfbd99a5a00563090a080e9bcb0cde9e963 (diff)
Don't pollute the dhall cache directory
Diffstat (limited to 'dhall')
-rw-r--r--dhall/Cargo.toml4
-rw-r--r--dhall/tests/spec.rs80
2 files changed, 48 insertions, 36 deletions
diff --git a/dhall/Cargo.toml b/dhall/Cargo.toml
index 7923009..207539a 100644
--- a/dhall/Cargo.toml
+++ b/dhall/Cargo.toml
@@ -41,15 +41,13 @@ reqwest = { version = "0.10", features = ["blocking"], optional = true }
[dev-dependencies]
anyhow = "1.0.28"
colored-diff = "0.2.2"
+fs_extra = "1.2.0"
libtest-mimic = "0.3.0"
rand = "0.7"
version-sync = "0.9"
walkdir = "2"
[build-dependencies]
-walkdir = "2"
abnf_to_pest = { version = "^0.5.0", path = "../abnf_to_pest" }
pest_generator = "2.1.3"
quote = "1.0"
-
-
diff --git a/dhall/tests/spec.rs b/dhall/tests/spec.rs
index ae53f4a..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,
@@ -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();
}