summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tracing-core/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/tracing-core/tests
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tracing-core/tests')
-rw-r--r--third_party/rust/tracing-core/tests/common/mod.rs30
-rw-r--r--third_party/rust/tracing-core/tests/dispatch.rs56
-rw-r--r--third_party/rust/tracing-core/tests/global_dispatch.rs34
-rw-r--r--third_party/rust/tracing-core/tests/macros.rs48
4 files changed, 168 insertions, 0 deletions
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::<TestSubscriberA>(),
+ "global dispatch get failed"
+ )
+ });
+
+ let guard = set_default(&Dispatch::new(TestSubscriberB));
+ get_default(|current| assert!(current.is::<TestSubscriberB>(), "set_default get failed"));
+
+ // Drop the guard, setting the dispatch back to the global dispatch
+ drop(guard);
+
+ get_default(|current| {
+ assert!(
+ current.is::<TestSubscriberA>(),
+ "global dispatch get failed"
+ )
+ });
+}
+
+#[test]
+fn nested_set_default() {
+ let _guard = set_default(&Dispatch::new(TestSubscriberA));
+ get_default(|current| {
+ assert!(
+ current.is::<TestSubscriberA>(),
+ "set_default for outer subscriber failed"
+ )
+ });
+
+ let inner_guard = set_default(&Dispatch::new(TestSubscriberB));
+ get_default(|current| {
+ assert!(
+ current.is::<TestSubscriberB>(),
+ "set_default inner subscriber failed"
+ )
+ });
+
+ drop(inner_guard);
+ get_default(|current| {
+ assert!(
+ current.is::<TestSubscriberA>(),
+ "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::<TestSubscriberA>(),
+ "global dispatch get failed"
+ )
+ });
+
+ #[cfg(feature = "std")]
+ with_default(&Dispatch::new(TestSubscriberB), || {
+ get_default(|current| {
+ assert!(
+ current.is::<TestSubscriberB>(),
+ "thread-local override of global dispatch failed"
+ )
+ });
+ });
+
+ get_default(|current| {
+ assert!(
+ current.is::<TestSubscriberA>(),
+ "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
+ };
+}