Skip to content

Commit dd67660

Browse files
authored
mock: document public APIs in event module (#2426)
## Motivation There has been interest around publishing tracing-mock to crates.io for some time. In order to make this possible, documentation and some code clean up is needed. The `event` module needs documentation and examples. ## Solution This change adds documentation to the event module and all the public APIs within it. This includes doctests on all the methods which serve as examples. The following pattern was applied to the description of most methods: - Short description of expectation - Additional clarification (where needed) - Description of cases that cause the expectation to fail - Examples - Successful validation - Unsuccesful validation Two changes were also made in the text provided to the user when an assertion fails for `with_explicit_parent` or `with_contextual_parent`. One small API changes is also included: The method `in_scope` has been placed behind the `tracing-subscriber` feature flag as it currently only works with the `MockSubscriber`, not with the `MockCollector`. If the feature flag is active and it is used to set a non-empty scope, the `MockCollector` will panic with `unimplemented` during validation. Refs: #539
1 parent 58accc6 commit dd67660

File tree

4 files changed

+476
-18
lines changed

4 files changed

+476
-18
lines changed

tracing-mock/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ publish = false
2020
[dependencies]
2121
tracing = { path = "../tracing", version = "0.2" }
2222
tracing-core = { path = "../tracing-core", version = "0.2", default-features = false }
23-
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", default-features = false, optional = true }
23+
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", default-features = false, features = ["registry"], optional = true }
2424
tokio-test = { version = "0.4.2", optional = true }
2525

2626
# Fix minimal-versions; tokio-test fails with otherwise acceptable 0.1.0

tracing-mock/src/collector.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ where
229229
match self.expected.lock().unwrap().pop_front() {
230230
None => {}
231231
Some(Expect::Event(mut expected)) => {
232+
#[cfg(feature = "tracing-subscriber")]
233+
{
234+
if !expected.scope_mut().is_empty() {
235+
unimplemented!(
236+
"Expected scope for events is not supported with `MockCollector`."
237+
)
238+
}
239+
}
232240
let get_parent_name = || {
233241
let stack = self.current.lock().unwrap();
234242
let spans = self.spans.lock().unwrap();

0 commit comments

Comments
 (0)