Skip to content

Commit 92cf66c

Browse files
committed
Add stderr checking for the conditional test well known cfg
1 parent 9e47488 commit 92cf66c

File tree

1 file changed

+82
-5
lines changed

1 file changed

+82
-5
lines changed

tests/testsuite/check_cfg.rs

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,22 +332,64 @@ fn test_false_lib() {
332332
test = false
333333
"#,
334334
)
335-
.file("src/lib.rs", "")
335+
.file("src/lib.rs", "#[cfg(test)] mod tests {}")
336336
.build();
337337

338338
p.cargo("check -v")
339339
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "docsrs,test"))
340340
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
341+
.with_stderr_data(str![[r#"
342+
...
343+
[WARNING] unexpected `cfg` condition name: `test`
344+
--> src/lib.rs:1:7
345+
|
346+
1 | #[cfg(test)] mod tests {}
347+
| ^^^^
348+
...
349+
350+
[WARNING] `foo` (lib) generated 1 warning
351+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
352+
353+
"#]])
341354
.run();
342355

343356
p.cargo("clean").run();
344357
p.cargo("test -v")
345358
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
359+
.with_stderr_data(str![[r#"
360+
...
361+
[WARNING] unexpected `cfg` condition name: `test`
362+
--> src/lib.rs:1:7
363+
|
364+
1 | #[cfg(test)] mod tests {}
365+
| ^^^^
366+
...
367+
368+
[WARNING] `foo` (lib) generated 1 warning
369+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
370+
[DOCTEST] foo
371+
[RUNNING] [..]
372+
373+
"#]])
346374
.run();
347375

348376
p.cargo("clean").run();
349377
p.cargo("test --lib -v")
350378
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
379+
.with_stderr_data(str![[r#"
380+
...
381+
[WARNING] unexpected `cfg` condition name: `test`
382+
--> src/lib.rs:1:7
383+
|
384+
1 | #[cfg(test)] mod tests {}
385+
| ^^^^
386+
...
387+
388+
[WARNING] `foo` (lib test) generated 1 warning
389+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
390+
[RUNNING] `[ROOT]/foo/target/debug/deps/foo-[HASH]`
391+
392+
"#]])
351393
.run();
352394
}
353395

@@ -368,13 +410,26 @@ fn test_false_bins() {
368410
path = "src/deamon.rs"
369411
"#,
370412
)
371-
.file("src/main.rs", "fn main() {}")
372-
.file("src/deamon.rs", "fn main() {}")
413+
.file("src/main.rs", "fn main() {}\n#[cfg(test)] mod tests {}")
414+
.file("src/deamon.rs", "fn main() {}\n#[cfg(test)] mod tests {}")
373415
.build();
374416

375417
p.cargo("check -v")
376418
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs,test")) // for foo
377419
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // for deamon
420+
.with_stderr_data(str![[r#"
421+
...
422+
[WARNING] unexpected `cfg` condition name: `test`
423+
--> src/deamon.rs:2:7
424+
|
425+
2 | #[cfg(test)] mod tests {}
426+
| ^^^^
427+
...
428+
429+
[WARNING] `foo` (bin "daemon") generated 1 warning
430+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
431+
432+
"#]])
378433
.run();
379434
}
380435

@@ -398,13 +453,35 @@ fn test_false_examples() {
398453
path = "src/deamon.rs"
399454
"#,
400455
)
401-
.file("src/lib.rs", "")
402-
.file("src/deamon.rs", "fn main() {}")
456+
.file("src/lib.rs", "#[cfg(test)] mod tests {}")
457+
.file("src/deamon.rs", "fn main() {}\n#[cfg(test)] mod tests {}")
403458
.build();
404459

405460
p.cargo("check --examples -v")
406461
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "docsrs,test"))
407462
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
463+
.with_stderr_data(str![[r#"
464+
...
465+
[WARNING] unexpected `cfg` condition name: `test`
466+
--> src/lib.rs:1:7
467+
|
468+
1 | #[cfg(test)] mod tests {}
469+
| ^^^^
470+
...
471+
472+
[WARNING] `foo` (lib) generated 1 warning
473+
...
474+
[WARNING] unexpected `cfg` condition name: `test`
475+
--> src/deamon.rs:2:7
476+
|
477+
2 | #[cfg(test)] mod tests {}
478+
| ^^^^
479+
...
480+
481+
[WARNING] `foo` (example "daemon") generated 1 warning
482+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
483+
484+
"#]])
408485
.run();
409486
}
410487

0 commit comments

Comments
 (0)