Skip to content

Commit 8f2592e

Browse files
hdsdavidbarsky
andcommitted
mock: document public APIs in the field module (#2443)
This change adds documentation to the tracing-mock `field` module and all the public APIs within it. This includes doctests on all the methods which serve as examples. Additionally, the `field::msg` function (which constructs a field with name "message" and the provided value) was moved to `expect::message`. This is part of a unification of all expectation constructors inside the `expect` module. Refs: #539 Co-authored-by: David Barsky <[email protected]>
1 parent e868509 commit 8f2592e

File tree

6 files changed

+382
-25
lines changed

6 files changed

+382
-25
lines changed

tracing-mock/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn yak_shaving() {
7878
}
7979

8080
let (subscriber, handle) = subscriber::mock()
81-
.event(expect::event().with_fields(field::msg("preparing to shave yaks")))
81+
.event(expect::event().with_fields(expect::message("preparing to shave yaks")))
8282
.only()
8383
.run_with_handle();
8484

@@ -102,7 +102,7 @@ Below is a slightly more complex example. `tracing-mock` asserts that, in order:
102102

103103
```rust
104104
use tracing::subscriber::with_default;
105-
use tracing_mock::{subscriber, expect, field};
105+
use tracing_mock::{subscriber, expect};
106106

107107
#[tracing::instrument]
108108
fn yak_shaving(number_of_yaks: u32) {
@@ -128,15 +128,15 @@ let (subscriber, handle) = subscriber::mock()
128128
expect::event().with_fields(
129129
expect::field("number_of_yaks")
130130
.with_value(&yak_count)
131-
.and(field::msg("preparing to shave yaks"))
131+
.and(expect::message("preparing to shave yaks"))
132132
.only(),
133133
),
134134
)
135135
.event(
136136
expect::event().with_fields(
137137
expect::field("all_yaks_shaved")
138138
.with_value(&true)
139-
.and(field::msg("yak shaving completed."))
139+
.and(expect::message("yak shaving completed."))
140140
.only(),
141141
),
142142
)
@@ -173,4 +173,4 @@ This project is licensed under the [MIT license][mit-url].
173173

174174
Unless you explicitly state otherwise, any contribution intentionally submitted
175175
for inclusion in Tracing by you, shall be licensed as MIT, without any additional
176-
terms or conditions.
176+
terms or conditions.

tracing-mock/src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct ExpectedEvent {
4848
}
4949

5050
pub fn msg(message: impl fmt::Display) -> ExpectedEvent {
51-
expect::event().with_fields(field::msg(message))
51+
expect::event().with_fields(expect::message(message))
5252
}
5353

5454
impl ExpectedEvent {

tracing-mock/src/expect.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ where
3838
}
3939
}
4040

41+
pub fn message(message: impl fmt::Display) -> ExpectedField {
42+
ExpectedField {
43+
name: "message".to_string(),
44+
value: ExpectedValue::Debug(message.to_string()),
45+
}
46+
}
47+
4148
pub fn span() -> ExpectedSpan {
4249
ExpectedSpan {
4350
..Default::default()

0 commit comments

Comments
 (0)