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
//! Test-only corner-table event log.
//!
//! Captures corner-table `set`/`map` operations during encoder and decoder
//! `CornerTable` construction so targeted tests can assert on how connectivity
//! is built. Not used on production code paths.
// Test-only event log used to capture corner-table operations (set/map) during
// encoder and decoder CornerTable construction for targeted tests.
use std::sync::{Mutex, OnceLock};
// Test event logger used by both unit and integration tests. Lightweight and
// only used for diagnostics of encoder/decoder ordering. Functions are public
// so integration tests (tests/) can access them.
static LOG: OnceLock<Mutex<Vec<String>>> = OnceLock::new();
pub fn init() {
LOG.get_or_init(|| Mutex::new(Vec::new()));
}
pub fn clear() {
if let Some(m) = LOG.get() {
m.lock().unwrap().clear();
}
}
pub fn enabled() -> bool {
LOG.get().is_some()
}
pub fn record_event(s: String) {
if let Some(m) = LOG.get() {
m.lock().unwrap().push(s);
}
}
pub fn take_events() -> Vec<String> {
if let Some(m) = LOG.get() {
let mut g = m.lock().unwrap();
std::mem::take(&mut *g)
} else {
Vec::new()
}
}