Skip to content

Commit

Permalink
mock: move subscriber mock from tracing-subscriber tests (#2369)
Browse files Browse the repository at this point in the history
The `tracing-subscriber` module `tests::support` included functionality
to mock a subscriber (via the `Subscribe` trait). This code depends on
some items from `tracing_mock::collector` which should otherwise not be
public.

This change moves the mocking functionality inside `tracing-mock` behind
a feature flag. Allowing the `Expect` enum and `MockHandle::new` from
`tracing_mock::collector` to be made `pub(crate)` instead of `pub`.
Since it's now used from two different modules, the `Expect` enum has
been moved to its own module.

This requires a lot of modifications to imports so that we're not doing
wildcard imports from another crate (i.e. in `tracing-subscriber`
importing wildcards from `tracing-mock`).

Closes: #2359
  • Loading branch information
hawkw committed Apr 21, 2023
1 parent 192921c commit cf94f91
Show file tree
Hide file tree
Showing 21 changed files with 1,126 additions and 465 deletions.
1 change: 1 addition & 0 deletions tracing-mock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ publish = false
[dependencies]
tracing = { path = "../tracing", version = "0.1.35", default-features = false }
tracing-core = { path = "../tracing-core", version = "0.1.28", default-features = false }
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", default-features = false, optional = true }
tokio-test = { version = "0.4.2", optional = true }

# Fix minimal-versions; tokio-test fails with otherwise acceptable 0.1.0
Expand Down
21 changes: 21 additions & 0 deletions tracing-mock/src/expectation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::{
event::MockEvent,
field,
span::{MockSpan, NewSpan},
};

#[derive(Debug, Eq, PartialEq)]
pub(crate) enum Expect {
Event(MockEvent),
FollowsFrom {
consequence: MockSpan,
cause: MockSpan,
},
Enter(MockSpan),
Exit(MockSpan),
CloneSpan(MockSpan),
DropSpan(MockSpan),
Visit(MockSpan, field::Expect),
NewSpan(NewSpan),
Nothing,
}
Loading

0 comments on commit cf94f91

Please sign in to comment.