Skip to content

Commit

Permalink
fix json test on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Jan 13, 2022
1 parent 6535633 commit 218afdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions tracing-subscriber/src/fmt/format/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\":\"",
&current_path.to_str().unwrap(),
current_path,
"\",\"fields\":{\"message\":\"some json test\"}}\n");
let collector = collector()
.flatten_event(false)
Expand Down
6 changes: 3 additions & 3 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1856,15 +1856,15 @@ 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")
.join("format")
.join("mod.rs")
.to_str()
.expect("path must not contain invalid unicode")
.to_owned()
}
}

0 comments on commit 218afdd

Please sign in to comment.