Skip to content

Commit

Permalink
mock: document public API in collector module (#2389)
Browse files Browse the repository at this point in the history
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.

This change adds documentation to the collector module itself and to all the
public APIs in the module. This includes doctests on all the methods
that serve as examples.

Additionally the implementation for the `Expect` struct has been moved
into the module with the definition, this was missed in #2369.

Refs: #539
  • Loading branch information
hds authored and davidbarsky committed Sep 26, 2023
1 parent 30895d6 commit 25ebc55
Show file tree
Hide file tree
Showing 2 changed files with 892 additions and 71 deletions.
50 changes: 50 additions & 0 deletions tracing-mock/src/expect.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt;

use crate::{
event::ExpectedEvent,
field::{ExpectedField, ExpectedFields, ExpectedValue},
Expand Down Expand Up @@ -41,3 +43,51 @@ pub fn span() -> ExpectedSpan {
..Default::default()
}
}

impl Expect {
pub(crate) fn bad(&self, name: impl AsRef<str>, what: fmt::Arguments<'_>) {
let name = name.as_ref();
match self {
Expect::Event(e) => panic!(
"\n[{}] expected event {}\n[{}] but instead {}",
name, e, name, what,
),
Expect::FollowsFrom { consequence, cause } => panic!(
"\n[{}] expected consequence {} to follow cause {} but instead {}",
name, consequence, cause, what,
),
Expect::Enter(e) => panic!(
"\n[{}] expected to enter {}\n[{}] but instead {}",
name, e, name, what,
),
Expect::Exit(e) => panic!(
"\n[{}] expected to exit {}\n[{}] but instead {}",
name, e, name, what,
),
Expect::CloneSpan(e) => {
panic!(
"\n[{}] expected to clone {}\n[{}] but instead {}",
name, e, name, what,
)
}
Expect::DropSpan(e) => {
panic!(
"\n[{}] expected to drop {}\n[{}] but instead {}",
name, e, name, what,
)
}
Expect::Visit(e, fields) => panic!(
"\n[{}] expected {} to record {}\n[{}] but instead {}",
name, e, fields, name, what,
),
Expect::NewSpan(e) => panic!(
"\n[{}] expected {}\n[{}] but instead {}",
name, e, name, what
),
Expect::Nothing => panic!(
"\n[{}] expected nothing else to happen\n[{}] but {} instead",
name, name, what,
),
}
}
}
Loading

0 comments on commit 25ebc55

Please sign in to comment.