Skip to content

Commit 4b8c82b

Browse files
committed
refactor(main): make CLI/runtime helpers and theme path testable
1 parent ad2e09d commit 4b8c82b

2 files changed

Lines changed: 254 additions & 56 deletions

File tree

‎src/config.rs‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ fn default_ignore_patterns() -> Vec<String> {
4545
Vec::new()
4646
}
4747

48+
#[cfg(test)]
49+
pub(crate) fn test_home_env_lock() -> &'static std::sync::Mutex<()> {
50+
static LOCK: std::sync::OnceLock<std::sync::Mutex<()>> = std::sync::OnceLock::new();
51+
LOCK.get_or_init(|| std::sync::Mutex::new(()))
52+
}
53+
4854
impl Default for Config {
4955
fn default() -> Self {
5056
Self {
@@ -214,7 +220,7 @@ mod tests {
214220
use super::*;
215221
use std::env;
216222
use std::ffi::OsString;
217-
use std::sync::{Mutex, MutexGuard, OnceLock};
223+
use std::sync::MutexGuard;
218224
use std::time::{SystemTime, UNIX_EPOCH};
219225

220226
const HOME_VARS: [&str; 4] = ["HOME", "USERPROFILE", "HOMEDRIVE", "HOMEPATH"];
@@ -227,7 +233,7 @@ mod tests {
227233

228234
impl TempHome {
229235
fn new() -> Result<Self> {
230-
let lock = env_lock()
236+
let lock = test_home_env_lock()
231237
.lock()
232238
.unwrap_or_else(|poisoned| poisoned.into_inner());
233239
let path = env::temp_dir().join(format!(
@@ -269,11 +275,6 @@ mod tests {
269275
}
270276
}
271277

272-
fn env_lock() -> &'static Mutex<()> {
273-
static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
274-
LOCK.get_or_init(|| Mutex::new(()))
275-
}
276-
277278
fn sample_config() -> Config {
278279
Config {
279280
theme: "nord".to_string(),

0 commit comments

Comments
 (0)