From 47f278b17ab0b45de94ffcba30e48b3dbb9f7a2a Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 19 Oct 2021 16:13:13 +0100 Subject: [PATCH] fix test macro in presence of other imports named test (#399) --- .cargo/config.toml | 2 +- actix-macros/CHANGES.md | 6 ++++++ actix-macros/Cargo.toml | 3 ++- actix-macros/src/lib.rs | 4 ++-- actix-rt/Cargo.toml | 2 +- actix-rt/tests/test-macro-import-conflict.rs | 17 +++++++++++++++++ actix-server/CHANGES.md | 1 + actix-tls/CHANGES.md | 1 + 8 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 actix-rt/tests/test-macro-import-conflict.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index f96081ae..5e5a6954 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -22,4 +22,4 @@ ci-test-rt-linux = " hack --feature-powerset test --package=actix-rt --li ci-test-server-linux = "hack --feature-powerset test --package=actix-server --lib --tests --no-fail-fast -- --nocapture" # test lower msrv -ci-test-lower-msrv = "hack --workspace --feature-powerset test --lib --tests --no-fail-fast -- --nocapture" +ci-test-lower-msrv = "hack --workspace --exclude=actix-server --exclude=actix-tls --feature-powerset test --lib --tests --no-fail-fast -- --nocapture" diff --git a/actix-macros/CHANGES.md b/actix-macros/CHANGES.md index 0509eb35..8cb03dd0 100644 --- a/actix-macros/CHANGES.md +++ b/actix-macros/CHANGES.md @@ -3,6 +3,12 @@ ## Unreleased - 2021-xx-xx +## 0.2.3 - 2021-10-19 +* Fix test macro in presence of other imports named "test". [#399] + +[#399]: https://github.com/actix/actix-net/pull/399 + + ## 0.2.2 - 2021-10-14 * Improve error recovery potential when macro input is invalid. [#391] * Allow custom `System`s on test macro. [#391] diff --git a/actix-macros/Cargo.toml b/actix-macros/Cargo.toml index bfda142d..75ac8b72 100644 --- a/actix-macros/Cargo.toml +++ b/actix-macros/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "actix-macros" -version = "0.2.2" +version = "0.2.3" authors = [ "Nikolay Kim ", "Ibraheem Ahmed ", + "Rob Ede ", ] description = "Macros for Actix system and runtime" repository = "https://github.com/actix/actix-net.git" diff --git a/actix-macros/src/lib.rs b/actix-macros/src/lib.rs index dae08681..be69b7b0 100644 --- a/actix-macros/src/lib.rs +++ b/actix-macros/src/lib.rs @@ -139,9 +139,9 @@ pub fn test(args: TokenStream, item: TokenStream) -> TokenStream { sig.asyncness = None; let missing_test_attr = if has_test_attr { - quote!() + quote! {} } else { - quote!(#[test]) + quote! { #[::core::prelude::v1::test] } }; let mut system = syn::parse_str::("::actix_rt::System").unwrap(); diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index 942d54aa..89368e19 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -23,7 +23,7 @@ macros = ["actix-macros"] io-uring = ["tokio-uring"] [dependencies] -actix-macros = { version = "0.2.0", optional = true } +actix-macros = { version = "0.2.3", optional = true } futures-core = { version = "0.3", default-features = false } tokio = { version = "1.5.1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } diff --git a/actix-rt/tests/test-macro-import-conflict.rs b/actix-rt/tests/test-macro-import-conflict.rs new file mode 100644 index 00000000..3760d34c --- /dev/null +++ b/actix-rt/tests/test-macro-import-conflict.rs @@ -0,0 +1,17 @@ +//! Checks that test macro does not cause problems in the presence of imports named "test" that +//! could be either a module with test items or the "test with runtime" macro itself. +//! +//! Before actix/actix-net#399 was implemented, this macro was running twice. The first run output +//! `#[test]` and it got run again and since it was in scope. +//! +//! Prevented by using the fully-qualified test marker (`#[::core::prelude::v1::test]`). + +#![cfg(feature = "macros")] + +use actix_rt::time as test; + +#[actix_rt::test] +async fn test_naming_conflict() { + use test as time; + time::sleep(std::time::Duration::from_millis(2)).await; +} diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md index 54096eca..a52712f7 100644 --- a/actix-server/CHANGES.md +++ b/actix-server/CHANGES.md @@ -1,6 +1,7 @@ # Changes ## Unreleased - 2021-xx-xx +* Minimum supported Rust version (MSRV) is now 1.52. ## 2.0.0-beta.6 - 2021-10-11 diff --git a/actix-tls/CHANGES.md b/actix-tls/CHANGES.md index 28dc612a..84d632f3 100644 --- a/actix-tls/CHANGES.md +++ b/actix-tls/CHANGES.md @@ -1,6 +1,7 @@ # Changes ## Unreleased - 2021-xx-xx +* Minimum supported Rust version (MSRV) is now 1.52. ## 3.0.0-beta.5 - 2021-03-29