Skip to content

Commit ca0557a

Browse files
committed
Auto merge of #11614 - ehuss:fix-unused-attr-warn, r=weihanglo
Fix unused attribute on Windows. The change introduced in #11610 is causing unused_attribute warnings on Windows because there are two `ignore` attributes when CARGO_PUBLIC_NETWORK_TESTS is not set. The solution here is to make `cargo_test` support a hard-coded option for an additional reason to ignore a test. Ideally I think this would use something like a `cfg()` expression, but those can't really be evaluated within the proc-macro (without pulling in `cargo_platform`). Could also just `allow(unused_attributes)`, but that felt a little icky.
2 parents af8ec14 + 9247e81 commit ca0557a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

crates/cargo-test-macro/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ pub fn cargo_test(attr: TokenStream, item: TokenStream) -> TokenStream {
8989
s if s.starts_with("reason=") => {
9090
explicit_reason = Some(s[7..].parse().unwrap());
9191
}
92+
s if s.starts_with("ignore_windows=") => {
93+
set_ignore!(cfg!(windows), "{}", &s[16..s.len() - 1]);
94+
}
9295
_ => panic!("unknown rule {:?}", rule),
9396
}
9497
}

src/doc/contrib/src/tests/writing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The options it supports are:
104104
These should work on Linux, macOS, and Windows where possible.
105105
Unfortunately these tests are not run in CI for macOS or Windows (no Docker on macOS, and Windows does not support Linux images).
106106
See [`crates/cargo-test-support/src/containers.rs`](https://github.com/rust-lang/cargo/blob/master/crates/cargo-test-support/src/containers.rs) for more on writing these tests.
107-
107+
* `ignore_windows="reason"` — Indicates that the test should be ignored on windows for the given reason.
108108

109109
#### Testing Nightly Features
110110

tests/testsuite/ssh.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,10 @@ Caused by:
385385
.run();
386386
}
387387

388-
#[cargo_test(public_network_test)]
389388
// For unknown reasons, this test occasionally fails on Windows with a
390389
// LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE error:
391390
// failed to start SSH session: Unable to exchange encryption keys; class=Ssh (23)
392-
#[cfg_attr(windows, ignore = "test is flaky on windows")]
391+
#[cargo_test(public_network_test, ignore_windows = "test is flaky on windows")]
393392
fn invalid_github_key() {
394393
// A key for github.com in known_hosts should override the built-in key.
395394
// This uses a bogus key which should result in an error.
@@ -420,11 +419,10 @@ fn invalid_github_key() {
420419
.run();
421420
}
422421

423-
#[cargo_test(public_network_test)]
424422
// For unknown reasons, this test occasionally fails on Windows with a
425423
// LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE error:
426424
// failed to start SSH session: Unable to exchange encryption keys; class=Ssh (23)
427-
#[cfg_attr(windows, ignore = "test is flaky on windows")]
425+
#[cargo_test(public_network_test, ignore_windows = "test is flaky on windows")]
428426
fn bundled_github_works() {
429427
// The bundled key for github.com works.
430428
//

0 commit comments

Comments
 (0)