Commit cc98eb34 authored by Raphaël Gomès's avatar Raphaël Gomès
Browse files

Add behavior tests

parent 6dbf275963cf
//! Behavio(u)r tests
//!
//! Check if the macro actually behaves as intended.
use log::{self, LevelFilter, Metadata, Record};
use micro_timer::timed;
use std::sync::atomic::{AtomicIsize, Ordering};
#[test]
fn test_behavior() {
struct SimpleLogger {
called: AtomicIsize,
};
impl log::Log for SimpleLogger {
fn enabled(&self, _metadata: &Metadata) -> bool {
true
}
fn log(&self, record: &Record) {
self.called.fetch_add(1, Ordering::Relaxed);
assert_eq!(record.level(), LevelFilter::Trace);
assert!(record
.args()
.to_string()
.starts_with("Duration of `thing`:"))
}
fn flush(&self) {}
}
static LOGGER: SimpleLogger = SimpleLogger {
called: AtomicIsize::new(0),
};
log::set_logger(&LOGGER)
.map(|()| log::set_max_level(LevelFilter::Trace))
.unwrap();
#[timed]
fn thing() {}
assert_eq!(LOGGER.called.load(Ordering::Relaxed), 0);
thing();
assert_eq!(LOGGER.called.load(Ordering::Relaxed), 1);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment