diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs index 792af8b..02e70ea 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -9,7 +9,7 @@ use std::{ sync::OnceLock, }; -use anyhow::{bail, Context as _, Result}; +use anyhow::Context as _; pub(crate) use build_context::TARGET; use easy_ext::ext; use fs_err as fs; @@ -80,7 +80,7 @@ impl Command { } _ => {} } - let (_test_project, cur_dir) = test_project(test_model).unwrap(); + let (_test_project, cur_dir) = test_project(test_model); let output = self.current_dir(cur_dir).output().context("could not execute process").unwrap(); AssertOutput(Some(AssertOutputInner { @@ -239,8 +239,9 @@ impl AssertOutput { } } -fn test_project(model: &str) -> Result<(tempfile::TempDir, PathBuf)> { - let tmpdir = tempfile::tempdir()?; +#[track_caller] +fn test_project(model: &str) -> (tempfile::TempDir, PathBuf) { + let tmpdir = tempfile::tempdir().unwrap(); let tmpdir_path = tmpdir.path(); let model_path; @@ -255,30 +256,32 @@ fn test_project(model: &str) -> Result<(tempfile::TempDir, PathBuf)> { workspace_root = tmpdir_path.to_path_buf(); } - for (file_name, from) in git_ls_files(&model_path, &[])? { + for (file_name, from) in git_ls_files(&model_path, &[]) { let to = &tmpdir_path.join(file_name); if !to.parent().unwrap().is_dir() { - fs::create_dir_all(to.parent().unwrap())?; + fs::create_dir_all(to.parent().unwrap()).unwrap(); } - fs::copy(from, to)?; + fs::copy(from, to).unwrap(); } - Ok((tmpdir, workspace_root)) + (tmpdir, workspace_root) } -fn git_ls_files(dir: &Path, filters: &[&str]) -> Result> { +#[track_caller] +fn git_ls_files(dir: &Path, filters: &[&str]) -> Vec<(String, PathBuf)> { let mut cmd = Command::new("git"); cmd.arg("ls-files").args(filters).current_dir(dir); - let output = cmd.output().with_context(|| format!("could not execute process `{cmd:?}`"))?; - if !output.status.success() { - bail!( + let output = + cmd.output().unwrap_or_else(|e| panic!("could not execute process `{cmd:?}`: {e}")); + assert!( + output.status.success(), "process didn't exit successfully: `{cmd:?}`:\n\nSTDOUT:\n{0}\n{1}\n{0}\n\nSTDERR:\n{0}\n{2}\n{0}\n", "-".repeat(60), String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr), ); - } - Ok(str::from_utf8(&output.stdout)? + str::from_utf8(&output.stdout) + .unwrap() .lines() .map(str::trim) .filter_map(|f| { @@ -291,5 +294,5 @@ fn git_ls_files(dir: &Path, filters: &[&str]) -> Result> } Some((f.to_owned(), p)) }) - .collect()) + .collect() }