-
Notifications
You must be signed in to change notification settings - Fork 27
/
lib.rs
36 lines (31 loc) · 1.13 KB
/
lib.rs
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
//! This crate is only here to test the `tracing-test-macro` crate (because proc macros cannot be
//! tested from within the crate itself).
#[cfg(test)]
mod tests {
use tracing::{info, warn};
use tracing_test::traced_test;
#[tokio::test]
#[traced_test]
async fn test_logs_are_captured() {
// Local log
info!("This is being logged on the info level");
// Log from a spawned task (which runs in a separate thread)
tokio::spawn(async {
warn!("This is being logged on the warn level from a spawned task");
})
.await
.unwrap();
// Ensure that `logs_contain` works as intended
assert!(logs_contain("logged on the info level"));
assert!(logs_contain("logged on the warn level"));
assert!(!logs_contain("logged on the error level"));
}
#[traced_test]
#[test]
fn annotate_sync_test() {
assert!(!logs_contain("Logging from a non-async test"));
info!("Logging from a non-async test");
assert!(logs_contain("Logging from a non-async test"));
assert!(!logs_contain("This was never logged"));
}
}