Make TestAppContext and its dependencies available only in tests

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-03-01 17:01:52 +01:00
parent 0d6f6bf5bb
commit 83a3402235
7 changed files with 161 additions and 98 deletions

View file

@ -66,6 +66,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
// Pass to the test function the number of app contexts that it needs,
// based on its parameter list.
let mut cx_vars = proc_macro2::TokenStream::new();
let mut cx_teardowns = proc_macro2::TokenStream::new();
let mut inner_fn_args = proc_macro2::TokenStream::new();
for (ix, arg) in inner_fn.sig.inputs.iter().enumerate() {
if let FnArg::Typed(arg) = arg {
@ -104,6 +105,11 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
#first_entity_id,
);
));
cx_teardowns.extend(quote!(
#cx_varname.update(|cx| cx.remove_all_windows());
deterministic.run_until_parked();
#cx_varname.update(|_| {}); // flush effects
));
inner_fn_args.extend(quote!(&mut #cx_varname,));
}
_ => {
@ -145,7 +151,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
&mut |cx, foreground_platform, deterministic, seed, is_last_iteration| {
#cx_vars
cx.foreground().run(#inner_fn_name(#inner_fn_args));
cx.foreground().run_until_parked();
#cx_teardowns
}
);
}