I'm running the following function in a test:
fn spellcheck(dir: &Path) -> Option<String> {
let pdf2text_status = Command::new("pdftotext")
.current_dir(dir)
.arg("Schüler_Name.pdf")
.status()
.unwrap();
assert!(pdf2text_status.success());
let mut txt = OpenOptions::new()
.read(true)
.open(&dir.join("Schüler_Name.txt"))
.unwrap();
let mut aspell = Command::new("aspell")
.arg("--lang=de")
.arg(&format!("--add-extra-dicts={}", ASPELL_PWS))
.arg("list")
.stdin(Stdio::piped())
.stderr(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
let aspell_stdin = aspell.stdin.as_mut().unwrap();
io::copy(&mut txt, aspell_stdin).unwrap();
let output = aspell.wait_with_output().unwrap();
assert!(output.status.success());
assert_eq!(String::from_utf8(output.stderr).unwrap(), String::new());
if !output.stdout.is_empty() {
let s = String::from_utf8_lossy(&output.stdout); // problem here
Some(s.to_string())
} else {
None
}
}
Basically, I'm capturing the output of aspell
, after arranging things properly (producing the text file, feeding it into aspell via stdin).
The problematic line has a comment. I tried using String::from_utf8
which panicked, so I settled on String::from_utf8_lossy
, seeing I certainly don't need the non-utf8 chars.... but that failed with
test correct_pdf_names_when_error ... ok
test render_all_demo ... ok
test tilde_in_dir ... ok
memory allocation of 139225504 bytes failed
error: test failed, to rerun pass--test full_runs
Caused by:
process didn't exit successfully:D:\a\zrs\zrs\target\debug\deps\full_runs-57c67b03501e848c.exe --nocapture
(exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
Error: Process completed with exit code 127.
Did I do something wrong? Seems to me this shouldn't really happen without unsafe, right?
Relatedly: What can I do about this, I do need the output from aspell? Note: On linux the test runs appropriately (using String::from_utf8
).