Skip to content

Commit

Permalink
Allow attributes after #[timeout]
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored and becheran committed Jun 18, 2024
1 parent 6ae723d commit 53d1aa1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ntest_timeout/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ pub fn timeout(attr: TokenStream, item: TokenStream) -> TokenStream {
let sig = &input.sig;
let output = &sig.output;
let body = &input.block;
let attrs = &input.attrs;
check_other_attributes(&input);
let result = quote! {
#(#attrs)*
#vis #sig {
fn ntest_callback() #output
#body
Expand Down
46 changes: 46 additions & 0 deletions ntest_timeout/tests/timeout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use ntest_timeout::timeout;
use std::{thread, time};

#[test]
#[timeout(100)]
fn no_timeout_1() {
let fifty_millis = time::Duration::from_millis(50);
thread::sleep(fifty_millis);
}

#[timeout(100)]
#[test]
fn no_timeout_2() {
let fifty_millis = time::Duration::from_millis(50);
thread::sleep(fifty_millis);
}

#[test]
#[timeout(10)]
#[should_panic]
fn timeout_1() {
loop {}
}

#[timeout(10)]
#[should_panic]
#[test]
fn timeout_2() {
loop {}
}

#[test]
#[timeout(100)]
fn timeout_with_result_1() -> Result<(), String> {
let ten_millis = time::Duration::from_millis(10);
thread::sleep(ten_millis);
Ok(())
}

#[timeout(100)]
#[test]
fn timeout_with_result_2() -> Result<(), String> {
let ten_millis = time::Duration::from_millis(10);
thread::sleep(ten_millis);
Ok(())
}

0 comments on commit 53d1aa1

Please sign in to comment.