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 92cf66c
Showing 1 changed file with 82 additions and 5 deletions.
87 changes: 82 additions & 5 deletions tests/testsuite/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,22 +332,64 @@ 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();
}

Expand All @@ -368,13 +410,26 @@ 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();
}

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 92cf66c

Please sign in to comment.