-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conditionally mark the test
cfg as a well known cfg
#15007
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -317,6 +317,193 @@ fn well_known_names_values_doctest() { | |
.run(); | ||
} | ||
|
||
#[cargo_test(nightly, reason = "warning currently only on nightly")] | ||
fn test_false_lib() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
test = false | ||
"#, | ||
) | ||
.file("src/lib.rs", "#[cfg(test)] mod tests {}") | ||
.build(); | ||
|
||
p.cargo("check -v") | ||
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "docsrs,test")) | ||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) | ||
.with_stderr_data(str![[r#" | ||
... | ||
[WARNING] unexpected `cfg` condition name: `test` | ||
... | ||
|
||
[WARNING] `foo` (lib) generated 1 warning | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
|
||
p.cargo("clean").run(); | ||
p.cargo("test -v") | ||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) | ||
.with_stderr_data(str![[r#" | ||
... | ||
[WARNING] unexpected `cfg` condition name: `test` | ||
... | ||
|
||
[WARNING] `foo` (lib) generated 1 warning | ||
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
[DOCTEST] foo | ||
[RUNNING] [..] | ||
|
||
"#]]) | ||
.run(); | ||
|
||
p.cargo("clean").run(); | ||
p.cargo("test --lib -v") | ||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) | ||
.with_stderr_data(str![[r#" | ||
... | ||
[WARNING] unexpected `cfg` condition name: `test` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If user has specified There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What the command line arguments are shouldn't matter, otherwise users would get a different behavior between a "normal" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. However, Maybe I should put the question this way: Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO having @jplatte made a further argument in his comment:
A similar comment was also put in the URLO thread. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for linking the thread here. Yeah I've read that, and agree that However, fields under Cargo targets are mostly about including in or excluding from the default crate set, and are largely affected by the command-line argument. If Cargo has started emitting unexpected warning for Cargo targets, it may also bite users that disabling tests for other reasons. For example, I've seen people setting While that kind of scenario I guess is far less than who don't want tests at all, it is still a valid use case aligning with what the current doc describes. Treating That being said, I am not surprised if Cargo targets settings don't meet people's expectation. It is always a source of confusions1 😞. Footnotes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
We can probably make the lint fire without the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I missed something in catching up on this, I feel like we'd get more out of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My main point is the meaning of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have adjusted the documentation with the new behavior. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are multiple ways which a target may be tested even when it has |
||
--> src/lib.rs:1:7 | ||
... | ||
|
||
[WARNING] `foo` (lib test) generated 1 warning | ||
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
[RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH][EXE]` | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test(nightly, reason = "warning currently only on nightly")] | ||
fn test_false_bins() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[[bin]] | ||
name = "daemon" | ||
test = false | ||
path = "src/deamon.rs" | ||
"#, | ||
) | ||
.file("src/main.rs", "fn main() {}\n#[cfg(test)] mod tests {}") | ||
.file("src/deamon.rs", "fn main() {}\n#[cfg(test)] mod tests {}") | ||
.build(); | ||
|
||
p.cargo("check -v") | ||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) // for foo | ||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // for deamon | ||
.with_stderr_data(str![[r#" | ||
... | ||
[WARNING] unexpected `cfg` condition name: `test` | ||
... | ||
|
||
[WARNING] `foo` (bin "daemon") generated 1 warning | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test(nightly, reason = "warning currently only on nightly")] | ||
fn test_false_examples() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
test = false | ||
|
||
[[example]] | ||
name = "daemon" | ||
test = false | ||
path = "src/deamon.rs" | ||
"#, | ||
) | ||
.file("src/lib.rs", "#[cfg(test)] mod tests {}") | ||
.file("src/deamon.rs", "fn main() {}\n#[cfg(test)] mod tests {}") | ||
.build(); | ||
|
||
p.cargo("check --examples -v") | ||
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "docsrs,test")) | ||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) | ||
.with_stderr_data(str![[r#" | ||
... | ||
[WARNING] unexpected `cfg` condition name: `test` | ||
... | ||
|
||
[WARNING] `foo` (lib) generated 1 warning | ||
... | ||
[WARNING] unexpected `cfg` condition name: `test` | ||
... | ||
|
||
[WARNING] `foo` (example "daemon") generated 1 warning | ||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test( | ||
nightly, | ||
reason = "bench is nightly & warning currently only on nightly" | ||
)] | ||
fn test_false_benches() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.0.0" | ||
edition = "2018" | ||
|
||
[[bench]] | ||
name = "ben1" | ||
test = false | ||
path = "benches/ben1.rs" | ||
"#, | ||
) | ||
.file("src/lib.rs", "") | ||
.file( | ||
"benches/ben1.rs", | ||
r#" | ||
#![feature(test)] | ||
extern crate test; | ||
#[bench] fn run1(_ben: &mut test::Bencher) { } | ||
"#, | ||
) | ||
.build(); | ||
|
||
// Benches always require the `test` cfg, there should be no warning. | ||
p.cargo("bench --bench ben1") | ||
.with_stderr_data(str![[r#" | ||
[COMPILING] foo v0.0.0 ([ROOT]/foo) | ||
[FINISHED] `bench` profile [optimized] target(s) in [ELAPSED]s | ||
[RUNNING] benches/ben1.rs (target/release/deps/ben1-[HASH][EXE]) | ||
|
||
"#]]) | ||
.run(); | ||
} | ||
|
||
#[cargo_test] | ||
fn features_doc() { | ||
let p = project() | ||
|
Uh oh!
There was an error while loading. Please reload this page.