mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
simplify unit tests
don't require them to start the logger
This commit is contained in:
parent
07967927dd
commit
afbf0aaa75
@ -271,7 +271,6 @@ pub fn build_archive_file_suggestion(path: &Path, suggested_extension: &str) ->
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::utils::logger::spawn_logger_thread;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_extensions_from_path() {
|
fn test_extensions_from_path() {
|
||||||
@ -286,7 +285,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
/// Test extension parsing for input/output files
|
/// Test extension parsing for input/output files
|
||||||
fn test_separate_known_extensions_from_name() {
|
fn test_separate_known_extensions_from_name() {
|
||||||
spawn_logger_thread();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
separate_known_extensions_from_name("file".as_ref()),
|
separate_known_extensions_from_name("file".as_ref()),
|
||||||
("file".as_ref(), vec![])
|
("file".as_ref(), vec![])
|
||||||
|
@ -125,10 +125,14 @@ mod logger_thread {
|
|||||||
static SENDER: OnceLock<LogSender> = OnceLock::new();
|
static SENDER: OnceLock<LogSender> = OnceLock::new();
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn setup_channel() -> LogReceiver {
|
fn setup_channel() -> Option<LogReceiver> {
|
||||||
let (tx, rx) = mpsc::channel();
|
let mut optional = None;
|
||||||
SENDER.set(tx).expect("`setup_channel` should only be called once");
|
SENDER.get_or_init(|| {
|
||||||
rx
|
let (tx, rx) = mpsc::channel();
|
||||||
|
optional = Some(rx);
|
||||||
|
tx
|
||||||
|
});
|
||||||
|
optional
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
@ -138,6 +142,9 @@ mod logger_thread {
|
|||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub(super) fn send_print_command(msg: PrintMessage) {
|
pub(super) fn send_print_command(msg: PrintMessage) {
|
||||||
|
if cfg!(test) {
|
||||||
|
spawn_logger_thread();
|
||||||
|
}
|
||||||
get_sender()
|
get_sender()
|
||||||
.send(LoggerCommand::Print(msg))
|
.send(LoggerCommand::Print(msg))
|
||||||
.expect("Failed to send print command");
|
.expect("Failed to send print command");
|
||||||
@ -170,8 +177,9 @@ mod logger_thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn spawn_logger_thread() {
|
pub fn spawn_logger_thread() {
|
||||||
let log_receiver = setup_channel();
|
if let Some(log_receiver) = setup_channel() {
|
||||||
thread::spawn(move || run_logger(log_receiver));
|
thread::spawn(move || run_logger(log_receiver));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_logger(log_receiver: LogReceiver) {
|
fn run_logger(log_receiver: LogReceiver) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user