2020-01-14 09:52:27 +01:00
|
|
|
use crate::common::*;
|
|
|
|
|
2020-03-06 06:44:20 +01:00
|
|
|
macro_rules! test_env {
|
|
|
|
{
|
|
|
|
args: [$($arg:expr),* $(,)?],
|
2020-03-08 04:23:20 +01:00
|
|
|
$(cwd: $cwd:expr,)?
|
2020-03-06 06:44:20 +01:00
|
|
|
tree: {
|
|
|
|
$($tree:tt)*
|
|
|
|
} $(,)?
|
|
|
|
} => {
|
|
|
|
{
|
|
|
|
let tempdir = temptree! { $($tree)* };
|
|
|
|
|
|
|
|
TestEnvBuilder::new()
|
2020-03-08 04:23:20 +01:00
|
|
|
$(.current_dir(tempdir.path().join($cwd)))?
|
2020-03-06 06:44:20 +01:00
|
|
|
.tempdir(tempdir)
|
|
|
|
.arg("imdl")
|
|
|
|
$(.arg($arg))*
|
|
|
|
.build()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 09:52:27 +01:00
|
|
|
pub(crate) struct TestEnv {
|
|
|
|
env: Env,
|
2020-03-08 04:23:20 +01:00
|
|
|
#[allow(unused)]
|
|
|
|
tempdir: TempDir,
|
2020-01-14 09:52:27 +01:00
|
|
|
err: Capture,
|
|
|
|
out: Capture,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestEnv {
|
2020-03-08 04:23:20 +01:00
|
|
|
pub(crate) fn new(tempdir: TempDir, env: Env, err: Capture, out: Capture) -> TestEnv {
|
|
|
|
Self {
|
|
|
|
tempdir,
|
|
|
|
err,
|
|
|
|
env,
|
|
|
|
out,
|
|
|
|
}
|
2020-01-14 09:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn err(&self) -> String {
|
|
|
|
self.err.string()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn out(&self) -> String {
|
|
|
|
self.out.string()
|
|
|
|
}
|
2020-02-05 06:29:53 +01:00
|
|
|
|
|
|
|
pub(crate) fn out_bytes(&self) -> Vec<u8> {
|
|
|
|
self.out.bytes()
|
|
|
|
}
|
2020-02-06 03:32:09 +01:00
|
|
|
|
2020-03-06 06:44:20 +01:00
|
|
|
pub(crate) fn write(&self, path: impl AsRef<Path>, bytes: impl AsRef<[u8]>) {
|
2020-02-06 03:32:09 +01:00
|
|
|
fs::write(self.env.resolve(path), bytes.as_ref()).unwrap();
|
|
|
|
}
|
2020-02-14 09:12:49 +01:00
|
|
|
|
2020-02-14 11:16:19 +01:00
|
|
|
pub(crate) fn load_metainfo(&self, filename: impl AsRef<Path>) -> Metainfo {
|
2020-02-14 09:12:49 +01:00
|
|
|
Metainfo::load(self.env.resolve(filename.as_ref())).unwrap()
|
|
|
|
}
|
2020-01-14 09:52:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|