#![allow(dead_code)]
use chisel::{Chisel, Options};
use tempfile::NamedTempFile;
pub enum Backing {
File(NamedTempFile),
Memory,
}
impl Backing {
pub fn fresh_file() -> Backing {
Backing::File(NamedTempFile::new().expect("tempfile"))
}
}
pub fn open_chisel(b: &Backing) -> Chisel {
open_chisel_with(b, Options::default())
}
pub fn open_chisel_with(b: &Backing, opts: Options) -> Chisel {
match b {
Backing::File(f) => Chisel::open(f.path(), opts).unwrap(),
Backing::Memory => Chisel::open_in_memory_with_options(opts).unwrap(),
}
}
#[macro_export]
macro_rules! dual_backing_test {
($name:ident, $body:ident) => {
pastey::paste! {
#[test]
fn [<$name _file>]() {
let b = $crate::common::Backing::fresh_file();
$body(&b);
}
#[test]
fn [<$name _memory>]() {
let b = $crate::common::Backing::Memory;
$body(&b);
}
}
};
}