child .stdin .as_ref() .unwrap() .write_all(&self.stdin) .unwrap(); let output = child.wait_with_output().unwrap(); let stdout = str::from_utf8(&output.stdout).unwrap(); let stderr = str::from_utf8(&output.stderr).unwrap(); if output.status.code() != Some(self.expected_exit_code) { panic!( "Test failed: {}\nstdout:\n{}\nstderr:\n{}", output.status, stdout, stderr ); } self.expected_stderr.assert_match(stderr); self.expected_stdout.assert_match(stdout); (self.tempdir, stdout.into()) } pub(crate) fn run_and_extract_file(self, path: impl AsRef) -> String { let tempdir = self.run().0; fs::read_to_string(tempdir.path().join(path)).unwrap() } pub(crate) fn run_and_extract_stdout(self) -> String { self.run().1 } pub(crate) fn run_and_deserialize_output(self) -> T { let stdout = self.stdout_regex(".*").run_and_extract_stdout(); serde_json::from_str(&stdout) .unwrap_or_else(|err| panic!("Failed to deserialize JSON: {err}\n{stdout}"))