Hi,
Chapter 07's tests will intermittently fail because of how cargo test runs tests concurrently by default. Specifically, when unreadable_dir creates tests/inputs/cant-touch-this, other tests will unintentionally detect that dir and include it in its output.
As a workaround, the run function was modified to filter that directory out:
fn run(args: &[&str], expected_file: &str) -> Result<()> {
let file = format_file_name(expected_file);
let contents = fs::read_to_string(file.as_ref())?;
let mut expected: Vec<&str> =
contents.split('\n').filter(|s| !s.is_empty()).collect();
expected.sort();
let cmd = Command::cargo_bin(PRG)?.args(args).assert().success();
let out = cmd.get_output();
let stdout = String::from_utf8(out.stdout.clone())?;
// unreadable_dir creates tests/inputs/cant-touch-this while tests run in
// parallel; ignore it so tests scanning tests/inputs don't race with it.
let mut lines: Vec<&str> = stdout
.split('\n')
.filter(|s| !s.is_empty() && !s.contains("cant-touch-this"))
.collect();
lines.sort();
assert_eq!(lines, expected);
Ok(())
}
Hi,
Chapter 07's tests will intermittently fail because of how
cargo testruns tests concurrently by default. Specifically, whenunreadable_dircreates tests/inputs/cant-touch-this, other tests will unintentionally detect that dir and include it in its output.As a workaround, the
runfunction was modified to filter that directory out: