1#![cfg(feature = "std")]
2mod common;
3
4use common::*;
5use tracing_core::dispatcher::*;
6
7#[test]
8fn 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#[test]
32fn nested_set_default() {
33 let _guard = set_default(&Dispatch::new(TestSubscriberA));
34 get_default(|current| {
35 assert!(
36 current.is::<TestSubscriberA>(),
37 "set_default for outer subscriber failed"
38 )
39 });
40
41 let inner_guard = set_default(&Dispatch::new(TestSubscriberB));
42 get_default(|current| {
43 assert!(
44 current.is::<TestSubscriberB>(),
45 "set_default inner subscriber failed"
46 )
47 });
48
49 drop(inner_guard);
50 get_default(|current| {
51 assert!(
52 current.is::<TestSubscriberA>(),
53 "set_default outer subscriber failed"
54 )
55 });
56}
57