Skip to content

Commit 2676a4a

Browse files
committed
test(update): Verify extra-update behavior
1 parent 774161b commit 2676a4a

File tree

1 file changed

+180
-1
lines changed

1 file changed

+180
-1
lines changed

tests/testsuite/update.rs

Lines changed: 180 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests for the `cargo update` command.
22
33
use cargo_test_support::registry::Package;
4-
use cargo_test_support::{basic_manifest, project};
4+
use cargo_test_support::{basic_lib_manifest, basic_manifest, git, project};
55

66
#[cargo_test]
77
fn minor_update_two_places() {
@@ -910,3 +910,182 @@ required by package `foo v0.1.0 ([ROOT]/foo)`
910910
)
911911
.run();
912912
}
913+
914+
#[cargo_test]
915+
fn update_only_members_order_one() {
916+
let git_project = git::new("rustdns", |project| {
917+
project
918+
.file("Cargo.toml", &basic_lib_manifest("rustdns"))
919+
.file("src/lib.rs", "pub fn bar() {}")
920+
});
921+
922+
let workspace_toml = format!(
923+
r#"
924+
[workspace.package]
925+
version = "2.29.8"
926+
edition = "2021"
927+
publish = false
928+
929+
[workspace]
930+
members = [
931+
"rootcrate",
932+
"subcrate",
933+
]
934+
resolver = "2"
935+
936+
[workspace.dependencies]
937+
# Internal crates
938+
subcrate = {{ version = "*", path = "./subcrate" }}
939+
940+
# External dependencies
941+
rustdns = {{ version = "0.5.0", default-features = false, git = "{}" }}
942+
"#,
943+
git_project.url()
944+
);
945+
let p = project()
946+
.file("Cargo.toml", &workspace_toml)
947+
.file(
948+
"rootcrate/Cargo.toml",
949+
r#"
950+
[package]
951+
name = "rootcrate"
952+
version.workspace = true
953+
edition.workspace = true
954+
publish.workspace = true
955+
956+
[dependencies]
957+
subcrate.workspace = true
958+
"#,
959+
)
960+
.file("rootcrate/src/main.rs", "fn main() {}")
961+
.file(
962+
"subcrate/Cargo.toml",
963+
r#"
964+
[package]
965+
name = "subcrate"
966+
version.workspace = true
967+
edition.workspace = true
968+
publish.workspace = true
969+
970+
[dependencies]
971+
rustdns.workspace = true
972+
"#,
973+
)
974+
.file("subcrate/src/lib.rs", "pub foo() {}")
975+
.build();
976+
977+
// First time around we should compile both foo and bar
978+
p.cargo("generate-lockfile")
979+
.with_stderr(&format!(
980+
"[UPDATING] git repository `{}`\n",
981+
git_project.url(),
982+
))
983+
.run();
984+
// Modify a file manually, shouldn't trigger a recompile
985+
git_project.change_file("src/lib.rs", r#"pub fn bar() { println!("hello!"); }"#);
986+
// Commit the changes and make sure we don't trigger a recompile because the
987+
// lock file says not to change
988+
let repo = git2::Repository::open(&git_project.root()).unwrap();
989+
git::add(&repo);
990+
git::commit(&repo);
991+
p.change_file("Cargo.toml", &workspace_toml.replace("2.29.8", "2.29.81"));
992+
993+
p.cargo("update -p rootcrate")
994+
.with_stderr(&format!(
995+
"\
996+
[UPDATING] git repository `{}`
997+
[UPDATING] rootcrate v2.29.8 ([CWD]/rootcrate) -> v2.29.81
998+
[UPDATING] rustdns v0.5.0 ([..]) -> [..]
999+
[UPDATING] subcrate v2.29.8 ([CWD]/subcrate) -> v2.29.81",
1000+
git_project.url(),
1001+
))
1002+
.run();
1003+
}
1004+
1005+
#[cargo_test]
1006+
fn update_only_members_order_two() {
1007+
let git_project = git::new("rustdns", |project| {
1008+
project
1009+
.file("Cargo.toml", &basic_lib_manifest("rustdns"))
1010+
.file("src/lib.rs", "pub fn bar() {}")
1011+
});
1012+
1013+
let workspace_toml = format!(
1014+
r#"
1015+
[workspace.package]
1016+
version = "2.29.8"
1017+
edition = "2021"
1018+
publish = false
1019+
1020+
[workspace]
1021+
members = [
1022+
"crate2",
1023+
"crate1",
1024+
]
1025+
resolver = "2"
1026+
1027+
[workspace.dependencies]
1028+
# Internal crates
1029+
crate1 = {{ version = "*", path = "./crate1" }}
1030+
1031+
# External dependencies
1032+
rustdns = {{ version = "0.5.0", default-features = false, git = "{}" }}
1033+
"#,
1034+
git_project.url()
1035+
);
1036+
let p = project()
1037+
.file("Cargo.toml", &workspace_toml)
1038+
.file(
1039+
"crate2/Cargo.toml",
1040+
r#"
1041+
[package]
1042+
name = "crate2"
1043+
version.workspace = true
1044+
edition.workspace = true
1045+
publish.workspace = true
1046+
1047+
[dependencies]
1048+
crate1.workspace = true
1049+
"#,
1050+
)
1051+
.file("crate2/src/main.rs", "fn main() {}")
1052+
.file(
1053+
"crate1/Cargo.toml",
1054+
r#"
1055+
[package]
1056+
name = "crate1"
1057+
version.workspace = true
1058+
edition.workspace = true
1059+
publish.workspace = true
1060+
1061+
[dependencies]
1062+
rustdns.workspace = true
1063+
"#,
1064+
)
1065+
.file("crate1/src/lib.rs", "pub foo() {}")
1066+
.build();
1067+
1068+
// First time around we should compile both foo and bar
1069+
p.cargo("generate-lockfile")
1070+
.with_stderr(&format!(
1071+
"[UPDATING] git repository `{}`\n",
1072+
git_project.url(),
1073+
))
1074+
.run();
1075+
// Modify a file manually, shouldn't trigger a recompile
1076+
git_project.change_file("src/lib.rs", r#"pub fn bar() { println!("hello!"); }"#);
1077+
// Commit the changes and make sure we don't trigger a recompile because the
1078+
// lock file says not to change
1079+
let repo = git2::Repository::open(&git_project.root()).unwrap();
1080+
git::add(&repo);
1081+
git::commit(&repo);
1082+
p.change_file("Cargo.toml", &workspace_toml.replace("2.29.8", "2.29.81"));
1083+
1084+
p.cargo("update -p crate2")
1085+
.with_stderr(
1086+
"\
1087+
[UPDATING] crate1 v2.29.8 ([CWD]/crate1) -> v2.29.81
1088+
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81",
1089+
)
1090+
.run();
1091+
}

0 commit comments

Comments
 (0)