Skip to content

Commit 0eff9ff

Browse files
committed
Add more unexpected target cfgs tests
1 parent 8b6ec04 commit 0eff9ff

File tree

1 file changed

+247
-0
lines changed

1 file changed

+247
-0
lines changed

tests/testsuite/cfg.rs

Lines changed: 247 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,249 @@ 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_diagnostics() {
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(target_pointer_width)".dependencies]
642+
b = { path = 'b' }
643+
644+
[target.'cfg( all(foo , bar))'.dependencies]
645+
b = { path = 'b' }
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+
.with_stderr_data(str![[r#"
656+
[LOCKING] 1 package to latest compatible version
657+
[CHECKING] a v0.0.1 ([ROOT]/foo)
658+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
659+
660+
"#]])
661+
.run();
662+
}
663+
664+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
665+
fn unexpected_cfgs_target_lint_level_allow() {
666+
let p = project()
667+
.file(
668+
"Cargo.toml",
669+
r#"
670+
[package]
671+
name = "a"
672+
version = "0.0.1"
673+
edition = "2015"
674+
authors = []
675+
676+
[target."cfg(foo)".dependencies]
677+
b = { path = 'b' }
678+
679+
[lints.rust.unexpected_cfgs]
680+
level = "allow"
681+
"#,
682+
)
683+
.file("src/lib.rs", "")
684+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
685+
.file("b/src/lib.rs", "")
686+
.build();
687+
688+
p.cargo("check -Zcheck-target-cfgs")
689+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
690+
// FIXME: We should warn on multiple 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+
.run();
698+
}
699+
700+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
701+
fn unexpected_cfgs_target_lint_level_deny() {
702+
let p = project()
703+
.file(
704+
"Cargo.toml",
705+
r#"
706+
[package]
707+
name = "a"
708+
version = "0.0.1"
709+
edition = "2015"
710+
authors = []
711+
712+
[target."cfg(foo)".dependencies]
713+
b = { path = 'b' }
714+
715+
[lints.rust.unexpected_cfgs]
716+
level = "deny"
717+
"#,
718+
)
719+
.file("src/lib.rs", "")
720+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
721+
.file("b/src/lib.rs", "")
722+
.build();
723+
724+
p.cargo("check -Zcheck-target-cfgs")
725+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
726+
.with_stderr_data(str![[r#"
727+
[LOCKING] 1 package to latest compatible version
728+
[CHECKING] a v0.0.1 ([ROOT]/foo)
729+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
730+
731+
"#]])
732+
// FIXME: this test should fail
733+
// .with_status(101)
734+
.run();
735+
}
736+
737+
#[cargo_test(nightly, reason = "--print=check-cfg is unstable in rustc")]
738+
fn unexpected_cfgs_target_cfg_any() {
739+
let p = project()
740+
.file(
741+
"Cargo.toml",
742+
r#"
743+
[package]
744+
name = "a"
745+
version = "0.0.1"
746+
edition = "2015"
747+
authors = []
748+
749+
[target."cfg(foo)".dependencies]
750+
b = { path = 'b' }
751+
752+
[lints.rust.unexpected_cfgs]
753+
level = "deny"
754+
check-cfg = ["cfg(any())"]
755+
"#,
756+
)
757+
.file("src/lib.rs", "")
758+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
759+
.file("b/src/lib.rs", "")
760+
.build();
761+
762+
p.cargo("check -Zcheck-target-cfgs")
763+
.masquerade_as_nightly_cargo(&["requires -Zcheck-target-cfgs"])
764+
.with_stderr_data(str![[r#"
765+
[LOCKING] 1 package to latest compatible version
766+
[CHECKING] a v0.0.1 ([ROOT]/foo)
767+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
768+
769+
"#]])
770+
.run();
771+
}
772+
773+
#[cargo_test]
774+
fn no_unexpected_cfgs_target() {
775+
let p = project()
776+
.file(
777+
"Cargo.toml",
778+
r#"
779+
[package]
780+
name = "a"
781+
version = "0.0.1"
782+
edition = "2015"
783+
authors = []
784+
785+
[target."cfg(any(windows, unix))".dependencies]
786+
b = { path = 'b' }
787+
788+
[target.'cfg(unix = "zoo")'.dependencies]
789+
b = { path = 'b' }
790+
"#,
791+
)
792+
.file(
793+
".cargo/config.toml",
794+
r#"
795+
[target."cfg(any(windows, unix))"]
796+
[target.'cfg(unix = "zoo")']
797+
"#,
798+
)
799+
.file("src/lib.rs", "extern crate b;")
800+
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
801+
.file("b/src/lib.rs", "")
802+
.build();
803+
804+
p.cargo("check")
805+
.with_stderr_data(str![[r#"
806+
[LOCKING] 1 package to latest compatible version
807+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
808+
[CHECKING] a v0.0.1 ([ROOT]/foo)
809+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
810+
811+
"#]])
812+
.run();
813+
814+
p.cargo("check -Zcargo-lints")
815+
.masquerade_as_nightly_cargo(&["requires -Zcargo-lints"])
816+
.with_stderr_data(str![[r#"
817+
[LOCKING] 1 package to latest compatible version
818+
[CHECKING] b v0.0.1 ([ROOT]/foo/b)
819+
[CHECKING] a v0.0.1 ([ROOT]/foo)
820+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
821+
822+
"#]])
823+
.run();
824+
}

0 commit comments

Comments
 (0)