diff options
Diffstat (limited to '')
-rw-r--r-- | vendor/tracing/tests/span.rs | 385 |
1 files changed, 214 insertions, 171 deletions
diff --git a/vendor/tracing/tests/span.rs b/vendor/tracing/tests/span.rs index 4ed650023..09f1be895 100644 --- a/vendor/tracing/tests/span.rs +++ b/vendor/tracing/tests/span.rs @@ -21,7 +21,12 @@ fn handles_to_the_same_span_are_equal() { // expect to see any spans. with_default(subscriber::mock().run(), || { let foo1 = tracing::span!(Level::TRACE, "foo"); + + // The purpose of this test is to assert that two clones of the same + // span are equal, so the clone here is kind of the whole point :) + #[allow(clippy::redundant_clone)] let foo2 = foo1.clone(); + // Two handles that point to the same span are equal. assert_eq!(foo1, foo2); }); @@ -62,12 +67,12 @@ fn handles_to_different_spans_with_the_same_metadata_are_not_equal() { #[test] fn spans_always_go_to_the_subscriber_that_tagged_them() { let subscriber1 = subscriber::mock() - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run(); let subscriber2 = subscriber::mock().run(); @@ -89,12 +94,12 @@ fn spans_always_go_to_the_subscriber_that_tagged_them() { #[test] fn spans_always_go_to_the_subscriber_that_tagged_them_even_across_threads() { let subscriber1 = subscriber::mock() - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run(); let foo = with_default(subscriber1, || { let foo = tracing::span!(Level::TRACE, "foo"); @@ -117,10 +122,10 @@ fn spans_always_go_to_the_subscriber_that_tagged_them_even_across_threads() { #[test] fn dropping_a_span_calls_drop_span() { let (subscriber, handle) = subscriber::mock() - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let span = tracing::span!(Level::TRACE, "foo"); @@ -135,11 +140,11 @@ fn dropping_a_span_calls_drop_span() { #[test] fn span_closes_after_event() { let (subscriber, handle) = subscriber::mock() - .enter(span::mock().named("foo")) - .event(event::mock()) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .event(expect::event()) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { tracing::span!(Level::TRACE, "foo").in_scope(|| { @@ -154,14 +159,14 @@ fn span_closes_after_event() { #[test] fn new_span_after_event() { let (subscriber, handle) = subscriber::mock() - .enter(span::mock().named("foo")) - .event(event::mock()) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .enter(span::mock().named("bar")) - .exit(span::mock().named("bar")) - .drop_span(span::mock().named("bar")) - .done() + .enter(expect::span().named("foo")) + .event(expect::event()) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .enter(expect::span().named("bar")) + .exit(expect::span().named("bar")) + .drop_span(expect::span().named("bar")) + .only() .run_with_handle(); with_default(subscriber, || { tracing::span!(Level::TRACE, "foo").in_scope(|| { @@ -177,11 +182,11 @@ fn new_span_after_event() { #[test] fn event_outside_of_span() { let (subscriber, handle) = subscriber::mock() - .event(event::mock()) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .event(expect::event()) + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { tracing::debug!("my tracing::event!"); @@ -195,7 +200,7 @@ fn event_outside_of_span() { #[test] fn cloning_a_span_calls_clone_span() { let (subscriber, handle) = subscriber::mock() - .clone_span(span::mock().named("foo")) + .clone_span(expect::span().named("foo")) .run_with_handle(); with_default(subscriber, || { let span = tracing::span!(Level::TRACE, "foo"); @@ -211,9 +216,9 @@ fn cloning_a_span_calls_clone_span() { #[test] fn drop_span_when_exiting_dispatchers_context() { let (subscriber, handle) = subscriber::mock() - .clone_span(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) + .clone_span(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) .run_with_handle(); with_default(subscriber, || { let span = tracing::span!(Level::TRACE, "foo"); @@ -228,15 +233,15 @@ fn drop_span_when_exiting_dispatchers_context() { #[test] fn clone_and_drop_span_always_go_to_the_subscriber_that_tagged_the_span() { let (subscriber1, handle1) = subscriber::mock() - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .clone_span(span::mock().named("foo")) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .clone_span(expect::span().named("foo")) + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) .run_with_handle(); - let subscriber2 = subscriber::mock().done().run(); + let subscriber2 = subscriber::mock().only().run(); let foo = with_default(subscriber1, || { let foo = tracing::span!(Level::TRACE, "foo"); @@ -259,10 +264,10 @@ fn clone_and_drop_span_always_go_to_the_subscriber_that_tagged_the_span() { #[test] fn span_closes_when_exited() { let (subscriber, handle) = subscriber::mock() - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let foo = tracing::span!(Level::TRACE, "foo"); @@ -279,11 +284,11 @@ fn span_closes_when_exited() { #[test] fn enter() { let (subscriber, handle) = subscriber::mock() - .enter(span::mock().named("foo")) - .event(event::mock()) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .event(expect::event()) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let foo = tracing::span!(Level::TRACE, "foo"); @@ -298,11 +303,11 @@ fn enter() { #[test] fn entered() { let (subscriber, handle) = subscriber::mock() - .enter(span::mock().named("foo")) - .event(event::mock()) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .event(expect::event()) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let _span = tracing::span!(Level::TRACE, "foo").entered(); @@ -316,11 +321,11 @@ fn entered() { #[test] fn entered_api() { let (subscriber, handle) = subscriber::mock() - .enter(span::mock().named("foo")) - .event(event::mock()) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .event(expect::event()) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let span = tracing::span!(Level::TRACE, "foo").entered(); @@ -337,16 +342,16 @@ fn entered_api() { fn moved_field() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("foo").with_field( - field::mock("bar") + expect::span().named("foo").with_field( + expect::field("bar") .with_value(&display("hello from my span")) .only(), ), ) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let from = "my span"; @@ -366,11 +371,11 @@ fn moved_field() { fn dotted_field_name() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock() + expect::span() .named("foo") - .with_field(field::mock("fields.bar").with_value(&true).only()), + .with_field(expect::field("fields.bar").with_value(&true).only()), ) - .done() + .only() .run_with_handle(); with_default(subscriber, || { tracing::span!(Level::TRACE, "foo", fields.bar = true); @@ -384,16 +389,16 @@ fn dotted_field_name() { fn borrowed_field() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("foo").with_field( - field::mock("bar") + expect::span().named("foo").with_field( + expect::field("bar") .with_value(&display("hello from my span")) .only(), ), ) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { @@ -427,17 +432,17 @@ fn move_field_out_of_struct() { }; let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("foo").with_field( - field::mock("x") + expect::span().named("foo").with_field( + expect::field("x") .with_value(&debug(3.234)) - .and(field::mock("y").with_value(&debug(-1.223))) + .and(expect::field("y").with_value(&debug(-1.223))) .only(), ), ) .new_span( - span::mock() + expect::span() .named("bar") - .with_field(field::mock("position").with_value(&debug(&pos)).only()), + .with_field(expect::field("position").with_value(&debug(&pos)).only()), ) .run_with_handle(); @@ -460,10 +465,10 @@ fn move_field_out_of_struct() { fn float_values() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("foo").with_field( - field::mock("x") + expect::span().named("foo").with_field( + expect::field("x") .with_value(&3.234) - .and(field::mock("y").with_value(&-1.223)) + .and(expect::field("y").with_value(&-1.223)) .only(), ), ) @@ -485,19 +490,19 @@ fn float_values() { fn add_field_after_new_span() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock() + expect::span() .named("foo") - .with_field(field::mock("bar").with_value(&5) - .and(field::mock("baz").with_value).only()), + .with_field(expect::field("bar").with_value(&5) + .and(expect::field("baz").with_value).only()), ) .record( - span::mock().named("foo"), - field::mock("baz").with_value(&true).only(), + expect::span().named("foo"), + field::expect("baz").with_value(&true).only(), ) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { @@ -513,19 +518,19 @@ fn add_field_after_new_span() { #[test] fn add_fields_only_after_new_span() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo")) + .new_span(expect::span().named("foo")) .record( - span::mock().named("foo"), - field::mock("bar").with_value(&5).only(), + expect::span().named("foo"), + field::expect("bar").with_value(&5).only(), ) .record( - span::mock().named("foo"), - field::mock("baz").with_value(&true).only(), + expect::span().named("foo"), + field::expect("baz").with_value(&true).only(), ) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { @@ -544,26 +549,26 @@ fn add_fields_only_after_new_span() { fn record_new_value_for_field() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("foo").with_field( - field::mock("bar") + expect::span().named("foo").with_field( + expect::field("bar") .with_value(&5) - .and(field::mock("baz").with_value(&false)) + .and(expect::field("baz").with_value(&false)) .only(), ), ) .record( - span::mock().named("foo"), - field::mock("baz").with_value(&true).only(), + expect::span().named("foo"), + expect::field("baz").with_value(&true).only(), ) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let span = tracing::span!(Level::TRACE, "foo", bar = 5, baz = false); - span.record("baz", &true); + span.record("baz", true); span.in_scope(|| {}) }); @@ -575,31 +580,31 @@ fn record_new_value_for_field() { fn record_new_values_for_fields() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("foo").with_field( - field::mock("bar") + expect::span().named("foo").with_field( + expect::field("bar") .with_value(&4) - .and(field::mock("baz").with_value(&false)) + .and(expect::field("baz").with_value(&false)) .only(), ), ) .record( - span::mock().named("foo"), - field::mock("bar").with_value(&5).only(), + expect::span().named("foo"), + expect::field("bar").with_value(&5).only(), ) .record( - span::mock().named("foo"), - field::mock("baz").with_value(&true).only(), + expect::span().named("foo"), + expect::field("baz").with_value(&true).only(), ) - .enter(span::mock().named("foo")) - .exit(span::mock().named("foo")) - .drop_span(span::mock().named("foo")) - .done() + .enter(expect::span().named("foo")) + .exit(expect::span().named("foo")) + .drop_span(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { let span = tracing::span!(Level::TRACE, "foo", bar = 4, baz = false); - span.record("bar", &5); - span.record("baz", &true); + span.record("bar", 5); + span.record("baz", true); span.in_scope(|| {}) }); @@ -611,12 +616,12 @@ fn record_new_values_for_fields() { fn new_span_with_target_and_log_level() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock() + expect::span() .named("foo") .with_target("app_span") .at_level(Level::DEBUG), ) - .done() + .only() .run_with_handle(); with_default(subscriber, || { @@ -630,8 +635,8 @@ fn new_span_with_target_and_log_level() { #[test] fn explicit_root_span_is_root() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo").with_explicit_parent(None)) - .done() + .new_span(expect::span().named("foo").with_explicit_parent(None)) + .only() .run_with_handle(); with_default(subscriber, || { @@ -645,11 +650,11 @@ fn explicit_root_span_is_root() { #[test] fn explicit_root_span_is_root_regardless_of_ctx() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo")) - .enter(span::mock().named("foo")) - .new_span(span::mock().named("bar").with_explicit_parent(None)) - .exit(span::mock().named("foo")) - .done() + .new_span(expect::span().named("foo")) + .enter(expect::span().named("foo")) + .new_span(expect::span().named("bar").with_explicit_parent(None)) + .exit(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { @@ -665,9 +670,13 @@ fn explicit_root_span_is_root_regardless_of_ctx() { #[test] fn explicit_child() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo")) - .new_span(span::mock().named("bar").with_explicit_parent(Some("foo"))) - .done() + .new_span(expect::span().named("foo")) + .new_span( + expect::span() + .named("bar") + .with_explicit_parent(Some("foo")), + ) + .only() .run_with_handle(); with_default(subscriber, || { @@ -682,13 +691,13 @@ fn explicit_child() { #[test] fn explicit_child_at_levels() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo")) - .new_span(span::mock().named("a").with_explicit_parent(Some("foo"))) - .new_span(span::mock().named("b").with_explicit_parent(Some("foo"))) - .new_span(span::mock().named("c").with_explicit_parent(Some("foo"))) - .new_span(span::mock().named("d").with_explicit_parent(Some("foo"))) - .new_span(span::mock().named("e").with_explicit_parent(Some("foo"))) - .done() + .new_span(expect::span().named("foo")) + .new_span(expect::span().named("a").with_explicit_parent(Some("foo"))) + .new_span(expect::span().named("b").with_explicit_parent(Some("foo"))) + .new_span(expect::span().named("c").with_explicit_parent(Some("foo"))) + .new_span(expect::span().named("d").with_explicit_parent(Some("foo"))) + .new_span(expect::span().named("e").with_explicit_parent(Some("foo"))) + .only() .run_with_handle(); with_default(subscriber, || { @@ -707,12 +716,16 @@ fn explicit_child_at_levels() { #[test] fn explicit_child_regardless_of_ctx() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo")) - .new_span(span::mock().named("bar")) - .enter(span::mock().named("bar")) - .new_span(span::mock().named("baz").with_explicit_parent(Some("foo"))) - .exit(span::mock().named("bar")) - .done() + .new_span(expect::span().named("foo")) + .new_span(expect::span().named("bar")) + .enter(expect::span().named("bar")) + .new_span( + expect::span() + .named("baz") + .with_explicit_parent(Some("foo")), + ) + .exit(expect::span().named("bar")) + .only() .run_with_handle(); with_default(subscriber, || { @@ -728,8 +741,8 @@ fn explicit_child_regardless_of_ctx() { #[test] fn contextual_root() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo").with_contextual_parent(None)) - .done() + .new_span(expect::span().named("foo").with_contextual_parent(None)) + .only() .run_with_handle(); with_default(subscriber, || { @@ -743,15 +756,15 @@ fn contextual_root() { #[test] fn contextual_child() { let (subscriber, handle) = subscriber::mock() - .new_span(span::mock().named("foo")) - .enter(span::mock().named("foo")) + .new_span(expect::span().named("foo")) + .enter(expect::span().named("foo")) .new_span( - span::mock() + expect::span() .named("bar") .with_contextual_parent(Some("foo")), ) - .exit(span::mock().named("foo")) - .done() + .exit(expect::span().named("foo")) + .only() .run_with_handle(); with_default(subscriber, || { @@ -768,13 +781,13 @@ fn contextual_child() { fn display_shorthand() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("my_span").with_field( - field::mock("my_field") + expect::span().named("my_span").with_field( + expect::field("my_field") .with_value(&display("hello world")) .only(), ), ) - .done() + .only() .run_with_handle(); with_default(subscriber, || { tracing::span!(Level::TRACE, "my_span", my_field = %"hello world"); @@ -788,13 +801,13 @@ fn display_shorthand() { fn debug_shorthand() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("my_span").with_field( - field::mock("my_field") + expect::span().named("my_span").with_field( + expect::field("my_field") .with_value(&debug("hello world")) .only(), ), ) - .done() + .only() .run_with_handle(); with_default(subscriber, || { tracing::span!(Level::TRACE, "my_span", my_field = ?"hello world"); @@ -808,14 +821,14 @@ fn debug_shorthand() { fn both_shorthands() { let (subscriber, handle) = subscriber::mock() .new_span( - span::mock().named("my_span").with_field( - field::mock("display_field") + expect::span().named("my_span").with_field( + expect::field("display_field") .with_value(&display("hello world")) - .and(field::mock("debug_field").with_value(&debug("hello world"))) + .and(expect::field("debug_field").with_value(&debug("hello world"))) .only(), ), ) - .done() + .only() .run_with_handle(); with_default(subscriber, || { tracing::span!(Level::TRACE, "my_span", display_field = %"hello world", debug_field = ?"hello world"); @@ -823,3 +836,33 @@ fn both_shorthands() { handle.assert_finished(); } + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[test] +fn constant_field_name() { + let (subscriber, handle) = subscriber::mock() + .new_span( + expect::span().named("my_span").with_field( + expect::field("foo") + .with_value(&"bar") + .and(expect::field("constant string").with_value(&"also works")) + .and(expect::field("foo.bar").with_value(&"baz")) + .only(), + ), + ) + .only() + .run_with_handle(); + + with_default(subscriber, || { + const FOO: &str = "foo"; + tracing::span!( + Level::TRACE, + "my_span", + { std::convert::identity(FOO) } = "bar", + { "constant string" } = "also works", + foo.bar = "baz", + ); + }); + + handle.assert_finished(); +} |