Files
ELYTerminal/src/testlog.rs
T
ZacharyZhang-NY dfaf378418
CI / platforms (windows-latest) (push) Failing after 8s
CI / macos (push) Failing after 8m47s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s
T05: shell integration for zsh, bash, fish, PowerShell; installed at start
2026-10-14 12:24:31 -04:00

37 lines
941 B
Rust

use std::sync::{Mutex, Once};
static LINES: Mutex<Vec<String>> = Mutex::new(Vec::new());
/// Keeps every log line so tests can assert what was logged.
struct Capture;
impl log::Log for Capture {
fn enabled(&self, metadata: &log::Metadata) -> bool {
metadata.level() <= log::Level::Debug && metadata.target().starts_with("elyterminal")
}
fn log(&self, record: &log::Record) {
let line = record.args().to_string();
eprintln!("{} {line}", record.level());
LINES.lock().expect("the log lines").push(line);
}
fn flush(&self) {}
}
pub fn init() {
static ONCE: Once = Once::new();
ONCE.call_once(|| {
log::set_logger(&Capture).expect("the only logger in tests");
log::set_max_level(log::LevelFilter::Debug);
});
}
pub fn logged(line: &str) -> bool {
LINES
.lock()
.expect("the log lines")
.iter()
.any(|kept| kept == line)
}