Skip to content

Commit 58458cd

Browse files
committed
test: migrate check_cfg to snapbox
1 parent 471287f commit 58458cd

File tree

1 file changed

+104
-31
lines changed

1 file changed

+104
-31
lines changed

tests/testsuite/check_cfg.rs

Lines changed: 104 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Tests for Cargo usage of rustc `--check-cfg`.
22
3-
#![allow(deprecated)]
4-
5-
use cargo_test_support::{basic_manifest, project};
3+
use cargo_test_support::prelude::*;
4+
use cargo_test_support::{basic_manifest, project, str};
65

76
macro_rules! x {
87
($tool:tt => $what:tt $(of $who:tt)?) => {{
@@ -31,6 +30,7 @@ macro_rules! x {
3130
}};
3231
}
3332

33+
#[allow(deprecated)]
3434
#[cargo_test]
3535
fn features() {
3636
let p = project()
@@ -57,6 +57,7 @@ fn features() {
5757
.run();
5858
}
5959

60+
#[allow(deprecated)]
6061
#[cargo_test]
6162
fn features_with_deps() {
6263
let p = project()
@@ -87,6 +88,7 @@ fn features_with_deps() {
8788
.run();
8889
}
8990

91+
#[allow(deprecated)]
9092
#[cargo_test]
9193
fn features_with_opt_deps() {
9294
let p = project()
@@ -118,6 +120,7 @@ fn features_with_opt_deps() {
118120
.run();
119121
}
120122

123+
#[allow(deprecated)]
121124
#[cargo_test]
122125
fn features_with_namespaced_features() {
123126
let p = project()
@@ -148,6 +151,7 @@ fn features_with_namespaced_features() {
148151
.run();
149152
}
150153

154+
#[allow(deprecated)]
151155
#[cargo_test]
152156
fn features_fingerprint() {
153157
let p = project()
@@ -210,14 +214,22 @@ fn features_fingerprint() {
210214

211215
p.cargo("check -v")
212216
// we check that the fingerprint is indeed dirty
213-
.with_stderr_contains("[..]Dirty[..]the list of declared features changed")
214217
// that is cause rustc to be called again with the new check-cfg args
215-
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a"))
216218
// and that we indeed found a new warning from the unexpected_cfgs lint
217-
.with_stderr_contains("[..]unexpected_cfgs[..]")
219+
.with_stderr_data(format!(
220+
"\
221+
[DIRTY] foo v0.1.0 ([ROOT]/foo): the list of declared features changed
222+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
223+
{running_rustc}
224+
[WARNING] unexpected `cfg` condition value: `f_b`
225+
...
226+
",
227+
running_rustc = x!("rustc" => "cfg" of "feature" with "f_a")
228+
))
218229
.run();
219230
}
220231

232+
#[allow(deprecated)]
221233
#[cargo_test]
222234
fn well_known_names_values() {
223235
let p = project()
@@ -231,6 +243,7 @@ fn well_known_names_values() {
231243
.run();
232244
}
233245

246+
#[allow(deprecated)]
234247
#[cargo_test]
235248
fn features_test() {
236249
let p = project()
@@ -256,6 +269,7 @@ fn features_test() {
256269
.run();
257270
}
258271

272+
#[allow(deprecated)]
259273
#[cargo_test]
260274
fn features_doctest() {
261275
let p = project()
@@ -285,6 +299,7 @@ fn features_doctest() {
285299
.run();
286300
}
287301

302+
#[allow(deprecated)]
288303
#[cargo_test]
289304
fn well_known_names_values_test() {
290305
let p = project()
@@ -298,6 +313,7 @@ fn well_known_names_values_test() {
298313
.run();
299314
}
300315

316+
#[allow(deprecated)]
301317
#[cargo_test]
302318
fn well_known_names_values_doctest() {
303319
let p = project()
@@ -313,6 +329,7 @@ fn well_known_names_values_doctest() {
313329
.run();
314330
}
315331

332+
#[allow(deprecated)]
316333
#[cargo_test]
317334
fn features_doc() {
318335
let p = project()
@@ -340,6 +357,7 @@ fn features_doc() {
340357
.run();
341358
}
342359

360+
#[allow(deprecated)]
343361
#[cargo_test]
344362
fn build_script_feedback() {
345363
let p = project()
@@ -368,6 +386,7 @@ fn build_script_feedback() {
368386
.run();
369387
}
370388

389+
#[allow(deprecated)]
371390
#[cargo_test]
372391
fn build_script_doc() {
373392
let p = project()
@@ -391,21 +410,22 @@ fn build_script_doc() {
391410

392411
p.cargo("doc -v")
393412
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
394-
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
395-
.with_stderr(
413+
.with_stderr_data(format!(
396414
"\
397-
[COMPILING] foo v0.0.1 ([CWD])
415+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
398416
[RUNNING] `rustc [..] build.rs [..]`
399-
[RUNNING] `[..]/build-script-build`
400-
[DOCUMENTING] foo [..]
401-
[RUNNING] `rustdoc [..] src/main.rs [..]
402-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
403-
[GENERATED] [CWD]/target/doc/foo/index.html
417+
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
418+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
419+
{running_rustdoc}
420+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
421+
[GENERATED] [ROOT]/foo/target/doc/foo/index.html
404422
",
405-
)
423+
running_rustdoc = x!("rustdoc" => "cfg" of "foo")
424+
))
406425
.run();
407426
}
408427

428+
#[allow(deprecated)]
409429
#[cargo_test]
410430
fn build_script_override() {
411431
let target = cargo_test_support::rustc_host();
@@ -491,14 +511,31 @@ fn build_script_test() {
491511
.build();
492512

493513
p.cargo("test -v")
494-
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
495-
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
496-
.with_stdout_contains("test test_foo ... ok")
497-
.with_stdout_contains("test test_bar ... ok")
498-
.with_stdout_contains_n("test [..] ... ok", 3)
514+
.with_stderr_data(
515+
format!(
516+
"\
517+
{running_rustc}
518+
{running_rustdoc}
519+
...
520+
",
521+
running_rustc = x!("rustc" => "cfg" of "foo"),
522+
running_rustdoc = x!("rustdoc" => "cfg" of "foo")
523+
)
524+
.unordered(),
525+
)
526+
.with_stdout_data(
527+
str![[r#"
528+
test test_foo ... ok
529+
test test_bar ... ok
530+
test [..] ... ok
531+
...
532+
"#]]
533+
.unordered(),
534+
)
499535
.run();
500536
}
501537

538+
#[allow(deprecated)]
502539
#[cargo_test]
503540
fn config_simple() {
504541
let p = project()
@@ -524,6 +561,7 @@ fn config_simple() {
524561
.run();
525562
}
526563

564+
#[allow(deprecated)]
527565
#[cargo_test]
528566
fn config_workspace() {
529567
let p = project()
@@ -553,11 +591,19 @@ fn config_workspace() {
553591
.build();
554592

555593
p.cargo("check -v")
556-
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
594+
.with_stderr_data(format!(
595+
"\
596+
...
597+
{running_rustc}
598+
...
599+
",
600+
running_rustc = x!("rustc" => "cfg" of "has_foo")
601+
))
557602
.with_stderr_does_not_contain("unexpected_cfgs")
558603
.run();
559604
}
560605

606+
#[allow(deprecated)]
561607
#[cargo_test]
562608
fn config_workspace_not_inherited() {
563609
let p = project()
@@ -589,6 +635,7 @@ fn config_workspace_not_inherited() {
589635
.run();
590636
}
591637

638+
#[allow(deprecated)]
592639
#[cargo_test]
593640
fn config_invalid_position() {
594641
let p = project()
@@ -608,7 +655,10 @@ fn config_invalid_position() {
608655
.build();
609656

610657
p.cargo("check -v")
611-
.with_stderr_contains("[..]unused manifest key: `lints.rust.use_bracket.check-cfg`[..]")
658+
.with_stderr_data(str![[r#"
659+
[WARNING] unused manifest key: `lints.rust.use_bracket.check-cfg`
660+
...
661+
"#]])
612662
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "has_foo"))
613663
.run();
614664
}
@@ -633,7 +683,10 @@ fn config_invalid_empty() {
633683

634684
p.cargo("check")
635685
.with_status(101)
636-
.with_stderr_contains("[..]missing field `level`[..]")
686+
.with_stderr_data(str![[r#"
687+
[ERROR] missing field `level`
688+
...
689+
"#]])
637690
.run();
638691
}
639692

@@ -657,9 +710,10 @@ fn config_invalid_not_list() {
657710

658711
p.cargo("check")
659712
.with_status(101)
660-
.with_stderr_contains(
661-
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
662-
)
713+
.with_stderr_data(str![[r#"
714+
[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string
715+
...
716+
"#]])
663717
.run();
664718
}
665719

@@ -683,12 +737,14 @@ fn config_invalid_not_list_string() {
683737

684738
p.cargo("check")
685739
.with_status(101)
686-
.with_stderr_contains(
687-
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
688-
)
740+
.with_stderr_data(str![[r#"
741+
[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string
742+
...
743+
"#]])
689744
.run();
690745
}
691746

747+
#[allow(deprecated)]
692748
#[cargo_test]
693749
fn config_and_features() {
694750
let p = project()
@@ -737,7 +793,14 @@ fn config_with_cargo_doc() {
737793
.build();
738794

739795
p.cargo("doc -v")
740-
.with_stderr_contains(x!("rustdoc" => "cfg" of "has_foo"))
796+
.with_stderr_data(format!(
797+
"\
798+
...
799+
{running_rustdoc}
800+
...
801+
",
802+
running_rustdoc = x!("rustdoc" => "cfg" of "has_foo")
803+
))
741804
.run();
742805
}
743806

@@ -760,10 +823,18 @@ fn config_with_cargo_test() {
760823
.build();
761824

762825
p.cargo("test -v")
763-
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
826+
.with_stderr_data(format!(
827+
"\
828+
...
829+
{running_rustc}
830+
...
831+
",
832+
running_rustc = x!("rustc" => "cfg" of "has_foo")
833+
))
764834
.run();
765835
}
766836

837+
#[allow(deprecated)]
767838
#[cargo_test]
768839
fn config_and_build_script() {
769840
let p = project()
@@ -793,6 +864,7 @@ fn config_and_build_script() {
793864
.run();
794865
}
795866

867+
#[allow(deprecated)]
796868
#[cargo_test]
797869
fn config_features_and_build_script() {
798870
let p = project()
@@ -828,6 +900,7 @@ fn config_features_and_build_script() {
828900
.run();
829901
}
830902

903+
#[allow(deprecated)]
831904
#[cargo_test]
832905
fn config_fingerprint() {
833906
let p = project()

0 commit comments

Comments
 (0)