From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/tracing-core/tests/common/mod.rs | 30 ++++++++++++ third_party/rust/tracing-core/tests/dispatch.rs | 56 ++++++++++++++++++++++ .../rust/tracing-core/tests/global_dispatch.rs | 34 +++++++++++++ third_party/rust/tracing-core/tests/macros.rs | 48 +++++++++++++++++++ 4 files changed, 168 insertions(+) create mode 100644 third_party/rust/tracing-core/tests/common/mod.rs create mode 100644 third_party/rust/tracing-core/tests/dispatch.rs create mode 100644 third_party/rust/tracing-core/tests/global_dispatch.rs create mode 100644 third_party/rust/tracing-core/tests/macros.rs (limited to 'third_party/rust/tracing-core/tests') diff --git a/third_party/rust/tracing-core/tests/common/mod.rs b/third_party/rust/tracing-core/tests/common/mod.rs new file mode 100644 index 0000000000..3420f0b899 --- /dev/null +++ b/third_party/rust/tracing-core/tests/common/mod.rs @@ -0,0 +1,30 @@ +use tracing_core::{metadata::Metadata, span, subscriber::Subscriber, Event}; + +pub struct TestSubscriberA; +impl Subscriber for TestSubscriberA { + fn enabled(&self, _: &Metadata<'_>) -> bool { + true + } + fn new_span(&self, _: &span::Attributes<'_>) -> span::Id { + span::Id::from_u64(1) + } + fn record(&self, _: &span::Id, _: &span::Record<'_>) {} + fn record_follows_from(&self, _: &span::Id, _: &span::Id) {} + fn event(&self, _: &Event<'_>) {} + fn enter(&self, _: &span::Id) {} + fn exit(&self, _: &span::Id) {} +} +pub struct TestSubscriberB; +impl Subscriber for TestSubscriberB { + fn enabled(&self, _: &Metadata<'_>) -> bool { + true + } + fn new_span(&self, _: &span::Attributes<'_>) -> span::Id { + span::Id::from_u64(1) + } + fn record(&self, _: &span::Id, _: &span::Record<'_>) {} + fn record_follows_from(&self, _: &span::Id, _: &span::Id) {} + fn event(&self, _: &Event<'_>) {} + fn enter(&self, _: &span::Id) {} + fn exit(&self, _: &span::Id) {} +} diff --git a/third_party/rust/tracing-core/tests/dispatch.rs b/third_party/rust/tracing-core/tests/dispatch.rs new file mode 100644 index 0000000000..3820692a86 --- /dev/null +++ b/third_party/rust/tracing-core/tests/dispatch.rs @@ -0,0 +1,56 @@ +#![cfg(feature = "std")] +mod common; + +use common::*; +use tracing_core::dispatcher::*; + +#[test] +fn set_default_dispatch() { + set_global_default(Dispatch::new(TestSubscriberA)).expect("global dispatch set failed"); + get_default(|current| { + assert!( + current.is::(), + "global dispatch get failed" + ) + }); + + let guard = set_default(&Dispatch::new(TestSubscriberB)); + get_default(|current| assert!(current.is::(), "set_default get failed")); + + // Drop the guard, setting the dispatch back to the global dispatch + drop(guard); + + get_default(|current| { + assert!( + current.is::(), + "global dispatch get failed" + ) + }); +} + +#[test] +fn nested_set_default() { + let _guard = set_default(&Dispatch::new(TestSubscriberA)); + get_default(|current| { + assert!( + current.is::(), + "set_default for outer subscriber failed" + ) + }); + + let inner_guard = set_default(&Dispatch::new(TestSubscriberB)); + get_default(|current| { + assert!( + current.is::(), + "set_default inner subscriber failed" + ) + }); + + drop(inner_guard); + get_default(|current| { + assert!( + current.is::(), + "set_default outer subscriber failed" + ) + }); +} diff --git a/third_party/rust/tracing-core/tests/global_dispatch.rs b/third_party/rust/tracing-core/tests/global_dispatch.rs new file mode 100644 index 0000000000..d430ac6182 --- /dev/null +++ b/third_party/rust/tracing-core/tests/global_dispatch.rs @@ -0,0 +1,34 @@ +mod common; + +use common::*; +use tracing_core::dispatcher::*; +#[test] +fn global_dispatch() { + set_global_default(Dispatch::new(TestSubscriberA)).expect("global dispatch set failed"); + get_default(|current| { + assert!( + current.is::(), + "global dispatch get failed" + ) + }); + + #[cfg(feature = "std")] + with_default(&Dispatch::new(TestSubscriberB), || { + get_default(|current| { + assert!( + current.is::(), + "thread-local override of global dispatch failed" + ) + }); + }); + + get_default(|current| { + assert!( + current.is::(), + "reset to global override failed" + ) + }); + + set_global_default(Dispatch::new(TestSubscriberA)) + .expect_err("double global dispatch set succeeded"); +} diff --git a/third_party/rust/tracing-core/tests/macros.rs b/third_party/rust/tracing-core/tests/macros.rs new file mode 100644 index 0000000000..ee9007eeeb --- /dev/null +++ b/third_party/rust/tracing-core/tests/macros.rs @@ -0,0 +1,48 @@ +use tracing_core::{ + callsite::Callsite, + metadata, + metadata::{Kind, Level, Metadata}, + subscriber::Interest, +}; + +#[test] +fn metadata_macro_api() { + // This test should catch any inadvertent breaking changes + // caused by changes to the macro. + struct TestCallsite; + + impl Callsite for TestCallsite { + fn set_interest(&self, _: Interest) { + unimplemented!("test") + } + fn metadata(&self) -> &Metadata<'_> { + unimplemented!("test") + } + } + + static CALLSITE: TestCallsite = TestCallsite; + let _metadata = metadata! { + name: "test_metadata", + target: "test_target", + level: Level::DEBUG, + fields: &["foo", "bar", "baz"], + callsite: &CALLSITE, + kind: Kind::SPAN, + }; + let _metadata = metadata! { + name: "test_metadata", + target: "test_target", + level: Level::TRACE, + fields: &[], + callsite: &CALLSITE, + kind: Kind::EVENT, + }; + let _metadata = metadata! { + name: "test_metadata", + target: "test_target", + level: Level::INFO, + fields: &[], + callsite: &CALLSITE, + kind: Kind::EVENT + }; +} -- cgit v1.2.3