process: Use a callback instead of real subprocess in tests

This commit is contained in:
Vicki Pfau 2024-04-01 20:58:29 -07:00
parent 1c825797be
commit c37bd22db0
2 changed files with 22 additions and 0 deletions

View file

@ -1,4 +1,6 @@
use anyhow::{anyhow, Result};
use std::cell::RefCell;
use std::ffi::OsStr;
use std::path::Path;
use std::rc::Rc;
use tempfile::{tempdir, TempDir};
@ -12,6 +14,7 @@ pub fn start() -> TestHandle {
assert!(lock.borrow().as_ref().is_none());
let test: Rc<Test> = Rc::new(Test {
base: tempdir().expect("Couldn't create test directory"),
process_cb: |_, _| Err(anyhow!("No current process_cb")),
});
*lock.borrow_mut() = Some(test.clone());
TestHandle { test }
@ -28,6 +31,7 @@ pub fn current() -> Rc<Test> {
pub struct Test {
base: TempDir,
pub process_cb: fn(&str, &[&OsStr]) -> Result<(i32, String)>,
}
pub struct TestHandle {