From ced93022f9c805682dd909a3cabd476b01eb24eb Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Tue, 22 Mar 2022 12:37:15 -0500 Subject: [PATCH] tests: put mocking functionality into a crate (#2009) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... instead of `#[path = ""]` importing it everywhere. Make sure to use a diff review tool that understands file renaming 😅 (GitHub's diff view does.) ## Motivation Transparency: I want to use the mocking functionality in the development of a tracing component out-of-tree. Additionally, this reduces the use of `#[path] mod` and file multiple-inclusion, which aren't that great of a practice. ## Solution The tracing test support module was already well self-contained, due to being `#[path] mod` used in multiple places. As such, extracting it to its own crate is rather mechanical, with no surprising blockers. We additionally move the tracing-futures support module contents into tracing_mock, for convenience. The one function which relies on tokio-test is made optional. It's a reasonable result for this functionality to stay unpublished, and only used inside the repo, but pulling it out into a directly reusable chunk instead of abusing the module system to reuse it via multiple-inclusion is an improvement to code structure and modularization. --- Cargo.toml | 1 + tracing-attributes/Cargo.toml | 1 + tracing-attributes/tests/async_fn.rs | 6 +---- tracing-attributes/tests/destructuring.rs | 4 +-- tracing-attributes/tests/err.rs | 7 +---- tracing-attributes/tests/fields.rs | 8 +++--- tracing-attributes/tests/instrument.rs | 4 +-- tracing-attributes/tests/levels.rs | 4 +-- tracing-attributes/tests/names.rs | 4 +-- tracing-attributes/tests/ret.rs | 7 +---- tracing-attributes/tests/support.rs | 5 ---- tracing-attributes/tests/targets.rs | 4 +-- tracing-futures/Cargo.toml | 1 + tracing-futures/src/lib.rs | 11 ++------ tracing-futures/tests/std_future.rs | 4 +-- tracing-mock/Cargo.toml | 27 +++++++++++++++++++ tracing-mock/LICENSE | 25 +++++++++++++++++ .../support => tracing-mock/src}/collector.rs | 0 .../support => tracing-mock/src}/event.rs | 4 +-- .../support => tracing-mock/src}/field.rs | 0 .../support.rs => tracing-mock/src/lib.rs | 27 ++++++++++++------- .../support => tracing-mock/src}/metadata.rs | 2 +- .../support => tracing-mock/src}/span.rs | 13 +++------ tracing-subscriber/Cargo.toml | 1 + tracing-subscriber/tests/duplicate_spans.rs | 1 - tracing-subscriber/tests/field_filter.rs | 4 +-- tracing-subscriber/tests/filter.rs | 3 +-- tracing-subscriber/tests/filter_log.rs | 4 +-- .../tests/reload_max_log_level.rs | 3 +-- tracing-subscriber/tests/same_len_filters.rs | 4 +-- tracing-subscriber/tests/support.rs | 8 ------ tracing-subscriber/tests/utils.rs | 4 +-- tracing/Cargo.toml | 1 + .../test_static_max_level_features/Cargo.toml | 1 + .../tests/test.rs | 7 +---- tracing/tests/collector.rs | 4 +-- tracing/tests/enabled.rs | 4 +-- tracing/tests/event.rs | 4 +-- .../filter_caching_is_lexically_scoped.rs | 4 +-- ...s_are_not_reevaluated_for_the_same_span.rs | 3 +-- ...re_reevaluated_for_different_call_sites.rs | 4 +-- tracing/tests/filters_dont_leak.rs | 3 +-- tracing/tests/max_level_hint.rs | 4 +-- tracing/tests/multiple_max_level_hints.rs | 3 +-- tracing/tests/no_collector.rs | 5 +--- tracing/tests/span.rs | 5 ++-- tracing/tests/support/mod.rs | 14 ---------- 47 files changed, 120 insertions(+), 147 deletions(-) delete mode 100644 tracing-attributes/tests/support.rs create mode 100644 tracing-mock/Cargo.toml create mode 100644 tracing-mock/LICENSE rename {tracing/tests/support => tracing-mock/src}/collector.rs (100%) rename {tracing/tests/support => tracing-mock/src}/event.rs (94%) rename {tracing/tests/support => tracing-mock/src}/field.rs (100%) rename tracing-futures/tests/support.rs => tracing-mock/src/lib.rs (79%) rename {tracing/tests/support => tracing-mock/src}/metadata.rs (94%) rename {tracing/tests/support => tracing-mock/src}/span.rs (89%) delete mode 100644 tracing-subscriber/tests/support.rs delete mode 100644 tracing/tests/support/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 79b600dbfb..35d6147776 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "tracing-tower", "tracing-log", "tracing-macros", + "tracing-mock", "tracing-opentelemetry", "tracing-subscriber", "tracing-serde", diff --git a/tracing-attributes/Cargo.toml b/tracing-attributes/Cargo.toml index 5d43956343..c715430866 100644 --- a/tracing-attributes/Cargo.toml +++ b/tracing-attributes/Cargo.toml @@ -40,6 +40,7 @@ quote = "1" [dev-dependencies] tracing = { path = "../tracing", version = "0.2" } +tracing-mock = { path = "../tracing-mock", features = ["tokio-test"] } tokio-test = { version = "0.2.0" } tracing-core = { path = "../tracing-core", version = "0.2"} async-trait = "0.1.44" diff --git a/tracing-attributes/tests/async_fn.rs b/tracing-attributes/tests/async_fn.rs index 68fc38568e..177a2a1b5b 100644 --- a/tracing-attributes/tests/async_fn.rs +++ b/tracing-attributes/tests/async_fn.rs @@ -1,8 +1,4 @@ -#[path = "../../tracing-futures/tests/support.rs"] -// we don't use some of the test support functions, but `tracing-futures` does. -#[allow(dead_code)] -mod support; -use support::*; +use tracing_mock::*; use std::{future::Future, pin::Pin, sync::Arc}; use tracing::collect::with_default; diff --git a/tracing-attributes/tests/destructuring.rs b/tracing-attributes/tests/destructuring.rs index b755a4e219..8064c406cc 100644 --- a/tracing-attributes/tests/destructuring.rs +++ b/tracing-attributes/tests/destructuring.rs @@ -1,8 +1,6 @@ -mod support; -use support::*; - use tracing::collect::with_default; use tracing_attributes::instrument; +use tracing_mock::*; #[test] fn destructure_tuples() { diff --git a/tracing-attributes/tests/err.rs b/tracing-attributes/tests/err.rs index ca8c2e3c07..1629ac102f 100644 --- a/tracing-attributes/tests/err.rs +++ b/tracing-attributes/tests/err.rs @@ -1,12 +1,7 @@ -#[path = "../../tracing-futures/tests/support.rs"] -// we don't use some of the test support functions, but `tracing-futures` does. -#[allow(dead_code)] -mod support; -use support::*; - use tracing::collect::with_default; use tracing::Level; use tracing_attributes::instrument; +use tracing_mock::*; use std::convert::TryFrom; use std::num::TryFromIntError; diff --git a/tracing-attributes/tests/fields.rs b/tracing-attributes/tests/fields.rs index 3fc0aaab89..e789dfddbd 100644 --- a/tracing-attributes/tests/fields.rs +++ b/tracing-attributes/tests/fields.rs @@ -1,10 +1,8 @@ -mod support; -use support::*; - -use crate::support::field::mock; -use crate::support::span::NewSpan; use tracing::collect::with_default; use tracing_attributes::instrument; +use tracing_mock::field::mock; +use tracing_mock::span::NewSpan; +use tracing_mock::*; #[instrument(fields(foo = "bar", dsa = true, num = 1))] fn fn_no_param() {} diff --git a/tracing-attributes/tests/instrument.rs b/tracing-attributes/tests/instrument.rs index 0e27c2cc60..5790d1d2f6 100644 --- a/tracing-attributes/tests/instrument.rs +++ b/tracing-attributes/tests/instrument.rs @@ -1,9 +1,7 @@ -mod support; -use support::*; - use tracing::collect::with_default; use tracing::Level; use tracing_attributes::instrument; +use tracing_mock::*; #[test] fn override_everything() { diff --git a/tracing-attributes/tests/levels.rs b/tracing-attributes/tests/levels.rs index dfd064bb04..2b34319667 100644 --- a/tracing-attributes/tests/levels.rs +++ b/tracing-attributes/tests/levels.rs @@ -1,9 +1,7 @@ -mod support; -use support::*; - use tracing::collect::with_default; use tracing::Level; use tracing_attributes::instrument; +use tracing_mock::*; #[test] fn named_levels() { diff --git a/tracing-attributes/tests/names.rs b/tracing-attributes/tests/names.rs index b272f9dad0..f97a747e4f 100644 --- a/tracing-attributes/tests/names.rs +++ b/tracing-attributes/tests/names.rs @@ -1,8 +1,6 @@ -mod support; -use support::*; - use tracing::collect::with_default; use tracing_attributes::instrument; +use tracing_mock::*; #[instrument] fn default_name() {} diff --git a/tracing-attributes/tests/ret.rs b/tracing-attributes/tests/ret.rs index d59d611824..878a901d02 100644 --- a/tracing-attributes/tests/ret.rs +++ b/tracing-attributes/tests/ret.rs @@ -1,11 +1,6 @@ -#[path = "../../tracing-futures/tests/support.rs"] -// we don't use some of the test support functions, but `tracing-futures` does. -#[allow(dead_code)] -mod support; -use support::*; - use std::convert::TryFrom; use std::num::TryFromIntError; +use tracing_mock::*; use tracing::{collect::with_default, Level}; use tracing_attributes::instrument; diff --git a/tracing-attributes/tests/support.rs b/tracing-attributes/tests/support.rs deleted file mode 100644 index 5514b1d4ad..0000000000 --- a/tracing-attributes/tests/support.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[path = "../../tracing/tests/support/mod.rs"] -// path attribute requires referenced module to have same name so allow module inception here -#[allow(clippy::module_inception)] -mod support; -pub use self::support::*; diff --git a/tracing-attributes/tests/targets.rs b/tracing-attributes/tests/targets.rs index 08949e0c52..ba476611aa 100644 --- a/tracing-attributes/tests/targets.rs +++ b/tracing-attributes/tests/targets.rs @@ -1,8 +1,6 @@ -mod support; -use support::*; - use tracing::collect::with_default; use tracing_attributes::instrument; +use tracing_mock::*; #[instrument] fn default_target() {} diff --git a/tracing-futures/Cargo.toml b/tracing-futures/Cargo.toml index c330c75a51..24af248538 100644 --- a/tracing-futures/Cargo.toml +++ b/tracing-futures/Cargo.toml @@ -38,6 +38,7 @@ tokio = { version = "0.1", optional = true } tokio = "0.1.22" tokio-test = "0.2" tracing-core = { path = "../tracing-core", version = "0.2" } +tracing-mock = { path = "../tracing-mock" } [badges] maintenance = { status = "actively-developed" } diff --git a/tracing-futures/src/lib.rs b/tracing-futures/src/lib.rs index 49a3a1990e..9083edfdc1 100644 --- a/tracing-futures/src/lib.rs +++ b/tracing-futures/src/lib.rs @@ -512,17 +512,10 @@ impl WithDispatch { } } -#[cfg(test)] -pub(crate) use self::support as test_support; -// This has to have the same name as the module in `tracing`. -#[path = "../../tracing/tests/support/mod.rs"] -#[cfg(test)] -#[allow(unreachable_pub)] -pub(crate) mod support; - #[cfg(test)] mod tests { - use super::{test_support::*, *}; + use super::*; + use tracing_mock::*; #[cfg(feature = "futures-01")] mod futures_01_tests { diff --git a/tracing-futures/tests/std_future.rs b/tracing-futures/tests/std_future.rs index 8757b88d13..7242320191 100644 --- a/tracing-futures/tests/std_future.rs +++ b/tracing-futures/tests/std_future.rs @@ -1,8 +1,6 @@ -mod support; -use support::*; - use tracing::Instrument; use tracing::{collect::with_default, Level}; +use tracing_mock::*; #[test] fn enter_exit_is_reasonable() { diff --git a/tracing-mock/Cargo.toml b/tracing-mock/Cargo.toml new file mode 100644 index 0000000000..8fb7a19019 --- /dev/null +++ b/tracing-mock/Cargo.toml @@ -0,0 +1,27 @@ +## BIG SCARY NOTE +# This Cargo.toml does not match the repo conventions YET +# Before releasing to crates.io: make it so! + +[package] +name = "tracing-mock" +version = "0.2.0" +authors = [ + "Eliza Weisman ", + "Tokio Contributors ", +] +license = "MIT" +readme = "README.md" +repository = "https://github.com/tokio-rs/tracing" +homepage = "https://tokio.rs" +edition = "2018" +rust-version = "1.49.0" +publish = false + +[dependencies] +tracing = { path = "../tracing", version = "0.2", default-features = false } +tracing-core = { path = "../tracing-core", version = "0.2", default-features = false } +tokio-test = { version = "0.2.0", optional = true } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/tracing-mock/LICENSE b/tracing-mock/LICENSE new file mode 100644 index 0000000000..cdb28b4b56 --- /dev/null +++ b/tracing-mock/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2019 Tokio Contributors + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/tracing/tests/support/collector.rs b/tracing-mock/src/collector.rs similarity index 100% rename from tracing/tests/support/collector.rs rename to tracing-mock/src/collector.rs diff --git a/tracing/tests/support/event.rs b/tracing-mock/src/event.rs similarity index 94% rename from tracing/tests/support/event.rs rename to tracing-mock/src/event.rs index 7033d8a134..8ce36a25bc 100644 --- a/tracing/tests/support/event.rs +++ b/tracing-mock/src/event.rs @@ -10,7 +10,7 @@ use std::fmt; #[derive(Debug, Default, Eq, PartialEq)] pub struct MockEvent { pub fields: Option, - pub(in crate::support) parent: Option, + pub(crate) parent: Option, metadata: metadata::Expect, } @@ -78,7 +78,7 @@ impl MockEvent { } } - pub(in crate::support) fn check(&mut self, event: &tracing::Event<'_>) { + pub(crate) fn check(&mut self, event: &tracing::Event<'_>) { let meta = event.metadata(); let name = meta.name(); self.metadata diff --git a/tracing/tests/support/field.rs b/tracing-mock/src/field.rs similarity index 100% rename from tracing/tests/support/field.rs rename to tracing-mock/src/field.rs diff --git a/tracing-futures/tests/support.rs b/tracing-mock/src/lib.rs similarity index 79% rename from tracing-futures/tests/support.rs rename to tracing-mock/src/lib.rs index 08bf462728..f860f3b9a9 100644 --- a/tracing-futures/tests/support.rs +++ b/tracing-mock/src/lib.rs @@ -1,15 +1,21 @@ -// this is the only way to make the path attribute play nice with `in -// crate::support`... -#[allow(clippy::module_inception)] -#[path = "../../tracing/tests/support/mod.rs"] -mod support; use std::{ - future::Future, pin::Pin, task::{Context, Poll}, }; -pub use support::*; -use tokio_test::task; + +pub mod collector; +pub mod event; +pub mod field; +mod metadata; +pub mod span; + +#[derive(Debug, Eq, PartialEq)] +pub(crate) enum Parent { + ContextualRoot, + Contextual(String), + ExplicitRoot, + Explicit(String), +} pub struct PollN { and_return: Option>, @@ -56,10 +62,13 @@ impl PollN<(), ()> { } } +#[cfg(feature = "tokio-test")] pub fn block_on_future(future: F) -> F::Output where - F: Future, + F: std::future::Future, { + use tokio_test::task; + let mut task = task::spawn(future); loop { if let Poll::Ready(v) = task.poll() { diff --git a/tracing/tests/support/metadata.rs b/tracing-mock/src/metadata.rs similarity index 94% rename from tracing/tests/support/metadata.rs rename to tracing-mock/src/metadata.rs index 2c3606b05e..f648c46141 100644 --- a/tracing/tests/support/metadata.rs +++ b/tracing-mock/src/metadata.rs @@ -9,7 +9,7 @@ pub struct Expect { } impl Expect { - pub(in crate::support) fn check(&self, actual: &Metadata<'_>, ctx: fmt::Arguments<'_>) { + pub(crate) fn check(&self, actual: &Metadata<'_>, ctx: fmt::Arguments<'_>) { if let Some(ref expected_name) = self.name { let name = actual.name(); assert!( diff --git a/tracing/tests/support/span.rs b/tracing-mock/src/span.rs similarity index 89% rename from tracing/tests/support/span.rs rename to tracing-mock/src/span.rs index 21112a8818..5b9ce7df23 100644 --- a/tracing/tests/support/span.rs +++ b/tracing-mock/src/span.rs @@ -8,14 +8,14 @@ use std::fmt; /// `subscriber` module. #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct MockSpan { - pub(in crate::support) metadata: metadata::Expect, + pub(crate) metadata: metadata::Expect, } #[derive(Debug, Default, Eq, PartialEq)] pub struct NewSpan { - pub(in crate::support) span: MockSpan, - pub(in crate::support) fields: field::Expect, - pub(in crate::support) parent: Option, + pub(crate) span: MockSpan, + pub(crate) fields: field::Expect, + pub(crate) parent: Option, } pub fn mock() -> MockSpan { @@ -96,11 +96,6 @@ impl MockSpan { ..Default::default() } } - - pub(in crate::support) fn check_metadata(&self, actual: &tracing::Metadata<'_>) { - self.metadata.check(actual, format_args!("span {}", self)); - assert!(actual.is_span(), "expected a span but got {:?}", actual); - } } impl fmt::Display for MockSpan { diff --git a/tracing-subscriber/Cargo.toml b/tracing-subscriber/Cargo.toml index 978e12bc40..9b9bb46283 100644 --- a/tracing-subscriber/Cargo.toml +++ b/tracing-subscriber/Cargo.toml @@ -65,6 +65,7 @@ thread_local = { version = "1.1.4", optional = true } [dev-dependencies] tracing = { path = "../tracing", version = "0.2" } +tracing-mock = { path = "../tracing-mock" } log = "0.4" tracing-log = { path = "../tracing-log", version = "0.2" } criterion = { version = "0.3", default_features = false } diff --git a/tracing-subscriber/tests/duplicate_spans.rs b/tracing-subscriber/tests/duplicate_spans.rs index 173c9ac3ba..32dfd525f9 100644 --- a/tracing-subscriber/tests/duplicate_spans.rs +++ b/tracing-subscriber/tests/duplicate_spans.rs @@ -1,5 +1,4 @@ #![cfg(all(feature = "env-filter", feature = "fmt"))] -mod support; use tracing::{self, collect::with_default, Span}; use tracing_subscriber::{filter::EnvFilter, fmt::Collector}; diff --git a/tracing-subscriber/tests/field_filter.rs b/tracing-subscriber/tests/field_filter.rs index 56ef889ee4..09754ed70d 100644 --- a/tracing-subscriber/tests/field_filter.rs +++ b/tracing-subscriber/tests/field_filter.rs @@ -1,7 +1,7 @@ #![cfg(feature = "env-filter")] -mod support; -use self::support::*; + use tracing::{self, collect::with_default, Level}; +use tracing_mock::*; use tracing_subscriber::{filter::EnvFilter, prelude::*}; #[test] diff --git a/tracing-subscriber/tests/filter.rs b/tracing-subscriber/tests/filter.rs index f17a533a03..1d269db95a 100644 --- a/tracing-subscriber/tests/filter.rs +++ b/tracing-subscriber/tests/filter.rs @@ -1,8 +1,7 @@ #![cfg(feature = "env-filter")] -mod support; -use self::support::*; use tracing::{self, collect::with_default, Level}; +use tracing_mock::*; use tracing_subscriber::{ filter::{EnvFilter, LevelFilter}, prelude::*, diff --git a/tracing-subscriber/tests/filter_log.rs b/tracing-subscriber/tests/filter_log.rs index 083f02bc09..1a81c9c394 100644 --- a/tracing-subscriber/tests/filter_log.rs +++ b/tracing-subscriber/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/tracing-subscriber/tests/reload_max_log_level.rs b/tracing-subscriber/tests/reload_max_log_level.rs index 1d485ce56a..ec172d5b8d 100644 --- a/tracing-subscriber/tests/reload_max_log_level.rs +++ b/tracing-subscriber/tests/reload_max_log_level.rs @@ -1,8 +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::LevelFilter, prelude::*, reload}; #[test] diff --git a/tracing-subscriber/tests/same_len_filters.rs b/tracing-subscriber/tests/same_len_filters.rs index fc0d8175d0..523e9819a2 100644 --- a/tracing-subscriber/tests/same_len_filters.rs +++ b/tracing-subscriber/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, collect::with_default, Level}; +use tracing_mock::*; use tracing_subscriber::{filter::EnvFilter, prelude::*}; #[test] diff --git a/tracing-subscriber/tests/support.rs b/tracing-subscriber/tests/support.rs deleted file mode 100644 index a69d95e84d..0000000000 --- a/tracing-subscriber/tests/support.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[cfg(test)] -pub use self::support::*; -// This has to have the same name as the module in `tracing`. -#[path = "../../tracing/tests/support/mod.rs"] -#[cfg(test)] -// path attribute requires referenced module to have same name so allow module inception here -#[allow(clippy::module_inception)] -mod support; diff --git a/tracing-subscriber/tests/utils.rs b/tracing-subscriber/tests/utils.rs index 3e3506cb02..34e9bb6eae 100644 --- a/tracing-subscriber/tests/utils.rs +++ b/tracing-subscriber/tests/utils.rs @@ -1,6 +1,6 @@ #![cfg(feature = "std")] -mod support; -use self::support::*; + +use tracing_mock::*; use tracing_subscriber::prelude::*; #[test] diff --git a/tracing/Cargo.toml b/tracing/Cargo.toml index 8cdc29467c..66419e31e9 100644 --- a/tracing/Cargo.toml +++ b/tracing/Cargo.toml @@ -40,6 +40,7 @@ pin-project-lite = "0.2" [dev-dependencies] criterion = { version = "0.3", default_features = false } log = "0.4" +tracing-mock = { path = "../tracing-mock" } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "^0.3" diff --git a/tracing/test_static_max_level_features/Cargo.toml b/tracing/test_static_max_level_features/Cargo.toml index 3770240b2a..89edfd506b 100644 --- a/tracing/test_static_max_level_features/Cargo.toml +++ b/tracing/test_static_max_level_features/Cargo.toml @@ -19,3 +19,4 @@ features = ["max_level_debug", "release_max_level_info"] [dev-dependencies] tokio-test = "0.2.0" +tracing-mock = { path = "../../tracing-mock", features = ["tokio-test"] } diff --git a/tracing/test_static_max_level_features/tests/test.rs b/tracing/test_static_max_level_features/tests/test.rs index f0798a6797..f4c6e12036 100644 --- a/tracing/test_static_max_level_features/tests/test.rs +++ b/tracing/test_static_max_level_features/tests/test.rs @@ -1,9 +1,3 @@ -#[path = "../../../tracing-futures/tests/support.rs"] -// this is only needed for `block_on_future` -#[allow(dead_code)] -mod support; -use support::*; - use std::future::Future; use std::pin::Pin; use std::sync::{Arc, Mutex}; @@ -12,6 +6,7 @@ use tracing::{ debug, error, info, instrument, span, trace, warn, Collect, Event, Id, Level, Metadata, }; use tracing_core::span::Current; +use tracing_mock::*; struct State { last_level: Mutex>, diff --git a/tracing/tests/collector.rs b/tracing/tests/collector.rs index 64a14825aa..fa602ac4bf 100644 --- a/tracing/tests/collector.rs +++ b/tracing/tests/collector.rs @@ -12,9 +12,7 @@ use tracing::{ Event, Level, Metadata, }; -mod support; - -use self::support::*; +use tracing_mock::*; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/tests/enabled.rs b/tracing/tests/enabled.rs index 59c9c1106e..09fe8c3ab3 100644 --- a/tracing/tests/enabled.rs +++ b/tracing/tests/enabled.rs @@ -2,10 +2,8 @@ // statically #![cfg(feature = "alloc")] -mod support; - -use self::support::*; use tracing::Level; +use tracing_mock::*; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/tests/event.rs b/tracing/tests/event.rs index 75dec9d0e6..eeba3a00cf 100644 --- a/tracing/tests/event.rs +++ b/tracing/tests/event.rs @@ -5,9 +5,6 @@ // The alternative would be for each of these tests to be defined in a separate // file, which is :( #![cfg(feature = "std")] -mod support; - -use self::support::*; use tracing::{ collect::with_default, @@ -15,6 +12,7 @@ use tracing::{ field::{debug, display}, info, trace, warn, Level, }; +use tracing_mock::*; macro_rules! event_without_message { ($name:ident: $e:expr) => { diff --git a/tracing/tests/filter_caching_is_lexically_scoped.rs b/tracing/tests/filter_caching_is_lexically_scoped.rs index 5a15889d4d..848f343462 100644 --- a/tracing/tests/filter_caching_is_lexically_scoped.rs +++ b/tracing/tests/filter_caching_is_lexically_scoped.rs @@ -11,10 +11,8 @@ #[cfg(not(feature = "std"))] extern crate std; -mod support; - -use self::support::*; use tracing::{span, Level}; +use tracing_mock::*; use std::sync::{ atomic::{AtomicUsize, Ordering}, diff --git a/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs b/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs index ef12aefe7c..ee34761fc3 100644 --- a/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs +++ b/tracing/tests/filters_are_not_reevaluated_for_the_same_span.rs @@ -10,10 +10,9 @@ #[cfg(not(feature = "std"))] extern crate std; -mod support; -use self::support::*; use tracing::{span, Level}; +use tracing_mock::*; use std::sync::{ atomic::{AtomicUsize, Ordering}, diff --git a/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs b/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs index 87bad8794d..1be61b3940 100644 --- a/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs +++ b/tracing/tests/filters_are_reevaluated_for_different_call_sites.rs @@ -12,9 +12,7 @@ extern crate std; use tracing::{span, Level}; -mod support; - -use self::support::*; +use tracing_mock::*; use std::sync::{ atomic::{AtomicUsize, Ordering}, diff --git a/tracing/tests/filters_dont_leak.rs b/tracing/tests/filters_dont_leak.rs index 8587dd1cf0..1f4e07801b 100644 --- a/tracing/tests/filters_dont_leak.rs +++ b/tracing/tests/filters_dont_leak.rs @@ -1,7 +1,6 @@ #![cfg(feature = "std")] -mod support; -use self::support::*; +use tracing_mock::*; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/tests/max_level_hint.rs b/tracing/tests/max_level_hint.rs index d2e51adee7..007bd8bbfa 100644 --- a/tracing/tests/max_level_hint.rs +++ b/tracing/tests/max_level_hint.rs @@ -2,10 +2,8 @@ // statically #![cfg(feature = "alloc")] -mod support; - -use self::support::*; use tracing::Level; +use tracing_mock::*; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/tests/multiple_max_level_hints.rs b/tracing/tests/multiple_max_level_hints.rs index df04d89ab3..019f2b7cd4 100644 --- a/tracing/tests/multiple_max_level_hints.rs +++ b/tracing/tests/multiple_max_level_hints.rs @@ -1,8 +1,7 @@ #![cfg(feature = "std")] -mod support; -use self::support::*; use tracing::Level; +use tracing_mock::*; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/tests/no_collector.rs b/tracing/tests/no_collector.rs index 6598ea55e4..4a65b7781d 100644 --- a/tracing/tests/no_collector.rs +++ b/tracing/tests/no_collector.rs @@ -1,10 +1,7 @@ #![cfg(feature = "std")] use tracing::collect; - -mod support; - -use self::support::*; +use tracing_mock::*; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/tests/span.rs b/tracing/tests/span.rs index 2218d54c58..637b9149c5 100644 --- a/tracing/tests/span.rs +++ b/tracing/tests/span.rs @@ -3,15 +3,14 @@ // with the standard lib disabled. #![cfg(feature = "std")] -mod support; - -use self::support::*; use std::thread; + use tracing::{ collect::with_default, field::{debug, display}, Level, Span, }; +use tracing_mock::*; #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] #[test] diff --git a/tracing/tests/support/mod.rs b/tracing/tests/support/mod.rs deleted file mode 100644 index f0bf36a583..0000000000 --- a/tracing/tests/support/mod.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![allow(dead_code)] -pub mod collector; -pub mod event; -pub mod field; -mod metadata; -pub mod span; - -#[derive(Debug, Eq, PartialEq)] -pub(in crate::support) enum Parent { - ContextualRoot, - Contextual(String), - ExplicitRoot, - Explicit(String), -}