diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:28 +0000 |
commit | 94a0819fe3a0d679c3042a77bfe6a2afc505daea (patch) | |
tree | 2b827afe6a05f3538db3f7803a88c4587fe85648 /vendor/tracing-subscriber-0.3.3/tests | |
parent | Adding upstream version 1.64.0+dfsg1. (diff) | |
download | rustc-94a0819fe3a0d679c3042a77bfe6a2afc505daea.tar.xz rustc-94a0819fe3a0d679c3042a77bfe6a2afc505daea.zip |
Adding upstream version 1.66.0+dfsg1.upstream/1.66.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/cached_layer_filters_dont_break_other_layers.rs (renamed from vendor/tracing-subscriber/tests/cached_layer_filters_dont_break_other_layers.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/duplicate_spans.rs (renamed from vendor/tracing-subscriber/tests/duplicate_spans.rs) | 1 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/field_filter.rs (renamed from vendor/tracing-subscriber/tests/field_filter.rs) | 4 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/filter.rs | 187 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/filter_log.rs (renamed from vendor/tracing-subscriber/tests/filter_log.rs) | 4 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/fmt_max_level_hint.rs (renamed from vendor/tracing-subscriber/tests/fmt_max_level_hint.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/hinted_layer_filters_dont_break_other_layers.rs (renamed from vendor/tracing-subscriber/tests/hinted_layer_filters_dont_break_other_layers.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/layer_filter_interests_are_cached.rs (renamed from vendor/tracing-subscriber/tests/layer_filter_interests_are_cached.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/layer_filters/boxed.rs (renamed from vendor/tracing-subscriber/tests/layer_filters/boxed.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/layer_filters/downcast_raw.rs (renamed from vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/layer_filters/filter_scopes.rs (renamed from vendor/tracing-subscriber/tests/layer_filters/filter_scopes.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/layer_filters/main.rs | 188 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/layer_filters/targets.rs (renamed from vendor/tracing-subscriber/tests/layer_filters/targets.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/layer_filters/trees.rs (renamed from vendor/tracing-subscriber/tests/layer_filters/trees.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/multiple_layer_filter_interests_cached.rs (renamed from vendor/tracing-subscriber/tests/multiple_layer_filter_interests_cached.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/registry_max_level_hint.rs (renamed from vendor/tracing-subscriber/tests/registry_max_level_hint.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/registry_with_subscriber.rs (renamed from vendor/tracing-subscriber/tests/registry_with_subscriber.rs) | 2 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/reload.rs | 81 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/same_len_filters.rs (renamed from vendor/tracing-subscriber/tests/same_len_filters.rs) | 4 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/support.rs (renamed from vendor/tracing-subscriber/tests/support.rs) | 19 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/unhinted_layer_filters_dont_break_other_layers.rs (renamed from vendor/tracing-subscriber/tests/unhinted_layer_filters_dont_break_other_layers.rs) | 0 | ||||
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/tests/utils.rs | 39 |
22 files changed, 515 insertions, 14 deletions
diff --git a/vendor/tracing-subscriber/tests/cached_layer_filters_dont_break_other_layers.rs b/vendor/tracing-subscriber-0.3.3/tests/cached_layer_filters_dont_break_other_layers.rs index 00e98a994..00e98a994 100644 --- a/vendor/tracing-subscriber/tests/cached_layer_filters_dont_break_other_layers.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/cached_layer_filters_dont_break_other_layers.rs diff --git a/vendor/tracing-subscriber/tests/duplicate_spans.rs b/vendor/tracing-subscriber-0.3.3/tests/duplicate_spans.rs index 5d4dc6a85..c4a736f74 100644 --- a/vendor/tracing-subscriber/tests/duplicate_spans.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/duplicate_spans.rs @@ -1,4 +1,5 @@ #![cfg(all(feature = "env-filter", feature = "fmt"))] +mod support; use tracing::{self, subscriber::with_default, Span}; use tracing_subscriber::{filter::EnvFilter, FmtSubscriber}; diff --git a/vendor/tracing-subscriber/tests/field_filter.rs b/vendor/tracing-subscriber-0.3.3/tests/field_filter.rs index f14a0626d..12b4053b6 100644 --- a/vendor/tracing-subscriber/tests/field_filter.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/field_filter.rs @@ -1,7 +1,7 @@ #![cfg(feature = "env-filter")] - +mod support; +use self::support::*; use tracing::{self, subscriber::with_default, Level}; -use tracing_mock::*; use tracing_subscriber::{filter::EnvFilter, prelude::*}; #[test] diff --git a/vendor/tracing-subscriber-0.3.3/tests/filter.rs b/vendor/tracing-subscriber-0.3.3/tests/filter.rs new file mode 100644 index 000000000..8386d34d2 --- /dev/null +++ b/vendor/tracing-subscriber-0.3.3/tests/filter.rs @@ -0,0 +1,187 @@ +#![cfg(feature = "env-filter")] + +mod support; +use self::support::*; +use tracing::{self, subscriber::with_default, Level}; +use tracing_subscriber::{ + filter::{EnvFilter, LevelFilter}, + prelude::*, +}; + +#[test] +fn level_filter_event() { + let filter: EnvFilter = "info".parse().expect("filter should parse"); + let (subscriber, finished) = subscriber::mock() + .event(event::mock().at_level(Level::INFO)) + .event(event::mock().at_level(Level::WARN)) + .event(event::mock().at_level(Level::ERROR)) + .done() + .run_with_handle(); + let subscriber = subscriber.with(filter); + + with_default(subscriber, || { + tracing::trace!("this should be disabled"); + tracing::info!("this shouldn't be"); + tracing::debug!(target: "foo", "this should also be disabled"); + tracing::warn!(target: "foo", "this should be enabled"); + tracing::error!("this should be enabled too"); + }); + + finished.assert_finished(); +} + +#[test] +fn same_name_spans() { + let filter: EnvFilter = "[foo{bar}]=trace,[foo{baz}]=trace" + .parse() + .expect("filter should parse"); + let (subscriber, finished) = subscriber::mock() + .new_span( + span::mock() + .named("foo") + .at_level(Level::TRACE) + .with_field(field::mock("bar")), + ) + .new_span( + span::mock() + .named("foo") + .at_level(Level::TRACE) + .with_field(field::mock("baz")), + ) + .done() + .run_with_handle(); + let subscriber = subscriber.with(filter); + with_default(subscriber, || { + tracing::trace_span!("foo", bar = 1); + tracing::trace_span!("foo", baz = 1); + }); + + finished.assert_finished(); +} + +#[test] +fn level_filter_event_with_target() { + let filter: EnvFilter = "info,stuff=debug".parse().expect("filter should parse"); + let (subscriber, finished) = subscriber::mock() + .event(event::mock().at_level(Level::INFO)) + .event(event::mock().at_level(Level::DEBUG).with_target("stuff")) + .event(event::mock().at_level(Level::WARN).with_target("stuff")) + .event(event::mock().at_level(Level::ERROR)) + .event(event::mock().at_level(Level::ERROR).with_target("stuff")) + .done() + .run_with_handle(); + let subscriber = subscriber.with(filter); + + with_default(subscriber, || { + tracing::trace!("this should be disabled"); + tracing::info!("this shouldn't be"); + tracing::debug!(target: "stuff", "this should be enabled"); + tracing::debug!("but this shouldn't"); + tracing::trace!(target: "stuff", "and neither should this"); + tracing::warn!(target: "stuff", "this should be enabled"); + tracing::error!("this should be enabled too"); + tracing::error!(target: "stuff", "this should be enabled also"); + }); + + finished.assert_finished(); +} + +#[test] +fn not_order_dependent() { + // this test reproduces tokio-rs/tracing#623 + + let filter: EnvFilter = "stuff=debug,info".parse().expect("filter should parse"); + let (subscriber, finished) = subscriber::mock() + .event(event::mock().at_level(Level::INFO)) + .event(event::mock().at_level(Level::DEBUG).with_target("stuff")) + .event(event::mock().at_level(Level::WARN).with_target("stuff")) + .event(event::mock().at_level(Level::ERROR)) + .event(event::mock().at_level(Level::ERROR).with_target("stuff")) + .done() + .run_with_handle(); + let subscriber = subscriber.with(filter); + + with_default(subscriber, || { + tracing::trace!("this should be disabled"); + tracing::info!("this shouldn't be"); + tracing::debug!(target: "stuff", "this should be enabled"); + tracing::debug!("but this shouldn't"); + tracing::trace!(target: "stuff", "and neither should this"); + tracing::warn!(target: "stuff", "this should be enabled"); + tracing::error!("this should be enabled too"); + tracing::error!(target: "stuff", "this should be enabled also"); + }); + + finished.assert_finished(); +} + +#[test] +fn add_directive_enables_event() { + // this test reproduces tokio-rs/tracing#591 + + // by default, use info level + let mut filter = EnvFilter::new(LevelFilter::INFO.to_string()); + + // overwrite with a more specific directive + filter = filter.add_directive("hello=trace".parse().expect("directive should parse")); + + let (subscriber, finished) = subscriber::mock() + .event(event::mock().at_level(Level::INFO).with_target("hello")) + .event(event::mock().at_level(Level::TRACE).with_target("hello")) + .done() + .run_with_handle(); + let subscriber = subscriber.with(filter); + + with_default(subscriber, || { + tracing::info!(target: "hello", "hello info"); + tracing::trace!(target: "hello", "hello trace"); + }); + + finished.assert_finished(); +} + +#[test] +fn span_name_filter_is_dynamic() { + let filter: EnvFilter = "info,[cool_span]=debug" + .parse() + .expect("filter should parse"); + let (subscriber, finished) = subscriber::mock() + .event(event::mock().at_level(Level::INFO)) + .enter(span::mock().named("cool_span")) + .event(event::mock().at_level(Level::DEBUG)) + .enter(span::mock().named("uncool_span")) + .event(event::mock().at_level(Level::WARN)) + .event(event::mock().at_level(Level::DEBUG)) + .exit(span::mock().named("uncool_span")) + .exit(span::mock().named("cool_span")) + .enter(span::mock().named("uncool_span")) + .event(event::mock().at_level(Level::WARN)) + .event(event::mock().at_level(Level::ERROR)) + .exit(span::mock().named("uncool_span")) + .done() + .run_with_handle(); + let subscriber = subscriber.with(filter); + + with_default(subscriber, || { + tracing::trace!("this should be disabled"); + tracing::info!("this shouldn't be"); + let cool_span = tracing::info_span!("cool_span"); + let uncool_span = tracing::info_span!("uncool_span"); + + { + let _enter = cool_span.enter(); + tracing::debug!("i'm a cool event"); + tracing::trace!("i'm cool, but not cool enough"); + let _enter2 = uncool_span.enter(); + tracing::warn!("warning: extremely cool!"); + tracing::debug!("i'm still cool"); + } + + let _enter = uncool_span.enter(); + tracing::warn!("warning: not that cool"); + tracing::trace!("im not cool enough"); + tracing::error!("uncool error"); + }); + + finished.assert_finished(); +} diff --git a/vendor/tracing-subscriber/tests/filter_log.rs b/vendor/tracing-subscriber-0.3.3/tests/filter_log.rs index 8d57ed600..28e742501 100644 --- a/vendor/tracing-subscriber/tests/filter_log.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/filter_log.rs @@ -1,7 +1,7 @@ #![cfg(all(feature = "env-filter", feature = "tracing-log"))] - +mod support; +use self::support::*; use tracing::{self, Level}; -use tracing_mock::*; use tracing_subscriber::{filter::EnvFilter, prelude::*}; mod my_module { diff --git a/vendor/tracing-subscriber/tests/fmt_max_level_hint.rs b/vendor/tracing-subscriber-0.3.3/tests/fmt_max_level_hint.rs index 57a0f6e3f..57a0f6e3f 100644 --- a/vendor/tracing-subscriber/tests/fmt_max_level_hint.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/fmt_max_level_hint.rs diff --git a/vendor/tracing-subscriber/tests/hinted_layer_filters_dont_break_other_layers.rs b/vendor/tracing-subscriber-0.3.3/tests/hinted_layer_filters_dont_break_other_layers.rs index 897dae282..897dae282 100644 --- a/vendor/tracing-subscriber/tests/hinted_layer_filters_dont_break_other_layers.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/hinted_layer_filters_dont_break_other_layers.rs diff --git a/vendor/tracing-subscriber/tests/layer_filter_interests_are_cached.rs b/vendor/tracing-subscriber-0.3.3/tests/layer_filter_interests_are_cached.rs index d89d3bf17..d89d3bf17 100644 --- a/vendor/tracing-subscriber/tests/layer_filter_interests_are_cached.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/layer_filter_interests_are_cached.rs diff --git a/vendor/tracing-subscriber/tests/layer_filters/boxed.rs b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/boxed.rs index 0fe37188e..0fe37188e 100644 --- a/vendor/tracing-subscriber/tests/layer_filters/boxed.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/boxed.rs diff --git a/vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/downcast_raw.rs index b5f7e35ce..b5f7e35ce 100644 --- a/vendor/tracing-subscriber/tests/layer_filters/downcast_raw.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/downcast_raw.rs diff --git a/vendor/tracing-subscriber/tests/layer_filters/filter_scopes.rs b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/filter_scopes.rs index 7fd7d843b..7fd7d843b 100644 --- a/vendor/tracing-subscriber/tests/layer_filters/filter_scopes.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/filter_scopes.rs diff --git a/vendor/tracing-subscriber-0.3.3/tests/layer_filters/main.rs b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/main.rs new file mode 100644 index 000000000..2359584d7 --- /dev/null +++ b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/main.rs @@ -0,0 +1,188 @@ +#![cfg(feature = "registry")] +#[path = "../support.rs"] +mod support; +use self::support::*; +mod boxed; +mod downcast_raw; +mod filter_scopes; +mod targets; +mod trees; + +use tracing::{level_filters::LevelFilter, Level}; +use tracing_subscriber::{filter, prelude::*}; + +#[test] +fn basic_layer_filters() { + let (trace_layer, trace_handle) = layer::named("trace") + .event(event::mock().at_level(Level::TRACE)) + .event(event::mock().at_level(Level::DEBUG)) + .event(event::mock().at_level(Level::INFO)) + .done() + .run_with_handle(); + + let (debug_layer, debug_handle) = layer::named("debug") + .event(event::mock().at_level(Level::DEBUG)) + .event(event::mock().at_level(Level::INFO)) + .done() + .run_with_handle(); + + let (info_layer, info_handle) = layer::named("info") + .event(event::mock().at_level(Level::INFO)) + .done() + .run_with_handle(); + + let _subscriber = tracing_subscriber::registry() + .with(trace_layer.with_filter(LevelFilter::TRACE)) + .with(debug_layer.with_filter(LevelFilter::DEBUG)) + .with(info_layer.with_filter(LevelFilter::INFO)) + .set_default(); + + tracing::trace!("hello trace"); + tracing::debug!("hello debug"); + tracing::info!("hello info"); + + trace_handle.assert_finished(); + debug_handle.assert_finished(); + info_handle.assert_finished(); +} + +#[test] +fn basic_layer_filters_spans() { + let (trace_layer, trace_handle) = layer::named("trace") + .new_span(span::mock().at_level(Level::TRACE)) + .new_span(span::mock().at_level(Level::DEBUG)) + .new_span(span::mock().at_level(Level::INFO)) + .done() + .run_with_handle(); + + let (debug_layer, debug_handle) = layer::named("debug") + .new_span(span::mock().at_level(Level::DEBUG)) + .new_span(span::mock().at_level(Level::INFO)) + .done() + .run_with_handle(); + + let (info_layer, info_handle) = layer::named("info") + .new_span(span::mock().at_level(Level::INFO)) + .done() + .run_with_handle(); + + let _subscriber = tracing_subscriber::registry() + .with(trace_layer.with_filter(LevelFilter::TRACE)) + .with(debug_layer.with_filter(LevelFilter::DEBUG)) + .with(info_layer.with_filter(LevelFilter::INFO)) + .set_default(); + + tracing::trace_span!("hello trace"); + tracing::debug_span!("hello debug"); + tracing::info_span!("hello info"); + + trace_handle.assert_finished(); + debug_handle.assert_finished(); + info_handle.assert_finished(); +} + +#[test] +fn global_filters_layers_still_work() { + let (expect, handle) = layer::mock() + .event(event::mock().at_level(Level::INFO)) + .event(event::mock().at_level(Level::WARN)) + .event(event::mock().at_level(Level::ERROR)) + .done() + .run_with_handle(); + + let _subscriber = tracing_subscriber::registry() + .with(expect) + .with(LevelFilter::INFO) + .set_default(); + + tracing::trace!("hello trace"); + tracing::debug!("hello debug"); + tracing::info!("hello info"); + tracing::warn!("hello warn"); + tracing::error!("hello error"); + + handle.assert_finished(); +} + +#[test] +fn global_filter_interests_are_cached() { + let (expect, handle) = layer::mock() + .event(event::mock().at_level(Level::WARN)) + .event(event::mock().at_level(Level::ERROR)) + .done() + .run_with_handle(); + + let _subscriber = tracing_subscriber::registry() + .with(expect.with_filter(filter::filter_fn(|meta| { + assert!( + meta.level() <= &Level::INFO, + "enabled should not be called for callsites disabled by the global filter" + ); + meta.level() <= &Level::WARN + }))) + .with(LevelFilter::INFO) + .set_default(); + + tracing::trace!("hello trace"); + tracing::debug!("hello debug"); + tracing::info!("hello info"); + tracing::warn!("hello warn"); + tracing::error!("hello error"); + + handle.assert_finished(); +} + +#[test] +fn global_filters_affect_layer_filters() { + let (expect, handle) = layer::named("debug") + .event(event::mock().at_level(Level::INFO)) + .event(event::mock().at_level(Level::WARN)) + .event(event::mock().at_level(Level::ERROR)) + .done() + .run_with_handle(); + + let _subscriber = tracing_subscriber::registry() + .with(expect.with_filter(LevelFilter::DEBUG)) + .with(LevelFilter::INFO) + .set_default(); + + tracing::trace!("hello trace"); + tracing::debug!("hello debug"); + tracing::info!("hello info"); + tracing::warn!("hello warn"); + tracing::error!("hello error"); + + handle.assert_finished(); +} + +#[test] +fn filter_fn() { + let (all, all_handle) = layer::named("all_targets") + .event(event::msg("hello foo")) + .event(event::msg("hello bar")) + .done() + .run_with_handle(); + + let (foo, foo_handle) = layer::named("foo_target") + .event(event::msg("hello foo")) + .done() + .run_with_handle(); + + let (bar, bar_handle) = layer::named("bar_target") + .event(event::msg("hello bar")) + .done() + .run_with_handle(); + + let _subscriber = tracing_subscriber::registry() + .with(all) + .with(foo.with_filter(filter::filter_fn(|meta| meta.target().starts_with("foo")))) + .with(bar.with_filter(filter::filter_fn(|meta| meta.target().starts_with("bar")))) + .set_default(); + + tracing::trace!(target: "foo", "hello foo"); + tracing::trace!(target: "bar", "hello bar"); + + foo_handle.assert_finished(); + bar_handle.assert_finished(); + all_handle.assert_finished(); +} diff --git a/vendor/tracing-subscriber/tests/layer_filters/targets.rs b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/targets.rs index c8133044b..c8133044b 100644 --- a/vendor/tracing-subscriber/tests/layer_filters/targets.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/targets.rs diff --git a/vendor/tracing-subscriber/tests/layer_filters/trees.rs b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/trees.rs index 18cdd8ccc..18cdd8ccc 100644 --- a/vendor/tracing-subscriber/tests/layer_filters/trees.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/layer_filters/trees.rs diff --git a/vendor/tracing-subscriber/tests/multiple_layer_filter_interests_cached.rs b/vendor/tracing-subscriber-0.3.3/tests/multiple_layer_filter_interests_cached.rs index 5c25e7f03..5c25e7f03 100644 --- a/vendor/tracing-subscriber/tests/multiple_layer_filter_interests_cached.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/multiple_layer_filter_interests_cached.rs diff --git a/vendor/tracing-subscriber/tests/registry_max_level_hint.rs b/vendor/tracing-subscriber-0.3.3/tests/registry_max_level_hint.rs index f94c8a1fb..f94c8a1fb 100644 --- a/vendor/tracing-subscriber/tests/registry_max_level_hint.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/registry_max_level_hint.rs diff --git a/vendor/tracing-subscriber/tests/registry_with_subscriber.rs b/vendor/tracing-subscriber-0.3.3/tests/registry_with_subscriber.rs index 50d2f551d..3f8d99b1d 100644 --- a/vendor/tracing-subscriber/tests/registry_with_subscriber.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/registry_with_subscriber.rs @@ -4,7 +4,7 @@ use tracing_subscriber::prelude::*; #[tokio::test] async fn future_with_subscriber() { - tracing_subscriber::registry().init(); + let _default = tracing_subscriber::registry().init(); let span = tracing::info_span!("foo"); let _e = span.enter(); let span = tracing::info_span!("bar"); diff --git a/vendor/tracing-subscriber-0.3.3/tests/reload.rs b/vendor/tracing-subscriber-0.3.3/tests/reload.rs new file mode 100644 index 000000000..5fe422e08 --- /dev/null +++ b/vendor/tracing-subscriber-0.3.3/tests/reload.rs @@ -0,0 +1,81 @@ +#![cfg(feature = "reload")] +use std::sync::atomic::{AtomicUsize, Ordering}; +use tracing_core::{ + span::{Attributes, Id, Record}, + subscriber::Interest, + Event, Metadata, Subscriber, +}; +use tracing_subscriber::{layer, prelude::*, reload::*}; + +pub struct NopSubscriber; + +impl Subscriber for NopSubscriber { + fn register_callsite(&self, _: &'static Metadata<'static>) -> Interest { + Interest::never() + } + + fn enabled(&self, _: &Metadata<'_>) -> bool { + false + } + + fn new_span(&self, _: &Attributes<'_>) -> Id { + Id::from_u64(1) + } + + fn record(&self, _: &Id, _: &Record<'_>) {} + fn record_follows_from(&self, _: &Id, _: &Id) {} + fn event(&self, _: &Event<'_>) {} + fn enter(&self, _: &Id) {} + fn exit(&self, _: &Id) {} +} + +#[test] +fn reload_handle() { + static FILTER1_CALLS: AtomicUsize = AtomicUsize::new(0); + static FILTER2_CALLS: AtomicUsize = AtomicUsize::new(0); + + enum Filter { + One, + Two, + } + + impl<S: Subscriber> tracing_subscriber::Layer<S> for Filter { + fn register_callsite(&self, m: &Metadata<'_>) -> Interest { + println!("REGISTER: {:?}", m); + Interest::sometimes() + } + + fn enabled(&self, m: &Metadata<'_>, _: layer::Context<'_, S>) -> bool { + println!("ENABLED: {:?}", m); + match self { + Filter::One => FILTER1_CALLS.fetch_add(1, Ordering::SeqCst), + Filter::Two => FILTER2_CALLS.fetch_add(1, Ordering::SeqCst), + }; + true + } + } + fn event() { + tracing::trace!("my event"); + } + + let (layer, handle) = Layer::new(Filter::One); + + let subscriber = tracing_core::dispatcher::Dispatch::new(layer.with_subscriber(NopSubscriber)); + + tracing_core::dispatcher::with_default(&subscriber, || { + assert_eq!(FILTER1_CALLS.load(Ordering::SeqCst), 0); + assert_eq!(FILTER2_CALLS.load(Ordering::SeqCst), 0); + + event(); + + assert_eq!(FILTER1_CALLS.load(Ordering::SeqCst), 1); + assert_eq!(FILTER2_CALLS.load(Ordering::SeqCst), 0); + + handle.reload(Filter::Two).expect("should reload"); + + event(); + + assert_eq!(FILTER1_CALLS.load(Ordering::SeqCst), 1); + assert_eq!(FILTER2_CALLS.load(Ordering::SeqCst), 1); + }) +} diff --git a/vendor/tracing-subscriber/tests/same_len_filters.rs b/vendor/tracing-subscriber-0.3.3/tests/same_len_filters.rs index 879e578d7..b525ea6fd 100644 --- a/vendor/tracing-subscriber/tests/same_len_filters.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/same_len_filters.rs @@ -1,9 +1,9 @@ // These tests include field filters with no targets, so they have to go in a // separate file. #![cfg(feature = "env-filter")] - +mod support; +use self::support::*; use tracing::{self, subscriber::with_default, Level}; -use tracing_mock::*; use tracing_subscriber::{filter::EnvFilter, prelude::*}; #[test] diff --git a/vendor/tracing-subscriber/tests/support.rs b/vendor/tracing-subscriber-0.3.3/tests/support.rs index 50e0e6669..848ebdc63 100644 --- a/vendor/tracing-subscriber/tests/support.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/support.rs @@ -1,15 +1,20 @@ #![allow(missing_docs, dead_code)] -pub use tracing_mock::{event, field, span, subscriber}; - -use tracing_core::{ - span::{Attributes, Id, Record}, - Event, Subscriber, -}; -use tracing_mock::{ +pub use self::support::{event, field, span, subscriber}; +// This has to have the same name as the module in `tracing`. +// path attribute requires referenced module to have same name so allow module inception here +#[allow(clippy::module_inception)] +#[path = "../../tracing/tests/support/mod.rs"] +mod support; + +use self::{ event::MockEvent, span::{MockSpan, NewSpan}, subscriber::{Expect, MockHandle}, }; +use tracing_core::{ + span::{Attributes, Id, Record}, + Event, Subscriber, +}; use tracing_subscriber::{ layer::{Context, Layer}, registry::{LookupSpan, SpanRef}, diff --git a/vendor/tracing-subscriber/tests/unhinted_layer_filters_dont_break_other_layers.rs b/vendor/tracing-subscriber-0.3.3/tests/unhinted_layer_filters_dont_break_other_layers.rs index 9fa5c6bd4..9fa5c6bd4 100644 --- a/vendor/tracing-subscriber/tests/unhinted_layer_filters_dont_break_other_layers.rs +++ b/vendor/tracing-subscriber-0.3.3/tests/unhinted_layer_filters_dont_break_other_layers.rs diff --git a/vendor/tracing-subscriber-0.3.3/tests/utils.rs b/vendor/tracing-subscriber-0.3.3/tests/utils.rs new file mode 100644 index 000000000..ff025a2a2 --- /dev/null +++ b/vendor/tracing-subscriber-0.3.3/tests/utils.rs @@ -0,0 +1,39 @@ +#![cfg(feature = "std")] +mod support; +use self::support::*; +use tracing_subscriber::prelude::*; + +#[test] +fn init_ext_works() { + let (subscriber, finished) = subscriber::mock() + .event( + event::mock() + .at_level(tracing::Level::INFO) + .with_target("init_works"), + ) + .done() + .run_with_handle(); + + let _guard = subscriber.set_default(); + tracing::info!(target: "init_works", "it worked!"); + finished.assert_finished(); +} + +#[test] +#[cfg(feature = "fmt")] +fn builders_are_init_ext() { + tracing_subscriber::fmt().set_default(); + let _ = tracing_subscriber::fmt() + .with_target(false) + .compact() + .try_init(); +} + +#[test] +#[cfg(all(feature = "fmt", feature = "env-filter"))] +fn layered_is_init_ext() { + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer()) + .with(tracing_subscriber::EnvFilter::new("foo=info")) + .set_default(); +} |