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
56
57
58
59
60
61
62
63
64
65
66
67
//! RAII helper that scopes env-var mutations within a single test.
//!
//! On construction, snapshots the current value of each named env var
//! (or `None` if unset) and clears the variable. Tests then call
//! [`EnvGuard::set`] to seed test-specific values. On drop, every prior
//! value is restored — `Some(_)` is written back via `std::env::set_var`,
//! `None` is written back as a `remove_var`.
//!
//! ## Threading
//!
//! Env state is process-global. Tests holding this guard MUST also be
//! marked `#[serial]` (via the `serial_test` crate) so the (single-
//! threaded) `serial` group is the only writer at a time. Concurrent
//! tests outside the `serial` group will race with this guard's
//! mutations.
//!
//! ## History
//!
//! Slice 5 (PR #84 advisory item A5 refactor): four
//! `crates/doiget-cli/tests/*_e2e.rs` integration-test binaries each
//! defined a private `struct EnvGuard` with subtly different
//! capabilities (some snapshotted prior values, some only cleared).
//! Consolidated here on the snapshot-and-restore variant so a test that
//! runs after another test that exported a real `DOIGET_*` env var
//! cannot leak that variable into the test under inspection.
/// RAII guard that saves + clears the named env vars on construction
/// and restores them on drop.