global_dispatch.rs 894 B

12345678910111213141516171819202122232425262728293031323334
  1. mod common;
  2. use common::*;
  3. use tracing_core::dispatcher::*;
  4. #[test]
  5. fn global_dispatch() {
  6. set_global_default(Dispatch::new(TestSubscriberA)).expect("global dispatch set failed");
  7. get_default(|current| {
  8. assert!(
  9. current.is::<TestSubscriberA>(),
  10. "global dispatch get failed"
  11. )
  12. });
  13. #[cfg(feature = "std")]
  14. with_default(&Dispatch::new(TestSubscriberB), || {
  15. get_default(|current| {
  16. assert!(
  17. current.is::<TestSubscriberB>(),
  18. "thread-local override of global dispatch failed"
  19. )
  20. });
  21. });
  22. get_default(|current| {
  23. assert!(
  24. current.is::<TestSubscriberA>(),
  25. "reset to global override failed"
  26. )
  27. });
  28. set_global_default(Dispatch::new(TestSubscriberA))
  29. .expect_err("double global dispatch set succeeded");
  30. }