Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow attributes after #[timeout] #28

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
Loading