|
1 |
| -use tracing::collect::with_default; |
| 1 | +use tracing::{collect::with_default, error, error_span, field}; |
2 | 2 | use tracing_attributes::instrument;
|
3 | 3 | use tracing_mock::{collector, expect, span::NewSpan};
|
4 | 4 |
|
@@ -34,6 +34,9 @@ fn fn_string(s: String) {
|
34 | 34 | let _ = s;
|
35 | 35 | }
|
36 | 36 |
|
| 37 | +#[instrument(fields(keywords.impl.type.fn = _arg), skip(_arg))] |
| 38 | +fn fn_keyword_ident_in_field(_arg: &str) {} |
| 39 | + |
37 | 40 | #[derive(Debug)]
|
38 | 41 | struct HasField {
|
39 | 42 | my_field: &'static str,
|
@@ -146,6 +149,40 @@ fn string_field() {
|
146 | 149 | });
|
147 | 150 | }
|
148 | 151 |
|
| 152 | +#[test] |
| 153 | +fn keyword_ident_in_field_name() { |
| 154 | + let span = expect::span().with_fields( |
| 155 | + expect::field("keywords.impl.type.fn") |
| 156 | + .with_value(&"test") |
| 157 | + .only(), |
| 158 | + ); |
| 159 | + run_test(span, || fn_keyword_ident_in_field("test")); |
| 160 | +} |
| 161 | + |
| 162 | +#[test] |
| 163 | +fn keyword_ident_in_field_name_event_macro() { |
| 164 | + let (collector, handle) = collector::mock() |
| 165 | + .event(expect::event().with_fields(expect::field("crate").with_value(&"tracing"))) |
| 166 | + .only() |
| 167 | + .run_with_handle(); |
| 168 | + |
| 169 | + with_default(collector, || error!(crate = "tracing", "message")); |
| 170 | + handle.assert_finished(); |
| 171 | +} |
| 172 | + |
| 173 | +#[test] |
| 174 | +fn keyword_ident_in_field_name_span_macro() { |
| 175 | + #[derive(Debug)] |
| 176 | + struct Foo; |
| 177 | + |
| 178 | + let span = |
| 179 | + expect::span().with_fields(expect::field("self").with_value(&field::debug(Foo)).only()); |
| 180 | + run_test(span, || { |
| 181 | + let guard = error_span!("span", self = ?Foo).entered(); |
| 182 | + drop(guard); |
| 183 | + }); |
| 184 | +} |
| 185 | + |
149 | 186 | fn run_test<F: FnOnce() -> T, T>(span: NewSpan, fun: F) {
|
150 | 187 | let (collector, handle) = collector::mock()
|
151 | 188 | .new_span(span)
|
|
0 commit comments