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
//! Test-only helpers shared across the crate's in-crate integration
//! tests — the ones migrated in from `tests/` when the library surface
//! was narrowed to [`crate::cmd`] (§3.4). Not part of the public surface:
//! `#[cfg(test)]` and non-`pub` at the crate root, so the parity checker
//! (which counts only externally-public items) never sees it.
use crateRoots;
use ;
use Mutex;
/// Serializes `LERNIE_HOME` mutation. The harness-root env (§2.2) is
/// process-global; every in-process test that must point it at a scratch
/// dir (`prime`/`new`, which found real files; `config`, whose
/// `harness_root::resolve` call is unmocked; `archive::replay_cli`'s
/// `LERNIE_HOME`-scoped scratch base) funnels through [`with_lernie_home`]
/// so the mutation is the *one* place a parallel `cargo test --lib` run
/// can race — the lock, not the caller's own scope, is what makes it
/// safe. Rust 2024's `set_var` is `unsafe` for exactly this reason.
static ENV_LOCK: = new;
/// Run `f` with `LERNIE_HOME` set to `home`, then clear it. Serialized
/// against every other `LERNIE_HOME` mutation via [`ENV_LOCK`] — the
/// single guarded critical section, so a reader of the ambient env (e.g.
/// `harness_root::resolve` called from inside `f`) never observes another
/// test's home mid-flight. Tests never pre-set the var, so the restore is
/// an unconditional clear — not a save/restore of a prior value.
/// Roots pointing at nonexistent subdirs of `base` — no
/// `template/` override under the config root, no data-root pools:
/// the plain embedded-template scaffold shape most tests want.
/// Resolve the cargo-built `lernie` binary from the running test binary.
///
/// `env!("CARGO_BIN_EXE_lernie")` is set only for `tests/` integration
/// targets, not for lib unit tests, so an in-crate test that must spawn
/// the real binary derives it from `current_exe()`: the test executable
/// (`<target>/<profile>/deps/<test>-<hash>`) and the `lernie` binary
/// (`<target>/<profile>/lernie`) are siblings — walk up from the test
/// binary and take the first ancestor directory holding a `lernie` file.