Skip to content

Commit

Permalink
Add stderr checking for the conditional test well known cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Jan 4, 2025
1 parent 9e47488 commit a02f269
Showing 1 changed file with 85 additions and 8 deletions.
93 changes: 85 additions & 8 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ fn well_known_names_values_doctest() {
.run();
}

#[cargo_test]
#[cargo_test(nightly, reason = "warning currently only on nightly")]
fn test_false_lib() {
let p = project()
.file(
Expand All @@ -332,26 +332,68 @@ fn test_false_lib() {
test = false
"#,
)
.file("src/lib.rs", "")
.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`
--> src/lib.rs:1:7
|
1 | #[cfg(test)] mod tests {}
| ^^^^
...
[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`
--> src/lib.rs:1:7
|
1 | #[cfg(test)] mod tests {}
| ^^^^
...
[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`
--> src/lib.rs:1:7
|
1 | #[cfg(test)] mod tests {}
| ^^^^
...
[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]`
"#]])
.run();
}

#[cargo_test]
#[cargo_test(nightly, reason = "warning currently only on nightly")]
fn test_false_bins() {
let p = project()
.file(
Expand All @@ -368,17 +410,30 @@ fn test_false_bins() {
path = "src/deamon.rs"
"#,
)
.file("src/main.rs", "fn main() {}")
.file("src/deamon.rs", "fn main() {}")
.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`
--> src/deamon.rs:2:7
|
2 | #[cfg(test)] mod tests {}
| ^^^^
...
[WARNING] `foo` (bin "daemon") generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

#[cargo_test]
#[cargo_test(nightly, reason = "warning currently only on nightly")]
fn test_false_examples() {
let p = project()
.file(
Expand All @@ -398,13 +453,35 @@ fn test_false_examples() {
path = "src/deamon.rs"
"#,
)
.file("src/lib.rs", "")
.file("src/deamon.rs", "fn main() {}")
.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`
--> src/lib.rs:1:7
|
1 | #[cfg(test)] mod tests {}
| ^^^^
...
[WARNING] `foo` (lib) generated 1 warning
...
[WARNING] unexpected `cfg` condition name: `test`
--> src/deamon.rs:2:7
|
2 | #[cfg(test)] mod tests {}
| ^^^^
...
[WARNING] `foo` (example "daemon") generated 1 warning
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

Expand Down

0 comments on commit a02f269

Please sign in to comment.