Skip to content

Commit

Permalink
test: add tests for the index API
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <[email protected]>
  • Loading branch information
Rustin170506 committed Nov 30, 2023
1 parent 395b684 commit f3f558e
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions tracing/tests/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ fn event_macros_dont_infinite_loop() {
}

fn enabled(&self, meta: &Metadata<'_>) -> bool {
assert!(meta.fields().iter().any(|f| f.name() == "foo"));
assert_eq!(
meta.fields()
.iter()
.find(|f| f.name() == "foo")
.map(|f| f.index()),
Some(0)
);
assert_eq!(
meta.fields()
.iter()
.find(|f| f.name() == "bar")
.map(|f| f.index()),
Some(1)
);
tracing::event!(Level::TRACE, bar = false);
true
}
Expand All @@ -41,7 +54,24 @@ fn event_macros_dont_infinite_loop() {
fn record_follows_from(&self, _: &Id, _: &Id) {}

fn event(&self, event: &Event<'_>) {
assert!(event.metadata().fields().iter().any(|f| f.name() == "foo"));
assert_eq!(
event
.metadata()
.fields()
.iter()
.find(|f| f.name() == "foo")
.map(|f| f.index()),
Some(0)
);
assert_eq!(
event
.metadata()
.fields()
.iter()
.find(|f| f.name() == "bar")
.map(|f| f.index()),
Some(1)
);
tracing::event!(Level::TRACE, baz = false);
}

Expand All @@ -55,7 +85,7 @@ fn event_macros_dont_infinite_loop() {
}

with_default(TestCollector, || {
tracing::event!(Level::TRACE, foo = false);
tracing::event!(Level::TRACE, foo = false, bar = false);
})
}

Expand Down

0 comments on commit f3f558e

Please sign in to comment.