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

Feature to disable the async work #74

Merged
merged 5 commits into from Aug 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions serial_test/Cargo.toml
Expand Up @@ -19,19 +19,22 @@ document-features = { version = "0.2", optional = true }
log = { version = "0.4", optional = true }
futures = { version = "^0.3", default_features = false, features = [
"executor",
] }
], optional = true}
dashmap = { version = "5"}

[dev-dependencies]
itertools = "0.10"
tokio = { version = "^1.17", features = ["macros", "rt"] }

[features]
default = ["logging"]
default = ["logging", "async"]

## Switches on debug logging (and requires the `log` package)
logging = ["log"]

## Enables async features
async = ["futures"]

## The file_locks feature unlocks the `file_serial`/`file_parallel` macros
file_locks = ["fslock"]

Expand Down
33 changes: 17 additions & 16 deletions serial_test/src/lib.rs
Expand Up @@ -64,26 +64,27 @@ mod parallel_file_lock;
#[cfg(feature = "file_locks")]
mod serial_file_lock;

pub use parallel_code_lock::{
local_async_parallel_core, local_async_parallel_core_with_return, local_parallel_core,
local_parallel_core_with_return,
};
pub use serial_code_lock::{
local_async_serial_core, local_async_serial_core_with_return, local_serial_core,
local_serial_core_with_return,
};
#[cfg(feature = "async")]
pub use parallel_code_lock::{local_async_parallel_core, local_async_parallel_core_with_return};

pub use parallel_code_lock::{local_parallel_core, local_parallel_core_with_return};

#[cfg(feature = "async")]
pub use serial_code_lock::{local_async_serial_core, local_async_serial_core_with_return};

pub use serial_code_lock::{local_serial_core, local_serial_core_with_return};

#[cfg(all(feature = "file_locks", feature = "async"))]
pub use serial_file_lock::{fs_async_serial_core, fs_async_serial_core_with_return};

#[cfg(feature = "file_locks")]
pub use serial_file_lock::{
fs_async_serial_core, fs_async_serial_core_with_return, fs_serial_core,
fs_serial_core_with_return,
};
pub use serial_file_lock::{fs_serial_core, fs_serial_core_with_return};

#[cfg(all(feature = "file_locks", feature = "async"))]
pub use parallel_file_lock::{fs_async_parallel_core, fs_async_parallel_core_with_return};

#[cfg(feature = "file_locks")]
pub use parallel_file_lock::{
fs_async_parallel_core, fs_async_parallel_core_with_return, fs_parallel_core,
fs_parallel_core_with_return,
};
pub use parallel_file_lock::{fs_parallel_core, fs_parallel_core_with_return};

// Re-export #[serial/parallel].
pub use serial_test_derive::{parallel, serial};
Expand Down
13 changes: 9 additions & 4 deletions serial_test/src/parallel_code_lock.rs
@@ -1,6 +1,7 @@
#![allow(clippy::await_holding_lock)]

use crate::code_lock::{check_new_key, LOCKS};
#[cfg(feature = "async")]
use futures::FutureExt;
use std::{panic, time::Duration};

Expand Down Expand Up @@ -40,6 +41,7 @@ pub fn local_parallel_core(name: &str, max_wait: Option<Duration>, function: fn(
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn local_async_parallel_core_with_return<E>(
name: &str,
max_wait: Option<Duration>,
Expand All @@ -60,6 +62,7 @@ pub async fn local_async_parallel_core_with_return<E>(
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn local_async_parallel_core(
name: &str,
max_wait: Option<Duration>,
Expand All @@ -78,10 +81,10 @@ pub async fn local_async_parallel_core(

#[cfg(test)]
mod tests {
use crate::{
code_lock::LOCKS, local_async_parallel_core, local_async_parallel_core_with_return,
local_parallel_core, local_parallel_core_with_return,
};
#[cfg(feature = "async")]
use crate::{local_async_parallel_core, local_async_parallel_core_with_return};

use crate::{code_lock::LOCKS, local_parallel_core, local_parallel_core_with_return};
use std::{io::Error, panic};

#[test]
Expand Down Expand Up @@ -122,6 +125,7 @@ mod tests {
}

#[tokio::test]
#[cfg(feature = "async")]
async fn unlock_on_assert_async_without_return() {
async fn demo_assert() {
assert!(false);
Expand All @@ -146,6 +150,7 @@ mod tests {
}

#[tokio::test]
#[cfg(feature = "async")]
async fn unlock_on_assert_async_with_return() {
async fn demo_assert() -> Result<(), Error> {
assert!(false);
Expand Down
11 changes: 9 additions & 2 deletions serial_test/src/parallel_file_lock.rs
@@ -1,5 +1,6 @@
use std::{panic, time::Duration};

#[cfg(feature = "async")]
use futures::FutureExt;

use crate::file_lock::make_lock_for_name_and_path;
Expand Down Expand Up @@ -40,6 +41,7 @@ pub fn fs_parallel_core_with_return<E>(
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn fs_async_parallel_core_with_return<E>(
name: &str,
_max_wait: Option<Duration>,
Expand All @@ -58,6 +60,7 @@ pub async fn fs_async_parallel_core_with_return<E>(
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn fs_async_parallel_core(
name: &str,
_max_wait: Option<Duration>,
Expand All @@ -74,10 +77,12 @@ pub async fn fs_async_parallel_core(

#[cfg(test)]
mod tests {
#[cfg(feature = "async")]
use crate::{fs_async_parallel_core, fs_async_parallel_core_with_return};

use crate::{
file_lock::{path_for_name, Lock},
fs_async_parallel_core, fs_async_parallel_core_with_return, fs_parallel_core,
fs_parallel_core_with_return,
fs_parallel_core, fs_parallel_core_with_return,
};
use std::{io::Error, panic};

Expand Down Expand Up @@ -120,6 +125,7 @@ mod tests {
}

#[tokio::test]
#[cfg(feature = "async")]
async fn unlock_on_assert_async_without_return() {
let lock_path = path_for_name("unlock_on_assert_async_without_return");
async fn demo_assert() {
Expand All @@ -145,6 +151,7 @@ mod tests {
}

#[tokio::test]
#[cfg(feature = "async")]
async fn unlock_on_assert_async_with_return() {
let lock_path = path_for_name("unlock_on_assert_async_with_return");

Expand Down
2 changes: 2 additions & 0 deletions serial_test/src/serial_code_lock.rs
Expand Up @@ -28,6 +28,7 @@ pub fn local_serial_core(name: &str, max_wait: Option<Duration>, function: fn())
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn local_async_serial_core_with_return<E>(
name: &str,
max_wait: Option<Duration>,
Expand All @@ -42,6 +43,7 @@ pub async fn local_async_serial_core_with_return<E>(
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn local_async_serial_core(
name: &str,
max_wait: Option<Duration>,
Expand Down
2 changes: 2 additions & 0 deletions serial_test/src/serial_file_lock.rs
Expand Up @@ -25,6 +25,7 @@ pub fn fs_serial_core_with_return<E>(
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn fs_async_serial_core_with_return<E>(
name: &str,
_max_wait: Option<Duration>,
Expand All @@ -39,6 +40,7 @@ pub async fn fs_async_serial_core_with_return<E>(
}

#[doc(hidden)]
#[cfg(feature = "async")]
pub async fn fs_async_serial_core(
name: &str,
_max_wait: Option<Duration>,
Expand Down
6 changes: 6 additions & 0 deletions serial_test_derive/src/lib.rs
Expand Up @@ -380,6 +380,9 @@ where
{
let ast: syn::ItemFn = syn::parse2(input).unwrap();
let asyncness = ast.sig.asyncness;
if asyncness.is_some() && cfg!(not(feature = "async")) {
panic!("async testing attempted with async feature disabled in serial_test!");
}
let name = ast.sig.ident;
let return_type = match ast.sig.output {
syn::ReturnType::Default => None,
Expand Down Expand Up @@ -577,6 +580,7 @@ mod tests {
}

#[test]
#[cfg(feature = "async")]
fn test_serial_async() {
let attrs = proc_macro2::TokenStream::new();
let input = quote! {
Expand All @@ -592,6 +596,7 @@ mod tests {
}

#[test]
#[cfg(feature = "async")]
fn test_serial_async_return() {
let attrs = proc_macro2::TokenStream::new();
let input = quote! {
Expand All @@ -609,6 +614,7 @@ mod tests {
// 1.54 needed for https://github.com/rust-lang/rust/commit/9daf546b77dbeab7754a80d7336cd8d00c6746e4 change in note message
#[rustversion::since(1.54)]
#[test]
#[cfg(feature = "async")]
fn test_serial_async_before_wrapper() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/broken/test_serial_async_before_wrapper.rs");
Expand Down