Skip to content

Commit bb81c7e

Browse files
hdsdavidbarsky
authored andcommitted
mock: document public API in collector module (#2389)
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
1 parent bcaeaa9 commit bb81c7e

File tree

3 files changed

+895
-73
lines changed

3 files changed

+895
-73
lines changed

tracing-mock/src/expect.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
use crate::{
24
event::ExpectedEvent,
35
field::{ExpectedField, ExpectedFields, ExpectedValue},
@@ -41,3 +43,51 @@ pub fn span() -> ExpectedSpan {
4143
..Default::default()
4244
}
4345
}
46+
47+
impl Expect {
48+
pub(crate) fn bad(&self, name: impl AsRef<str>, what: fmt::Arguments<'_>) {
49+
let name = name.as_ref();
50+
match self {
51+
Expect::Event(e) => panic!(
52+
"\n[{}] expected event {}\n[{}] but instead {}",
53+
name, e, name, what,
54+
),
55+
Expect::FollowsFrom { consequence, cause } => panic!(
56+
"\n[{}] expected consequence {} to follow cause {} but instead {}",
57+
name, consequence, cause, what,
58+
),
59+
Expect::Enter(e) => panic!(
60+
"\n[{}] expected to enter {}\n[{}] but instead {}",
61+
name, e, name, what,
62+
),
63+
Expect::Exit(e) => panic!(
64+
"\n[{}] expected to exit {}\n[{}] but instead {}",
65+
name, e, name, what,
66+
),
67+
Expect::CloneSpan(e) => {
68+
panic!(
69+
"\n[{}] expected to clone {}\n[{}] but instead {}",
70+
name, e, name, what,
71+
)
72+
}
73+
Expect::DropSpan(e) => {
74+
panic!(
75+
"\n[{}] expected to drop {}\n[{}] but instead {}",
76+
name, e, name, what,
77+
)
78+
}
79+
Expect::Visit(e, fields) => panic!(
80+
"\n[{}] expected {} to record {}\n[{}] but instead {}",
81+
name, e, fields, name, what,
82+
),
83+
Expect::NewSpan(e) => panic!(
84+
"\n[{}] expected {}\n[{}] but instead {}",
85+
name, e, name, what
86+
),
87+
Expect::Nothing => panic!(
88+
"\n[{}] expected nothing else to happen\n[{}] but {} instead",
89+
name, name, what,
90+
),
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)