Sometime, tests or fixtures need a fixture for its side effect (temporary directory...) and don't directly use the value itself.
#[fixture]
fn tmp_dir() -> std::io::Result<tempfile::TmpDir> {
tempfile::tempdir()
}
#[fixture]
fn tmp_path(tmp_dir: TmpDir) -> PathBuf {
tmp_dir.path().to_owned() // <- This will return a path to a non existant directory
// tmp_dir will delete the directory when it is drop.
}
We need to implement a way to prevent the source fixture being drop too soon.
Some ideas of api:
#[fixture(keep=tmp_dir)]
fn tmp_path(tmp_dir: TmpDir) -> PathBuf {
tmp_dir.path().to_owned()
}
#[fixture]
fn tmp_path(#[keep] tmp_dir: TmpDir) -> PathBuf {
tmp_dir.path().to_owned()
}
#[fixture]
fn tmp_path(ctx: Context, tmp_dir: TmpDir) -> PathBuf {
ctx.keep(tmp_dir);
tmp_dir.path().to_owned()
}
Sometime, tests or fixtures need a fixture for its side effect (temporary directory...) and don't directly use the value itself.
We need to implement a way to prevent the source fixture being drop too soon.
Some ideas of api: