summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2024-05-04 15:45:37 +0200
committerGitHub <noreply@github.com>2024-05-04 09:45:37 -0400
commit711353b4dd3c3c1c740c586d6a0ddab9d68c8b07 (patch)
treed22749acc2920f4f5171aa361d0d583585a9ce9a
parent3b953daac79e050ffd72c41d208e81e853f9206c (diff)
tests: prevent parallel env var access (#1681)
`env::set_var` is not-yet-unsafe, and here tests fail because a var is already set by a second test while the first one is still running. `cargo test -- test_env` with sufficient (auto detected) parallelism triggers this.
-rw-r--r--src/env.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/env.rs b/src/env.rs
index 978c4881..8c169bcc 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -62,10 +62,17 @@ impl DeltaEnv {
#[cfg(test)]
pub mod tests {
use super::DeltaEnv;
+ use lazy_static::lazy_static;
use std::env;
+ use std::sync::{Arc, Mutex};
+
+ lazy_static! {
+ static ref ENV_ACCESS: Arc<Mutex<()>> = Arc::new(Mutex::new(()));
+ }
#[test]
fn test_env_parsing() {
+ let _guard = ENV_ACCESS.lock().unwrap();
let feature = "Awesome Feature";
env::set_var("DELTA_FEATURES", feature);
let env = DeltaEnv::init();
@@ -74,6 +81,7 @@ pub mod tests {
#[test]
fn test_env_parsing_with_pager_set_to_bat() {
+ let _guard = ENV_ACCESS.lock().unwrap();
env::set_var("PAGER", "bat");
let env = DeltaEnv::init();
assert_eq!(
@@ -86,6 +94,7 @@ pub mod tests {
#[test]
fn test_env_parsing_with_pager_set_to_more() {
+ let _guard = ENV_ACCESS.lock().unwrap();
env::set_var("PAGER", "more");
let env = DeltaEnv::init();
assert_eq!(env.pagers.1, Some("less".into()));
@@ -93,6 +102,7 @@ pub mod tests {
#[test]
fn test_env_parsing_with_pager_set_to_most() {
+ let _guard = ENV_ACCESS.lock().unwrap();
env::set_var("PAGER", "most");
let env = DeltaEnv::init();
assert_eq!(env.pagers.1, Some("less".into()));