1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SAFETY: every `unsafe` block in this module serializes env-var mutation through `lock()`.
//! Shared test-only helpers for tests that mutate process-global env vars
//! (`FSLITE_CONFIG_DIR`, `XDG_CONFIG_HOME`).
//!
//! `paths.rs`, `registry.rs`, and `context.rs` each have unit tests that
//! call `std::env::set_var`/`remove_var` on these vars so they can point
//! `config_dir()` at an isolated temp directory. Cargo runs every test in
//! this binary's single test binary in parallel threads by default, and
//! env vars are process-global state — so without serialization, one
//! test's `set_var`/`remove_var` races with another test's, and a test can
//! observe a config dir it never set (intermittent, order-dependent
//! failures).
//!
//! [`lock`] hands back a guard on a single process-wide mutex; callers must
//! hold it for the *entire* test body (not just around the `set_var`
//! calls), since the whole point is serializing anything that reads
//! config-dir-derived state while another test's env vars are mid-flight.
//! [`with_temp_config_dir`] is the common case: acquire the lock, point
//! `FSLITE_CONFIG_DIR` at a fresh temp directory for the duration of `f`,
//! then clean up.
use ;
/// Acquires the process-wide env-var lock, recovering from a poisoned lock
/// (a panic in another test while it held the guard) instead of cascading
/// that panic into every other env-var test.
/// Runs `f` while `FSLITE_CONFIG_DIR` is set to a fresh temp directory,
/// holding the env-var lock for the full duration so no other
/// env-var-mutating test can interleave.