Skip to content

Commit 55d23f2

Browse files
committed
Add more unexpected target cfgs tests
1 parent 81e6819 commit 55d23f2

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed

tests/testsuite/cfg.rs

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ fn unexpected_cfgs_target() {
566566

567567
p.cargo("check -Zcheck-target-cfgs")
568568
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
569+
// FIXME: We should warn on multiple cfgs
569570
.with_stderr_data(str![[r#"
570571
[LOCKING] 2 packages to latest compatible versions
571572
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
@@ -575,3 +576,214 @@ fn unexpected_cfgs_target() {
575576
"#]])
576577
.run();
577578
}
579+
580+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
581+
fn unexpected_cfgs_target_with_lint() {
582+
let p = project()
583+
.file(
584+
"Cargo.toml",
585+
r#"
586+
[package]
587+
name = "a"
588+
version = "0.0.1"
589+
edition = "2015"
590+
authors = []
591+
592+
[target."cfg(foo)".dependencies] # should not warn here
593+
b = { path = 'b' }
594+
595+
[target.'cfg(foo = "foo")'.dependencies] # should not warn here
596+
b = { path = 'b' }
597+
598+
[target."cfg(bar)".dependencies]
599+
b = { path = 'b' }
600+
601+
[lints.rust.unexpected_cfgs]
602+
level = "warn"
603+
check-cfg = ['cfg(foo, values(none(), "foo"))'] # because of this line
604+
"#,
605+
)
606+
.file(
607+
".cargo/config.toml",
608+
r#"
609+
[target."cfg(foo)"] # but it doesn't have an effect here
610+
"#,
611+
)
612+
.file("src/lib.rs", "")
613+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
614+
.file("b/src/lib.rs", "")
615+
.build();
616+
617+
p.cargo("check -Zcheck-target-cfgs")
618+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
619+
// FIXME: We should warn on multiple cfgs
620+
.with_stderr_data(str![[r#"
621+
[LOCKING] 1 package to latest compatible version
622+
[CHECKING] a v0.0.1 ([ROOT]/foo)
623+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
624+
625+
"#]])
626+
.run();
627+
}
628+
629+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
630+
fn unexpected_cfgs_target_lint_level_allow() {
631+
let p = project()
632+
.file(
633+
"Cargo.toml",
634+
r#"
635+
[package]
636+
name = "a"
637+
version = "0.0.1"
638+
edition = "2015"
639+
authors = []
640+
641+
[target."cfg(foo)".dependencies]
642+
b = { path = 'b' }
643+
644+
[lints.rust.unexpected_cfgs]
645+
level = "allow"
646+
"#,
647+
)
648+
.file("src/lib.rs", "")
649+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
650+
.file("b/src/lib.rs", "")
651+
.build();
652+
653+
p.cargo("check -Zcheck-target-cfgs")
654+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
655+
// FIXME: We should warn on multiple cfgs
656+
.with_stderr_data(str![[r#"
657+
[LOCKING] 1 package to latest compatible version
658+
[CHECKING] a v0.0.1 ([ROOT]/foo)
659+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
660+
661+
"#]])
662+
.run();
663+
}
664+
665+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
666+
fn unexpected_cfgs_target_lint_level_deny() {
667+
let p = project()
668+
.file(
669+
"Cargo.toml",
670+
r#"
671+
[package]
672+
name = "a"
673+
version = "0.0.1"
674+
edition = "2015"
675+
authors = []
676+
677+
[target."cfg(foo)".dependencies]
678+
b = { path = 'b' }
679+
680+
[lints.rust.unexpected_cfgs]
681+
level = "deny"
682+
"#,
683+
)
684+
.file("src/lib.rs", "")
685+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
686+
.file("b/src/lib.rs", "")
687+
.build();
688+
689+
p.cargo("check -Zcheck-target-cfgs")
690+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
691+
.with_stderr_data(str![[r#"
692+
[LOCKING] 1 package to latest compatible version
693+
[CHECKING] a v0.0.1 ([ROOT]/foo)
694+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
695+
696+
"#]])
697+
// FIXME: this test should fail
698+
// .with_status(101)
699+
.run();
700+
}
701+
702+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
703+
fn unexpected_cfgs_target_cfg_any() {
704+
let p = project()
705+
.file(
706+
"Cargo.toml",
707+
r#"
708+
[package]
709+
name = "a"
710+
version = "0.0.1"
711+
edition = "2015"
712+
authors = []
713+
714+
[target."cfg(foo)".dependencies]
715+
b = { path = 'b' }
716+
717+
[lints.rust.unexpected_cfgs]
718+
level = "deny"
719+
check-cfg = ["cfg(any())"]
720+
"#,
721+
)
722+
.file("src/lib.rs", "")
723+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
724+
.file("b/src/lib.rs", "")
725+
.build();
726+
727+
p.cargo("check -Zcheck-target-cfgs")
728+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
729+
.with_stderr_data(str![[r#"
730+
[LOCKING] 1 package to latest compatible version
731+
[CHECKING] a v0.0.1 ([ROOT]/foo)
732+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
733+
734+
"#]])
735+
.run();
736+
}
737+
738+
#[cargo_test]
739+
fn no_unexpected_cfgs_target() {
740+
let p = project()
741+
.file(
742+
"Cargo.toml",
743+
r#"
744+
[package]
745+
name = "a"
746+
version = "0.0.1"
747+
edition = "2015"
748+
authors = []
749+
750+
[target."cfg(any(windows, unix))".dependencies]
751+
b = { path = 'b' }
752+
753+
[target.'cfg(unix = "zoo")'.dependencies]
754+
b = { path = 'b' }
755+
"#,
756+
)
757+
.file(
758+
".cargo/config.toml",
759+
r#"
760+
[target."cfg(any(windows, unix))"]
761+
[target.'cfg(unix = "zoo")']
762+
"#,
763+
)
764+
.file("src/lib.rs", "extern crate b;")
765+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
766+
.file("b/src/lib.rs", "")
767+
.build();
768+
769+
p.cargo("check")
770+
.with_stderr_data(str![[r#"
771+
[LOCKING] 1 package to latest compatible version
772+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
773+
[CHECKING] a v0.0.1 ([ROOT]/foo)
774+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
775+
776+
"#]])
777+
.run();
778+
779+
p.cargo("check -Zcargo-lints")
780+
.masquerade_as_nightly_cargo(&["requires -Zcargo-lints"])
781+
.with_stderr_data(str![[r#"
782+
[LOCKING] 1 package to latest compatible version
783+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
784+
[CHECKING] a v0.0.1 ([ROOT]/foo)
785+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
786+
787+
"#]])
788+
.run();
789+
}

0 commit comments

Comments
 (0)