-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test_with_retries macro to repeat GA tests. Some tests may fail…
… due to the randomness in the solutions
- Loading branch information
1 parent
3d22e53
commit 4a28c65
Showing
6 changed files
with
75 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "optirustic-macros" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
syn = { version = "*", features = ["full"] } | ||
quote = "*" | ||
proc-macro2 = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use proc_macro::TokenStream; | ||
|
||
use quote::quote; | ||
use syn::{parse_macro_input, ItemFn}; | ||
|
||
/// An attribute macro to repeat a test `n` times until the test passes. The test passes if it does | ||
/// not panic once, it fails if it panics `n` times. | ||
#[proc_macro_attribute] | ||
pub fn test_with_retries(attrs: TokenStream, item: TokenStream) -> TokenStream { | ||
let input_fn = parse_macro_input!(item as ItemFn); | ||
let fn_name = &input_fn.sig.ident; | ||
let tries = attrs | ||
.to_string() | ||
.parse::<u8>() | ||
.expect("Attr must be an int"); | ||
|
||
let expanded = quote! { | ||
#[test] | ||
fn #fn_name() { | ||
#input_fn | ||
for i in 1..=#tries { | ||
let result = std::panic::catch_unwind(|| { #fn_name() }); | ||
|
||
if result.is_ok() { | ||
return; | ||
} | ||
|
||
if i == #tries { | ||
std::panic::resume_unwind(result.unwrap_err()); | ||
} | ||
}; | ||
} | ||
}; | ||
expanded.into() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters