mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 05:00:16 +00:00
Add an 'on_failure' attribute to gpui tests
This lets us perform a finalization step when a randomized test fails.
This commit is contained in:
parent
5ecc9606af
commit
7b0a6c0dfa
2 changed files with 20 additions and 0 deletions
|
@ -45,6 +45,7 @@ pub fn run_test(
|
||||||
Arc<executor::Deterministic>,
|
Arc<executor::Deterministic>,
|
||||||
u64,
|
u64,
|
||||||
)),
|
)),
|
||||||
|
on_fail_fn: Option<fn()>,
|
||||||
fn_name: String,
|
fn_name: String,
|
||||||
) {
|
) {
|
||||||
// let _profiler = dhat::Profiler::new_heap();
|
// let _profiler = dhat::Profiler::new_heap();
|
||||||
|
@ -177,6 +178,7 @@ pub fn run_test(
|
||||||
if is_randomized {
|
if is_randomized {
|
||||||
eprintln!("failing seed: {}", atomic_seed.load(SeqCst));
|
eprintln!("failing seed: {}", atomic_seed.load(SeqCst));
|
||||||
}
|
}
|
||||||
|
on_fail_fn.map(|f| f());
|
||||||
panic::resume_unwind(error);
|
panic::resume_unwind(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
|
use proc_macro2::Ident;
|
||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use syn::{
|
use syn::{
|
||||||
|
@ -15,6 +16,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
let mut num_iterations = 1;
|
let mut num_iterations = 1;
|
||||||
let mut starting_seed = 0;
|
let mut starting_seed = 0;
|
||||||
let mut detect_nondeterminism = false;
|
let mut detect_nondeterminism = false;
|
||||||
|
let mut on_failure_fn_name = quote!(None);
|
||||||
|
|
||||||
for arg in args {
|
for arg in args {
|
||||||
match arg {
|
match arg {
|
||||||
|
@ -33,6 +35,20 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
Some("retries") => max_retries = parse_int(&meta.lit)?,
|
Some("retries") => max_retries = parse_int(&meta.lit)?,
|
||||||
Some("iterations") => num_iterations = parse_int(&meta.lit)?,
|
Some("iterations") => num_iterations = parse_int(&meta.lit)?,
|
||||||
Some("seed") => starting_seed = parse_int(&meta.lit)?,
|
Some("seed") => starting_seed = parse_int(&meta.lit)?,
|
||||||
|
Some("on_failure") => {
|
||||||
|
if let Lit::Str(name) = meta.lit {
|
||||||
|
let ident = Ident::new(&name.value(), name.span());
|
||||||
|
on_failure_fn_name = quote!(Some(#ident));
|
||||||
|
} else {
|
||||||
|
return Err(TokenStream::from(
|
||||||
|
syn::Error::new(
|
||||||
|
meta.lit.span(),
|
||||||
|
"on_failure argument must be a string",
|
||||||
|
)
|
||||||
|
.into_compile_error(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(TokenStream::from(
|
return Err(TokenStream::from(
|
||||||
syn::Error::new(meta.path.span(), "invalid argument")
|
syn::Error::new(meta.path.span(), "invalid argument")
|
||||||
|
@ -152,6 +168,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
cx.foreground().run(#inner_fn_name(#inner_fn_args));
|
cx.foreground().run(#inner_fn_name(#inner_fn_args));
|
||||||
#cx_teardowns
|
#cx_teardowns
|
||||||
},
|
},
|
||||||
|
#on_failure_fn_name,
|
||||||
stringify!(#outer_fn_name).to_string(),
|
stringify!(#outer_fn_name).to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -187,6 +204,7 @@ pub fn test(args: TokenStream, function: TokenStream) -> TokenStream {
|
||||||
#max_retries,
|
#max_retries,
|
||||||
#detect_nondeterminism,
|
#detect_nondeterminism,
|
||||||
&mut |cx, _, _, seed| #inner_fn_name(#inner_fn_args),
|
&mut |cx, _, _, seed| #inner_fn_name(#inner_fn_args),
|
||||||
|
#on_failure_fn_name,
|
||||||
stringify!(#outer_fn_name).to_string(),
|
stringify!(#outer_fn_name).to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue