use proc_macro2::TokenStream;
pub fn transform_test_with_dir<TS>(input: TS) -> TS
where
TokenStream: From<TS>,
TS: From<TokenStream>,
{
let input = TokenStream::from(input);
TS::from(transform_test_with_dir_inner(input).unwrap_or_else(syn::Error::into_compile_error))
}
fn transform_test_with_dir_inner(input: TokenStream) -> Result<TokenStream, syn::parse::Error> {
use quote::quote;
use syn::{parse2, Ident, ItemFn};
let mut implfn: ItemFn = parse2(input)?;
let testname = implfn.sig.ident;
let testnamestr = testname.to_string();
let implname = Ident::new(&format!("{}_impl", &testnamestr), testname.span());
implfn.sig.ident = implname.clone();
let output = implfn.sig.output.clone();
Ok(quote! {
#[test]
fn #testname() #output {
let testdir =
::target_test_dir_support::get_base_test_dir()
.join(format!("{}-{}", module_path!().replace("::", "-"), #testnamestr));
match std::fs::create_dir(&testdir) {
Ok(()) => {}
Err(e) => {
panic!("Could not create test dir {:?}: {}", testdir.display(), e);
}
}
#implname (testdir)
}
#implfn
})
}
#[cfg(test)]
mod tests;