Skip to content

Commit 0ecf43a

Browse files
committed
Add more unexpected target cfgs tests
1 parent 1c30e77 commit 0ecf43a

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
@@ -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,249 @@ 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.rust.unexpected_cfgs]
976+
level = "allow"
977+
"#,
978+
)
979+
.file("src/lib.rs", "")
980+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
981+
.file("b/src/lib.rs", "")
982+
.build();
983+
984+
p.cargo("check -Zcheck-target-cfgs")
985+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
986+
// FIXME: We should warn on multiple cfgs
987+
.with_stderr_data(str![[r#"
988+
[LOCKING] 1 package to latest compatible version
989+
[CHECKING] a v0.0.1 ([ROOT]/foo)
990+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
991+
992+
"#]])
993+
.run();
994+
}
995+
996+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
997+
fn unexpected_cfgs_target_lint_level_deny() {
998+
let p = project()
999+
.file(
1000+
"Cargo.toml",
1001+
r#"
1002+
[package]
1003+
name = "a"
1004+
version = "0.0.1"
1005+
edition = "2015"
1006+
authors = []
1007+
1008+
[target."cfg(foo)".dependencies]
1009+
b = { path = 'b' }
1010+
1011+
[lints.rust.unexpected_cfgs]
1012+
level = "deny"
1013+
"#,
1014+
)
1015+
.file("src/lib.rs", "")
1016+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
1017+
.file("b/src/lib.rs", "")
1018+
.build();
1019+
1020+
p.cargo("check -Zcheck-target-cfgs")
1021+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
1022+
.with_stderr_data(str![[r#"
1023+
[LOCKING] 1 package to latest compatible version
1024+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1025+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1026+
1027+
"#]])
1028+
// FIXME: this test should fail
1029+
// .with_status(101)
1030+
.run();
1031+
}
1032+
1033+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
1034+
fn unexpected_cfgs_target_cfg_any() {
1035+
let p = project()
1036+
.file(
1037+
"Cargo.toml",
1038+
r#"
1039+
[package]
1040+
name = "a"
1041+
version = "0.0.1"
1042+
edition = "2015"
1043+
authors = []
1044+
1045+
[target."cfg(foo)".dependencies]
1046+
b = { path = 'b' }
1047+
1048+
[lints.rust.unexpected_cfgs]
1049+
level = "deny"
1050+
check-cfg = ["cfg(any())"]
1051+
"#,
1052+
)
1053+
.file("src/lib.rs", "")
1054+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
1055+
.file("b/src/lib.rs", "")
1056+
.build();
1057+
1058+
p.cargo("check -Zcheck-target-cfgs")
1059+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
1060+
.with_stderr_data(str![[r#"
1061+
[LOCKING] 1 package to latest compatible version
1062+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1063+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1064+
1065+
"#]])
1066+
.run();
1067+
}
1068+
1069+
#[cargo_test]
1070+
fn no_unexpected_cfgs_target() {
1071+
let p = project()
1072+
.file(
1073+
"Cargo.toml",
1074+
r#"
1075+
[package]
1076+
name = "a"
1077+
version = "0.0.1"
1078+
edition = "2015"
1079+
authors = []
1080+
1081+
[target."cfg(any(windows, unix))".dependencies]
1082+
b = { path = 'b' }
1083+
1084+
[target.'cfg(unix = "zoo")'.dependencies]
1085+
b = { path = 'b' }
1086+
"#,
1087+
)
1088+
.file(
1089+
".cargo/config.toml",
1090+
r#"
1091+
[target."cfg(any(windows, unix))"]
1092+
[target.'cfg(unix = "zoo")']
1093+
"#,
1094+
)
1095+
.file("src/lib.rs", "extern crate b;")
1096+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
1097+
.file("b/src/lib.rs", "")
1098+
.build();
1099+
1100+
p.cargo("check")
1101+
.with_stderr_data(str![[r#"
1102+
[LOCKING] 1 package to latest compatible version
1103+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
1104+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1105+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1106+
1107+
"#]])
1108+
.run();
1109+
1110+
p.cargo("check -Zcargo-lints")
1111+
.masquerade_as_nightly_cargo(&["requires -Zcargo-lints"])
1112+
.with_stderr_data(str![[r#"
1113+
[LOCKING] 1 package to latest compatible version
1114+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
1115+
[CHECKING] a v0.0.1 ([ROOT]/foo)
1116+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1117+
1118+
"#]])
1119+
.run();
1120+
}

0 commit comments

Comments
 (0)