diff --git a/tracing-subscriber/src/fmt/format/json.rs b/tracing-subscriber/src/fmt/format/json.rs index bd47214da3..425634fe80 100644 --- a/tracing-subscriber/src/fmt/format/json.rs +++ b/tracing-subscriber/src/fmt/format/json.rs @@ -529,11 +529,15 @@ mod test { .join("src") .join("fmt") .join("format") - .join("json.rs"); + .join("json.rs") + .to_str() + .expect("path must be valid unicode") + // escape windows backslashes + .replace('\\', "\\\\"); let expected = &format!("{}{}{}", "{\"timestamp\":\"fake time\",\"level\":\"INFO\",\"span\":{\"answer\":42,\"name\":\"json_span\",\"number\":3},\"spans\":[{\"answer\":42,\"name\":\"json_span\",\"number\":3}],\"target\":\"tracing_subscriber::fmt::format::json::test\",\"filename\":\"", - ¤t_path.to_str().unwrap(), + current_path, "\",\"fields\":{\"message\":\"some json test\"}}\n"); let collector = collector() .flatten_event(false) diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index 63d47757c7..204df05fab 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -1856,9 +1856,8 @@ pub(super) mod test { assert!(f.contains(FmtSpan::CLOSE)); } - /// Returns the test's module path, pre-processed for use in a regular - /// expression by escaping `\` characters.. - fn current_path() -> &str { + /// Returns the test's module path. + fn current_path() -> String { Path::new("tracing-subscriber") .join("src") .join("fmt") @@ -1866,5 +1865,6 @@ pub(super) mod test { .join("mod.rs") .to_str() .expect("path must not contain invalid unicode") + .to_owned() } }