use crate::common::*; macro_rules! test_env { { args: [$($arg:expr),* $(,)?], $(cwd: $cwd:expr,)? tree: { $($tree:tt)* } $(,)? } => { { let tempdir = temptree! { $($tree)* }; TestEnvBuilder::new() $(.current_dir(tempdir.path().join($cwd)))? .tempdir(tempdir) .arg("imdl") $(.arg($arg))* .build() } } } pub(crate) struct TestEnv { env: Env, #[allow(unused)] tempdir: TempDir, err: Capture, out: Capture, } impl TestEnv { pub(crate) fn new(tempdir: TempDir, env: Env, err: Capture, out: Capture) -> TestEnv { Self { tempdir, err, env, out, } } pub(crate) fn err(&self) -> String { self.err.string() } pub(crate) fn out(&self) -> String { self.out.string() } pub(crate) fn out_bytes(&self) -> Vec { self.out.bytes() } pub(crate) fn write(&self, path: impl AsRef, bytes: impl AsRef<[u8]>) { fs::write(self.env.resolve(path), bytes.as_ref()).unwrap(); } pub(crate) fn load_metainfo(&self, filename: impl AsRef) -> Metainfo { Metainfo::load(self.env.resolve(filename.as_ref())).unwrap() } } impl Deref for TestEnv { type Target = Env; fn deref(&self) -> &Self::Target { &self.env } } impl DerefMut for TestEnv { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.env } }