Skip to content

Commit

Permalink
Fix wrong type in escape
Browse files Browse the repository at this point in the history
Signed-off-by: Heinz N. Gies <heinz@licenser.net>
  • Loading branch information
Licenser committed Jul 22, 2022
1 parent 746d370 commit a40be1f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
29 changes: 20 additions & 9 deletions serial_test_derive/src/lib.rs
Expand Up @@ -311,8 +311,12 @@ fn local_serial_core(
input: proc_macro2::TokenStream,
) -> proc_macro2::TokenStream {
let config = get_core_key(attr);
let args: Vec<Box<dyn ToTokens>> =
vec![Box::new(config.name), Box::new(QuoteOption(config.timeout))];
let timeout = if let Some(t) = config.timeout {
quote! { ::std::option::Option::Some(::std::time::Duration::from_millis(#t)) }
} else {
quote! { ::std::option::Option::None }
};
let args: Vec<Box<dyn ToTokens>> = vec![Box::new(config.name), Box::new(timeout)];
serial_setup(input, args, "local")
}

Expand All @@ -321,19 +325,26 @@ fn local_parallel_core(
input: proc_macro2::TokenStream,
) -> proc_macro2::TokenStream {
let config = get_core_key(attr);
let args: Vec<Box<dyn ToTokens>> =
vec![Box::new(config.name), Box::new(QuoteOption(config.timeout))];
let timeout = if let Some(t) = config.timeout {
quote! { Some(::std::time::Duration::from_millis(#t)) }
} else {
quote! { None }
};
let args: Vec<Box<dyn ToTokens>> = vec![Box::new(config.name), Box::new(timeout)];
parallel_setup(input, args, "local")
}

fn fs_args(attr: proc_macro2::TokenStream) -> Vec<Box<dyn ToTokens>> {
let config = get_core_key(attr);
if config.timeout.is_some() {
let timeout = if let Some(_t) = config.timeout {
panic!("Timeout is not supported for file_serial");
}
// quote! { ::std::option::Option::Some(::std::time::Duration::from_millis(#t)) }
} else {
quote! { ::std::option::Option::None }
};
vec![
Box::new(config.name),
Box::new(QuoteOption(config.timeout)),
Box::new(timeout),
if let Some(path) = config.path {
Box::new(QuoteOption(Some(path)))
} else {
Expand Down Expand Up @@ -512,7 +523,7 @@ mod tests {
let compare = quote! {
#[test]
fn foo () {
serial_test::local_serial_core("", :: std :: option :: Option :: Some (42u64), || {} );
serial_test::local_serial_core("", :: std :: option :: Option :: Some (::std::time::Duration::from_millis(42u64)), || {} );
}
};
assert_eq!(format!("{}", compare), format!("{}", stream));
Expand All @@ -538,7 +549,7 @@ mod tests {
let compare = quote! {
#[test]
fn foo () {
serial_test::local_serial_core("foo", :: std :: option :: Option :: Some (42u64), || {} );
serial_test::local_serial_core("foo", :: std :: option :: Option :: Some (::std::time::Duration::from_millis(42u64)), || {} );
}
};
assert_eq!(format!("{}", compare), format!("{}", stream));
Expand Down
8 changes: 8 additions & 0 deletions serial_test_test/src/lib.rs
Expand Up @@ -106,6 +106,14 @@ mod tests {
#[cfg(feature = "file_locks")]
use serial_test::{file_parallel, file_serial};

#[test]
#[serial(timeout_key, timeout_ms = 30000)]
fn demo_timeout_with_key() {}

#[test]
#[serial(timeout_ms = 30000)]
fn demo_timeout() {}

#[test]
#[serial]
fn test_serial_no_arg() {
Expand Down

0 comments on commit a40be1f

Please sign in to comment.