Skip to content

Commit d8d70f4

Browse files
committed
Add more unexpected target cfgs tests
1 parent e63115f commit d8d70f4

File tree

1 file changed

+253
-0
lines changed

1 file changed

+253
-0
lines changed

tests/testsuite/cfg.rs

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ fn unexpected_cfgs_target() {
862862

863863
p.cargo("check -Zcheck-target-cfgs")
864864
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
865+
// FIXME: We should warn on multiple cfgs
865866
.with_stderr_data(str![[r#"
866867
[LOCKING] 2 packages to latest compatible versions
867868
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
@@ -871,3 +872,255 @@ fn unexpected_cfgs_target() {
871872
"#]])
872873
.run();
873874
}
875+
876+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
877+
fn unexpected_cfgs_target_with_lint() {
878+
let p = project()
879+
.file(
880+
"Cargo.toml",
881+
r#"
882+
[package]
883+
name = "a"
884+
version = "0.0.1"
885+
edition = "2015"
886+
authors = []
887+
888+
[target."cfg(foo)".dependencies] # should not warn here
889+
b = { path = 'b' }
890+
891+
[target.'cfg(foo = "foo")'.dependencies] # should not warn here
892+
b = { path = 'b' }
893+
894+
[target."cfg(bar)".dependencies]
895+
b = { path = 'b' }
896+
897+
[lints.rust.unexpected_cfgs]
898+
level = "warn"
899+
check-cfg = ['cfg(foo, values(none(), "foo"))'] # because of this line
900+
"#,
901+
)
902+
.file(
903+
".cargo/config.toml",
904+
r#"
905+
[target."cfg(foo)"] # but it doesn't have an effect here
906+
"#,
907+
)
908+
.file("src/lib.rs", "")
909+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
910+
.file("b/src/lib.rs", "")
911+
.build();
912+
913+
p.cargo("check -Zcheck-target-cfgs")
914+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
915+
// FIXME: We should warn on multiple cfgs
916+
.with_stderr_data(str![[r#"
917+
[LOCKING] 1 package to latest compatible version
918+
[CHECKING] a v0.0.1 ([ROOT]/foo)
919+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
920+
921+
"#]])
922+
.run();
923+
}
924+
925+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
926+
fn unexpected_cfgs_target_diagnostics() {
927+
let p = project()
928+
.file(
929+
"Cargo.toml",
930+
r#"
931+
[package]
932+
name = "a"
933+
version = "0.0.1"
934+
edition = "2015"
935+
authors = []
936+
937+
[target."cfg(target_pointer_width)".dependencies]
938+
b = { path = 'b' }
939+
940+
[target.'cfg( all(foo , bar))'.dependencies]
941+
b = { path = 'b' }
942+
"#,
943+
)
944+
.file("src/lib.rs", "")
945+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
946+
.file("b/src/lib.rs", "")
947+
.build();
948+
949+
p.cargo("check -Zcheck-target-cfgs")
950+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
951+
.with_stderr_data(str![[r#"
952+
[LOCKING] 1 package to latest compatible version
953+
[CHECKING] a v0.0.1 ([ROOT]/foo)
954+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
955+
956+
"#]])
957+
.run();
958+
}
959+
960+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
961+
fn unexpected_cfgs_target_lint_level_allow() {
962+
let p = project()
963+
.file(
964+
"Cargo.toml",
965+
r#"
966+
[package]
967+
name = "a"
968+
version = "0.0.1"
969+
edition = "2015"
970+
authors = []
971+
972+
[target."cfg(foo)".dependencies]
973+
b = { path = 'b' }
974+
975+
[lints.cargo.unexpected_cfgs]
976+
level = "allow"
977+
978+
[lints.rust.unexpected_cfgs]
979+
level = "deny"
980+
"#,
981+
)
982+
.file("src/lib.rs", "")
983+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
984+
.file("b/src/lib.rs", "")
985+
.build();
986+
987+
p.cargo("check -Zcheck-target-cfgs")
988+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
989+
// FIXME: We should warn on multiple cfgs
990+
.with_stderr_data(str![[r#"
991+
[LOCKING] 1 package to latest compatible version
992+
[CHECKING] a v0.0.1 ([ROOT]/foo)
993+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
994+
995+
"#]])
996+
.run();
997+
}
998+
999+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
1000+
fn unexpected_cfgs_target_lint_level_deny() {
1001+
let p = project()
1002+
.file(
1003+
"Cargo.toml",
1004+
r#"
1005+
[package]
1006+
name = "a"
1007+
version = "0.0.1"
1008+
edition = "2015"
1009+
authors = []
1010+
1011+
[target."cfg(foo)".dependencies]
1012+
b = { path = 'b' }
1013+
1014+
[lints.cargo.unexpected_cfgs]
1015+
level = "deny"
1016+
1017+
[lints.rust.unexpected_cfgs]
1018+
level = "allow"
1019+
"#,
1020+
)
1021+
.file("src/lib.rs", "")
1022+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
1023+
.file("b/src/lib.rs", "")
1024+
.build();
1025+
1026+
p.cargo("check -Zcheck-target-cfgs")
1027+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
1028+
.with_stderr_data(str![[r#"
1029+
[LOCKING] 1 package to latest compatible version
1030+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1031+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1032+
1033+
"#]])
1034+
// FIXME: this test should fail
1035+
// .with_status(101)
1036+
.run();
1037+
}
1038+
1039+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
1040+
fn unexpected_cfgs_target_cfg_any() {
1041+
let p = project()
1042+
.file(
1043+
"Cargo.toml",
1044+
r#"
1045+
[package]
1046+
name = "a"
1047+
version = "0.0.1"
1048+
edition = "2015"
1049+
authors = []
1050+
1051+
[target."cfg(foo)".dependencies]
1052+
b = { path = 'b' }
1053+
1054+
[lints.rust.unexpected_cfgs]
1055+
level = "deny"
1056+
check-cfg = ["cfg(any())"]
1057+
"#,
1058+
)
1059+
.file("src/lib.rs", "")
1060+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
1061+
.file("b/src/lib.rs", "")
1062+
.build();
1063+
1064+
p.cargo("check -Zcheck-target-cfgs")
1065+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
1066+
.with_stderr_data(str![[r#"
1067+
[LOCKING] 1 package to latest compatible version
1068+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1069+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1070+
1071+
"#]])
1072+
.run();
1073+
}
1074+
1075+
#[cargo_test]
1076+
fn no_unexpected_cfgs_target() {
1077+
let p = project()
1078+
.file(
1079+
"Cargo.toml",
1080+
r#"
1081+
[package]
1082+
name = "a"
1083+
version = "0.0.1"
1084+
edition = "2015"
1085+
authors = []
1086+
1087+
[target."cfg(any(windows, unix))".dependencies]
1088+
b = { path = 'b' }
1089+
1090+
[target.'cfg(unix = "zoo")'.dependencies]
1091+
b = { path = 'b' }
1092+
"#,
1093+
)
1094+
.file(
1095+
".cargo/config.toml",
1096+
r#"
1097+
[target."cfg(any(windows, unix))"]
1098+
[target.'cfg(unix = "zoo")']
1099+
"#,
1100+
)
1101+
.file("src/lib.rs", "extern crate b;")
1102+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
1103+
.file("b/src/lib.rs", "")
1104+
.build();
1105+
1106+
p.cargo("check")
1107+
.with_stderr_data(str![[r#"
1108+
[LOCKING] 1 package to latest compatible version
1109+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
1110+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1111+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1112+
1113+
"#]])
1114+
.run();
1115+
1116+
p.cargo("check -Zcargo-lints")
1117+
.masquerade_as_nightly_cargo(&["requires -Zcargo-lints"])
1118+
.with_stderr_data(str![[r#"
1119+
[LOCKING] 1 package to latest compatible version
1120+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
1121+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1122+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1123+
1124+
"#]])
1125+
.run();
1126+
}

0 commit comments

Comments
 (0)