Better tests

This commit is contained in:
Adrian Heine 2022-01-10 11:56:06 +01:00
parent 395fb1c9fa
commit 0d41e8a833
2 changed files with 112 additions and 63 deletions

View file

@ -2,12 +2,13 @@ use std::cell::RefCell;
use std::cmp::min;
use std::io::stderr;
use std::io::Write;
use std::rc::Rc;
// The log crate defines
// 1 - Error, 2 - Warn, 3 - Info, 4 - Debug, 5 - Trace
pub type Level = usize;
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct Entry<S>(pub Level, pub S);
pub trait Logger {
@ -100,7 +101,7 @@ impl<'a, L: Logger> Logger for FilteringLogger<'a, L> {
#[derive(Clone, Debug, Default)]
pub struct StoringLogger {
log: RefCell<(bool, Vec<Entry<String>>)>,
log: Rc<RefCell<(bool, Vec<Entry<String>>)>>,
}
impl StoringLogger {
@ -110,7 +111,7 @@ impl StoringLogger {
}
pub fn release(self) -> Vec<Entry<String>> {
self.log.into_inner().1
Rc::try_unwrap(self.log).unwrap().into_inner().1
}
}