Skip to content

Commit 899067f

Browse files
committed
Add a cyclical dev-dep test.
1 parent 76f0d68 commit 899067f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/testsuite/features2.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,77 @@ fn build_script_runtime_features() {
609609
.masquerade_as_nightly_cargo()
610610
.run();
611611
}
612+
613+
#[cargo_test]
614+
fn cyclical_dev_dep() {
615+
// Check how a cyclical dev-dependency will work.
616+
let p = project()
617+
.file(
618+
"Cargo.toml",
619+
r#"
620+
[package]
621+
name = "foo"
622+
version = "0.1.0"
623+
edition = "2018"
624+
625+
[features]
626+
dev = []
627+
628+
[dev-dependencies]
629+
foo = { path = '.', features = ["dev"] }
630+
"#,
631+
)
632+
.file(
633+
"src/lib.rs",
634+
r#"
635+
pub fn assert_dev(enabled: bool) {
636+
assert_eq!(enabled, cfg!(feature="dev"));
637+
}
638+
639+
#[test]
640+
fn test_in_lib() {
641+
assert_dev(true);
642+
}
643+
"#,
644+
)
645+
.file(
646+
"src/main.rs",
647+
r#"
648+
fn main() {
649+
let expected: bool = std::env::args().skip(1).next().unwrap().parse().unwrap();
650+
foo::assert_dev(expected);
651+
}
652+
"#,
653+
)
654+
.file(
655+
"tests/t1.rs",
656+
r#"
657+
#[test]
658+
fn integration_links() {
659+
foo::assert_dev(true);
660+
// The lib linked with main.rs will also be unified.
661+
let s = std::process::Command::new("target/debug/foo")
662+
.arg("true")
663+
.status().unwrap();
664+
assert!(s.success());
665+
}
666+
"#,
667+
)
668+
.build();
669+
670+
// Old way unifies features.
671+
p.cargo("run true").run();
672+
673+
// Should decouple main.
674+
p.cargo("run -Zfeatures=dev_dep false")
675+
.masquerade_as_nightly_cargo()
676+
.run();
677+
678+
// dev feature should always be enabled in tests.
679+
p.cargo("test").run();
680+
681+
// And this should be no different.
682+
p.cargo("test -Zfeatures=dev_dep")
683+
.masquerade_as_nightly_cargo()
684+
.run();
685+
}

0 commit comments

Comments
 (0)