Skip to content

Commit 4f2d1b0

Browse files
committed
Adapt deferred test for optional weak dependencies
1 parent 2539c74 commit 4f2d1b0

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

tests/testsuite/weak_dep_features.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,3 +807,95 @@ fn disabled_weak_optional_deps() {
807807
"bar inside lockfile!\n{lockfile}",
808808
);
809809
}
810+
811+
#[cargo_test]
812+
fn deferred_v4() {
813+
// A modified version of the deferred test from above to enable
814+
// an entire dependency in a deferred way.
815+
Package::new("bar", "1.0.0")
816+
.feature("feat", &["feat_dep"])
817+
.add_dep(Dependency::new("feat_dep", "1.0").optional(true))
818+
.file("src/lib.rs", "extern crate feat_dep;")
819+
.publish();
820+
Package::new("dep", "1.0.0")
821+
.add_dep(Dependency::new("bar", "1.0").optional(true))
822+
.feature("feat", &["bar?/feat"])
823+
.publish();
824+
Package::new("bar_activator", "1.0.0")
825+
.feature_dep("dep", "1.0", &["bar"])
826+
.publish();
827+
Package::new("feat_dep", "1.0.0").publish();
828+
let p = project()
829+
.file(
830+
"Cargo.toml",
831+
r#"
832+
[package]
833+
name = "foo"
834+
version = "0.1.0"
835+
836+
[dependencies]
837+
dep = { version = "1.0", features = ["feat"] }
838+
bar_activator = "1.0"
839+
"#,
840+
)
841+
.file("src/lib.rs", "")
842+
.build();
843+
844+
p.cargo("check")
845+
.with_stderr(
846+
"\
847+
[UPDATING] [..]
848+
[DOWNLOADING] crates ...
849+
[DOWNLOADED] feat_dep v1.0.0 [..]
850+
[DOWNLOADED] dep v1.0.0 [..]
851+
[DOWNLOADED] bar_activator v1.0.0 [..]
852+
[DOWNLOADED] bar v1.0.0 [..]
853+
[CHECKING] feat_dep v1.0.0
854+
[CHECKING] bar v1.0.0
855+
[CHECKING] dep v1.0.0
856+
[CHECKING] bar_activator v1.0.0
857+
[CHECKING] foo v0.1.0 [..]
858+
[FINISHED] [..]
859+
",
860+
)
861+
.run();
862+
let lockfile = p.read_lockfile();
863+
864+
assert!(
865+
lockfile.contains(r#"version = 3"#),
866+
"lockfile version is not 3!\n{lockfile}",
867+
);
868+
// Previous behavior: feat_dep is inside lockfile.
869+
assert!(
870+
lockfile.contains(r#"name = "feat_dep""#),
871+
"feat_dep not found\n{lockfile}",
872+
);
873+
// Update to new lockfile version
874+
let new_lockfile = lockfile.replace("version = 3", "version = 4");
875+
p.change_file("Cargo.lock", &new_lockfile);
876+
877+
// We should still compile feat_dep
878+
p.cargo("check")
879+
.with_stderr(
880+
"\
881+
[CHECKING] feat_dep v1.0.0
882+
[CHECKING] bar v1.0.0
883+
[CHECKING] dep v1.0.0
884+
[CHECKING] bar_activator v1.0.0
885+
[CHECKING] foo v0.1.0 [..]
886+
[FINISHED] [..]
887+
",
888+
)
889+
.run();
890+
891+
let lockfile = p.read_lockfile();
892+
assert!(
893+
lockfile.contains(r#"version = 4"#),
894+
"lockfile version is not 4!\n{lockfile}",
895+
);
896+
// New behavior: feat_dep is still there.
897+
assert!(
898+
lockfile.contains(r#"name = "feat_dep""#),
899+
"feat_dep not found\n{lockfile}",
900+
);
901+
}

0 commit comments

Comments
 (0)