1 mod common;
2 
3 use common::*;
4 use tracing_core::dispatcher::*;
5 
6 #[cfg(feature = "std")]
7 #[test]
set_default_dispatch()8 fn set_default_dispatch() {
9     set_global_default(Dispatch::new(TestSubscriberA)).expect("global dispatch set failed");
10     get_default(|current| {
11         assert!(
12             current.is::<TestSubscriberA>(),
13             "global dispatch get failed"
14         )
15     });
16 
17     let guard = set_default(&Dispatch::new(TestSubscriberB));
18     get_default(|current| assert!(current.is::<TestSubscriberB>(), "set_default get failed"));
19 
20     // Drop the guard, setting the dispatch back to the global dispatch
21     drop(guard);
22 
23     get_default(|current| {
24         assert!(
25             current.is::<TestSubscriberA>(),
26             "global dispatch get failed"
27         )
28     });
29 }
30 
31 #[cfg(feature = "std")]
32 #[test]
nested_set_default()33 fn nested_set_default() {
34     let _guard = set_default(&Dispatch::new(TestSubscriberA));
35     get_default(|current| {
36         assert!(
37             current.is::<TestSubscriberA>(),
38             "set_default for outer subscriber failed"
39         )
40     });
41 
42     let inner_guard = set_default(&Dispatch::new(TestSubscriberB));
43     get_default(|current| {
44         assert!(
45             current.is::<TestSubscriberB>(),
46             "set_default inner subscriber failed"
47         )
48     });
49 
50     drop(inner_guard);
51     get_default(|current| {
52         assert!(
53             current.is::<TestSubscriberA>(),
54             "set_default outer subscriber failed"
55         )
56     });
57 }
58