Skip to content

Commit 02b2621

Browse files
committed
Add more unexpected target cfgs tests
1 parent 4af70bd commit 02b2621

File tree

1 file changed

+247
-0
lines changed

1 file changed

+247
-0
lines changed

tests/testsuite/cfg.rs

+247
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ fn unexpected_cfgs_target() {
704704

705705
p.cargo("check -Zcheck-target-cfgs")
706706
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
707+
// FIXME: We should warn on multiple cfgs
707708
.with_stderr_data(str![[r#"
708709
[LOCKING] 2 packages to latest compatible versions
709710
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
@@ -713,3 +714,249 @@ fn unexpected_cfgs_target() {
713714
"#]])
714715
.run();
715716
}
717+
718+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
719+
fn unexpected_cfgs_target_with_lint() {
720+
let p = project()
721+
.file(
722+
"Cargo.toml",
723+
r#"
724+
[package]
725+
name = "a"
726+
version = "0.0.1"
727+
edition = "2015"
728+
authors = []
729+
730+
[target."cfg(foo)".dependencies] # should not warn here
731+
b = { path = 'b' }
732+
733+
[target.'cfg(foo = "foo")'.dependencies] # should not warn here
734+
b = { path = 'b' }
735+
736+
[target."cfg(bar)".dependencies]
737+
b = { path = 'b' }
738+
739+
[lints.rust.unexpected_cfgs]
740+
level = "warn"
741+
check-cfg = ['cfg(foo, values(none(), "foo"))'] # because of this line
742+
"#,
743+
)
744+
.file(
745+
".cargo/config.toml",
746+
r#"
747+
[target."cfg(foo)"] # but it doesn't have an effect here
748+
"#,
749+
)
750+
.file("src/lib.rs", "")
751+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
752+
.file("b/src/lib.rs", "")
753+
.build();
754+
755+
p.cargo("check -Zcheck-target-cfgs")
756+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
757+
// FIXME: We should warn on multiple cfgs
758+
.with_stderr_data(str![[r#"
759+
[LOCKING] 1 package to latest compatible version
760+
[CHECKING] a v0.0.1 ([ROOT]/foo)
761+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
762+
763+
"#]])
764+
.run();
765+
}
766+
767+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
768+
fn unexpected_cfgs_target_diagnostics() {
769+
let p = project()
770+
.file(
771+
"Cargo.toml",
772+
r#"
773+
[package]
774+
name = "a"
775+
version = "0.0.1"
776+
edition = "2015"
777+
authors = []
778+
779+
[target."cfg(target_pointer_width)".dependencies]
780+
b = { path = 'b' }
781+
782+
[target.'cfg( all(foo , bar))'.dependencies]
783+
b = { path = 'b' }
784+
"#,
785+
)
786+
.file("src/lib.rs", "")
787+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
788+
.file("b/src/lib.rs", "")
789+
.build();
790+
791+
p.cargo("check -Zcheck-target-cfgs")
792+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
793+
.with_stderr_data(str![[r#"
794+
[LOCKING] 1 package to latest compatible version
795+
[CHECKING] a v0.0.1 ([ROOT]/foo)
796+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
797+
798+
"#]])
799+
.run();
800+
}
801+
802+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
803+
fn unexpected_cfgs_target_lint_level_allow() {
804+
let p = project()
805+
.file(
806+
"Cargo.toml",
807+
r#"
808+
[package]
809+
name = "a"
810+
version = "0.0.1"
811+
edition = "2015"
812+
authors = []
813+
814+
[target."cfg(foo)".dependencies]
815+
b = { path = 'b' }
816+
817+
[lints.rust.unexpected_cfgs]
818+
level = "allow"
819+
"#,
820+
)
821+
.file("src/lib.rs", "")
822+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
823+
.file("b/src/lib.rs", "")
824+
.build();
825+
826+
p.cargo("check -Zcheck-target-cfgs")
827+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
828+
// FIXME: We should warn on multiple cfgs
829+
.with_stderr_data(str![[r#"
830+
[LOCKING] 1 package to latest compatible version
831+
[CHECKING] a v0.0.1 ([ROOT]/foo)
832+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
833+
834+
"#]])
835+
.run();
836+
}
837+
838+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
839+
fn unexpected_cfgs_target_lint_level_deny() {
840+
let p = project()
841+
.file(
842+
"Cargo.toml",
843+
r#"
844+
[package]
845+
name = "a"
846+
version = "0.0.1"
847+
edition = "2015"
848+
authors = []
849+
850+
[target."cfg(foo)".dependencies]
851+
b = { path = 'b' }
852+
853+
[lints.rust.unexpected_cfgs]
854+
level = "deny"
855+
"#,
856+
)
857+
.file("src/lib.rs", "")
858+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
859+
.file("b/src/lib.rs", "")
860+
.build();
861+
862+
p.cargo("check -Zcheck-target-cfgs")
863+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
864+
.with_stderr_data(str![[r#"
865+
[LOCKING] 1 package to latest compatible version
866+
[CHECKING] a v0.0.1 ([ROOT]/foo)
867+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
868+
869+
"#]])
870+
// FIXME: this test should fail
871+
// .with_status(101)
872+
.run();
873+
}
874+
875+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
876+
fn unexpected_cfgs_target_cfg_any() {
877+
let p = project()
878+
.file(
879+
"Cargo.toml",
880+
r#"
881+
[package]
882+
name = "a"
883+
version = "0.0.1"
884+
edition = "2015"
885+
authors = []
886+
887+
[target."cfg(foo)".dependencies]
888+
b = { path = 'b' }
889+
890+
[lints.rust.unexpected_cfgs]
891+
level = "deny"
892+
check-cfg = ["cfg(any())"]
893+
"#,
894+
)
895+
.file("src/lib.rs", "")
896+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
897+
.file("b/src/lib.rs", "")
898+
.build();
899+
900+
p.cargo("check -Zcheck-target-cfgs")
901+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
902+
.with_stderr_data(str![[r#"
903+
[LOCKING] 1 package to latest compatible version
904+
[CHECKING] a v0.0.1 ([ROOT]/foo)
905+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
906+
907+
"#]])
908+
.run();
909+
}
910+
911+
#[cargo_test]
912+
fn no_unexpected_cfgs_target() {
913+
let p = project()
914+
.file(
915+
"Cargo.toml",
916+
r#"
917+
[package]
918+
name = "a"
919+
version = "0.0.1"
920+
edition = "2015"
921+
authors = []
922+
923+
[target."cfg(any(windows, unix))".dependencies]
924+
b = { path = 'b' }
925+
926+
[target.'cfg(unix = "zoo")'.dependencies]
927+
b = { path = 'b' }
928+
"#,
929+
)
930+
.file(
931+
".cargo/config.toml",
932+
r#"
933+
[target."cfg(any(windows, unix))"]
934+
[target.'cfg(unix = "zoo")']
935+
"#,
936+
)
937+
.file("src/lib.rs", "extern crate b;")
938+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
939+
.file("b/src/lib.rs", "")
940+
.build();
941+
942+
p.cargo("check")
943+
.with_stderr_data(str![[r#"
944+
[LOCKING] 1 package to latest compatible version
945+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
946+
[CHECKING] a v0.0.1 ([ROOT]/foo)
947+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
948+
949+
"#]])
950+
.run();
951+
952+
p.cargo("check -Zcargo-lints")
953+
.masquerade_as_nightly_cargo(&["requires -Zcargo-lints"])
954+
.with_stderr_data(str![[r#"
955+
[LOCKING] 1 package to latest compatible version
956+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
957+
[CHECKING] a v0.0.1 ([ROOT]/foo)
958+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
959+
960+
"#]])
961+
.run();
962+
}

0 commit comments

Comments
 (0)