#[cfg(test)]
pub mod tests {
use std::process::Command;
#[test]
fn test_basic_output() {
let output = Command::new("cargo")
.args([
"run",
"-p",
"test-mutex-async-lock",
"--example",
"basic_mutex_async_lock",
"--features",
"hotpath",
])
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
let stdout = String::from_utf8_lossy(&output.stdout);
let all_expected = [
"async-lock Mutex example completed!",
"mutexes",
"counter",
"Locks",
"Wait avg",
"Acq avg",
];
for expected in all_expected {
assert!(
stdout.contains(expected),
"Expected:\n{expected}\n\nGot:\n{stdout}",
);
}
}
#[test]
fn test_json_output() {
let output = Command::new("cargo")
.args([
"run",
"-p",
"test-mutex-async-lock",
"--example",
"basic_mutex_async_lock",
"--features",
"hotpath",
])
.env("HOTPATH_OUTPUT_FORMAT", "json")
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
let stdout = String::from_utf8_lossy(&output.stdout);
let all_expected = [
"\"mutexes\"",
"\"label\":\"counter\"",
"\"count\":6",
"\"wait_avg\"",
"\"acquire_avg\"",
"\"wait_percentiles\"",
"\"acquire_percentiles\"",
];
for expected in all_expected {
assert!(
stdout.contains(expected),
"Expected:\n{expected}\n\nGot:\n{stdout}",
);
}
}
}