1 | #![cfg (feature = "std" )] |
2 | use tracing::Level; |
3 | use tracing_mock::*; |
4 | |
5 | #[cfg_attr (target_arch = "wasm32" , wasm_bindgen_test::wasm_bindgen_test)] |
6 | #[test] |
7 | fn level_and_target() { |
8 | let subscriber = subscriber::mock() |
9 | .with_filter(|meta| { |
10 | if meta.target() == "debug_module" { |
11 | meta.level() <= &Level::DEBUG |
12 | } else { |
13 | meta.level() <= &Level::INFO |
14 | } |
15 | }) |
16 | .only() |
17 | .run(); |
18 | |
19 | let _guard = tracing::subscriber::set_default(subscriber); |
20 | |
21 | assert!(tracing::enabled!(target: "debug_module" , Level::DEBUG)); |
22 | assert!(tracing::enabled!(Level::ERROR)); |
23 | assert!(!tracing::enabled!(Level::DEBUG)); |
24 | } |
25 | |
26 | #[cfg_attr (target_arch = "wasm32" , wasm_bindgen_test::wasm_bindgen_test)] |
27 | #[test] |
28 | fn span_and_event() { |
29 | let subscriber = subscriber::mock() |
30 | .with_filter(|meta| { |
31 | if meta.target() == "debug_module" { |
32 | meta.level() <= &Level::DEBUG |
33 | } else if meta.is_span() { |
34 | meta.level() <= &Level::TRACE |
35 | } else if meta.is_event() { |
36 | meta.level() <= &Level::DEBUG |
37 | } else { |
38 | meta.level() <= &Level::INFO |
39 | } |
40 | }) |
41 | .only() |
42 | .run(); |
43 | |
44 | let _guard = tracing::subscriber::set_default(subscriber); |
45 | |
46 | // Ensure that the `_event` and `_span` alternatives work corretly |
47 | assert!(!tracing::event_enabled!(Level::TRACE)); |
48 | assert!(tracing::event_enabled!(Level::DEBUG)); |
49 | assert!(tracing::span_enabled!(Level::TRACE)); |
50 | |
51 | // target variants |
52 | assert!(tracing::span_enabled!(target: "debug_module" , Level::DEBUG)); |
53 | assert!(tracing::event_enabled!(target: "debug_module" , Level::DEBUG)); |
54 | } |
55 | |