Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor test_logger_filters's subprocess machinery into a separate…
… function
  • Loading branch information
koute committed Oct 21, 2021
commit 5ae74c8248c2058944a459f699c4e3aef05f7321
31 changes: 21 additions & 10 deletions client/tracing/src/logging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,28 @@ mod tests {
let _ = LoggerBuilder::new(directives).init().unwrap();
}

fn run_test_in_another_process(
test_name: &str,
test_body: impl FnOnce(),
) -> Option<std::process::Output> {
if env::var("RUN_FORKED_TEST").is_ok() {
test_body();
None
} else {
let output = Command::new(env::current_exe().unwrap())
.arg(test_name)
.env("RUN_FORKED_TEST", "1")
.output()
.unwrap();

assert!(output.status.success());
Some(output)
}
}

#[test]
fn test_logger_filters() {
if env::var("RUN_TEST_LOGGER_FILTERS").is_ok() {
run_test_in_another_process("test_logger_filters", || {
let test_directives =
"afg=debug,sync=trace,client=warn,telemetry,something-with-dash=error";
init_logger(&test_directives);
Expand Down Expand Up @@ -336,15 +355,7 @@ mod tests {
assert!(test_filter("telemetry", Level::TRACE));
assert!(test_filter("something-with-dash", Level::ERROR));
});
} else {
let status = Command::new(env::current_exe().unwrap())
.arg("test_logger_filters")
.env("RUN_TEST_LOGGER_FILTERS", "1")
.output()
.unwrap()
.status;
assert!(status.success());
}
});
}

/// This test ensures that using dash (`-`) in the target name in logs and directives actually
Expand Down