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

test: fix duplicated test runs from test_case and stuck::test #53

Merged
merged 1 commit into from
Apr 19, 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
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ more-asserts = "0.2.2"
[dev-dependencies]
pretty_assertions = "1.2.0"
scopeguard = "1.2.0"
test-case = "2.0.2"
test-case = "3.3.1"

[patch.crates-io]
test-case = { git = "https://github.com/kezhuw/test-case.git", branch = "test-proc-macros-cooperation" }

[workspace]
members = ["macros"]
2 changes: 1 addition & 1 deletion macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ categories = ["Concurrency"]
proc-macro = true

[dependencies]
syn = {version ="1.0", features=["full"]}
syn = {version ="1.0", features=["full", "extra-traits"]}
quote = "1.0"
proc-macro2 = "1.0.37"
6 changes: 4 additions & 2 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ extern crate proc_macro;
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::quote;
use syn::parse_quote;

#[derive(Default)]
struct Configuration {
Expand Down Expand Up @@ -91,7 +92,8 @@ fn generate(is_test: bool, attr: TokenStream, item: TokenStream) -> TokenStream
return TokenStream::from(err.into_compile_error());
}

let header = if is_test {
let test_attr: syn::Attribute = parse_quote! { #[::core::prelude::v1::test] };
let header = if is_test && !attrs.iter().any(|attr| *attr == test_attr) {
quote! {
#[::core::prelude::v1::test]
}
Expand All @@ -103,8 +105,8 @@ fn generate(is_test: bool, attr: TokenStream, item: TokenStream) -> TokenStream
let parallelism = config.parallelism.unwrap_or(0);
let parallelism_default: usize = if is_test { 2 } else { 0 };
let result = quote! {
#header
#(#attrs)*
#header
#vis fn #name() #ret {
fn entry(#inputs) #ret {
#body
Expand Down
Loading