Skip to content

Commit ced9302

Browse files
authored
tests: put mocking functionality into a crate (#2009)
... 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.
1 parent 44dc9f5 commit ced9302

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+120
-147
lines changed

β€ŽCargo.tomlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"tracing-tower",
1111
"tracing-log",
1212
"tracing-macros",
13+
"tracing-mock",
1314
"tracing-opentelemetry",
1415
"tracing-subscriber",
1516
"tracing-serde",

β€Žtracing-attributes/Cargo.tomlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ quote = "1"
4040

4141
[dev-dependencies]
4242
tracing = { path = "../tracing", version = "0.2" }
43+
tracing-mock = { path = "../tracing-mock", features = ["tokio-test"] }
4344
tokio-test = { version = "0.2.0" }
4445
tracing-core = { path = "../tracing-core", version = "0.2"}
4546
async-trait = "0.1.44"

β€Žtracing-attributes/tests/async_fn.rsβ€Ž

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
#[path = "../../tracing-futures/tests/support.rs"]
2-
// we don't use some of the test support functions, but `tracing-futures` does.
3-
#[allow(dead_code)]
4-
mod support;
5-
use support::*;
1+
use tracing_mock::*;
62

73
use std::{future::Future, pin::Pin, sync::Arc};
84
use tracing::collect::with_default;

β€Žtracing-attributes/tests/destructuring.rsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
mod support;
2-
use support::*;
3-
41
use tracing::collect::with_default;
52
use tracing_attributes::instrument;
3+
use tracing_mock::*;
64

75
#[test]
86
fn destructure_tuples() {

β€Žtracing-attributes/tests/err.rsβ€Ž

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
#[path = "../../tracing-futures/tests/support.rs"]
2-
// we don't use some of the test support functions, but `tracing-futures` does.
3-
#[allow(dead_code)]
4-
mod support;
5-
use support::*;
6-
71
use tracing::collect::with_default;
82
use tracing::Level;
93
use tracing_attributes::instrument;
4+
use tracing_mock::*;
105

116
use std::convert::TryFrom;
127
use std::num::TryFromIntError;

β€Žtracing-attributes/tests/fields.rsβ€Ž

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
mod support;
2-
use support::*;
3-
4-
use crate::support::field::mock;
5-
use crate::support::span::NewSpan;
61
use tracing::collect::with_default;
72
use tracing_attributes::instrument;
3+
use tracing_mock::field::mock;
4+
use tracing_mock::span::NewSpan;
5+
use tracing_mock::*;
86

97
#[instrument(fields(foo = "bar", dsa = true, num = 1))]
108
fn fn_no_param() {}

β€Žtracing-attributes/tests/instrument.rsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
mod support;
2-
use support::*;
3-
41
use tracing::collect::with_default;
52
use tracing::Level;
63
use tracing_attributes::instrument;
4+
use tracing_mock::*;
75

86
#[test]
97
fn override_everything() {

β€Žtracing-attributes/tests/levels.rsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
mod support;
2-
use support::*;
3-
41
use tracing::collect::with_default;
52
use tracing::Level;
63
use tracing_attributes::instrument;
4+
use tracing_mock::*;
75

86
#[test]
97
fn named_levels() {

β€Žtracing-attributes/tests/names.rsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
mod support;
2-
use support::*;
3-
41
use tracing::collect::with_default;
52
use tracing_attributes::instrument;
3+
use tracing_mock::*;
64

75
#[instrument]
86
fn default_name() {}

β€Žtracing-attributes/tests/ret.rsβ€Ž

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
#[path = "../../tracing-futures/tests/support.rs"]
2-
// we don't use some of the test support functions, but `tracing-futures` does.
3-
#[allow(dead_code)]
4-
mod support;
5-
use support::*;
6-
71
use std::convert::TryFrom;
82
use std::num::TryFromIntError;
3+
use tracing_mock::*;
94

105
use tracing::{collect::with_default, Level};
116
use tracing_attributes::instrument;

0 commit comments

Comments
Β (0)