Skip to content

Commit f87928a

Browse files
committed
test(update): Verify extra-update behavior
1 parent 2761949 commit f87928a

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() {
@@ -873,3 +873,182 @@ required by package `foo v0.1.0 ([ROOT]/foo)`
873873
)
874874
.run();
875875
}
876+
877+
#[cargo_test]
878+
fn update_only_members_order_one() {
879+
let git_project = git::new("rustdns", |project| {
880+
project
881+
.file("Cargo.toml", &basic_lib_manifest("rustdns"))
882+
.file("src/lib.rs", "pub fn bar() {}")
883+
});
884+
885+
let workspace_toml = format!(
886+
r#"
887+
[workspace.package]
888+
version = "2.29.8"
889+
edition = "2021"
890+
publish = false
891+
892+
[workspace]
893+
members = [
894+
"rootcrate",
895+
"subcrate",
896+
]
897+
resolver = "2"
898+
899+
[workspace.dependencies]
900+
# Internal crates
901+
subcrate = {{ version = "*", path = "./subcrate" }}
902+
903+
# External dependencies
904+
rustdns = {{ version = "0.5.0", default-features = false, git = "{}" }}
905+
"#,
906+
git_project.url()
907+
);
908+
let p = project()
909+
.file("Cargo.toml", &workspace_toml)
910+
.file(
911+
"rootcrate/Cargo.toml",
912+
r#"
913+
[package]
914+
name = "rootcrate"
915+
version.workspace = true
916+
edition.workspace = true
917+
publish.workspace = true
918+
919+
[dependencies]
920+
subcrate.workspace = true
921+
"#,
922+
)
923+
.file("rootcrate/src/main.rs", "fn main() {}")
924+
.file(
925+
"subcrate/Cargo.toml",
926+
r#"
927+
[package]
928+
name = "subcrate"
929+
version.workspace = true
930+
edition.workspace = true
931+
publish.workspace = true
932+
933+
[dependencies]
934+
rustdns.workspace = true
935+
"#,
936+
)
937+
.file("subcrate/src/lib.rs", "pub foo() {}")
938+
.build();
939+
940+
// First time around we should compile both foo and bar
941+
p.cargo("generate-lockfile")
942+
.with_stderr(&format!(
943+
"[UPDATING] git repository `{}`\n",
944+
git_project.url(),
945+
))
946+
.run();
947+
// Modify a file manually, shouldn't trigger a recompile
948+
git_project.change_file("src/lib.rs", r#"pub fn bar() { println!("hello!"); }"#);
949+
// Commit the changes and make sure we don't trigger a recompile because the
950+
// lock file says not to change
951+
let repo = git2::Repository::open(&git_project.root()).unwrap();
952+
git::add(&repo);
953+
git::commit(&repo);
954+
p.change_file("Cargo.toml", &workspace_toml.replace("2.29.8", "2.29.81"));
955+
956+
p.cargo("update -p rootcrate")
957+
.with_stderr(&format!(
958+
"\
959+
[UPDATING] git repository `{}`
960+
[UPDATING] rootcrate v2.29.8 ([CWD]/rootcrate) -> v2.29.81
961+
[UPDATING] rustdns v0.5.0 ([..]) -> [..]
962+
[UPDATING] subcrate v2.29.8 ([CWD]/subcrate) -> v2.29.81",
963+
git_project.url(),
964+
))
965+
.run();
966+
}
967+
968+
#[cargo_test]
969+
fn update_only_members_order_two() {
970+
let git_project = git::new("rustdns", |project| {
971+
project
972+
.file("Cargo.toml", &basic_lib_manifest("rustdns"))
973+
.file("src/lib.rs", "pub fn bar() {}")
974+
});
975+
976+
let workspace_toml = format!(
977+
r#"
978+
[workspace.package]
979+
version = "2.29.8"
980+
edition = "2021"
981+
publish = false
982+
983+
[workspace]
984+
members = [
985+
"crate2",
986+
"crate1",
987+
]
988+
resolver = "2"
989+
990+
[workspace.dependencies]
991+
# Internal crates
992+
crate1 = {{ version = "*", path = "./crate1" }}
993+
994+
# External dependencies
995+
rustdns = {{ version = "0.5.0", default-features = false, git = "{}" }}
996+
"#,
997+
git_project.url()
998+
);
999+
let p = project()
1000+
.file("Cargo.toml", &workspace_toml)
1001+
.file(
1002+
"crate2/Cargo.toml",
1003+
r#"
1004+
[package]
1005+
name = "crate2"
1006+
version.workspace = true
1007+
edition.workspace = true
1008+
publish.workspace = true
1009+
1010+
[dependencies]
1011+
crate1.workspace = true
1012+
"#,
1013+
)
1014+
.file("crate2/src/main.rs", "fn main() {}")
1015+
.file(
1016+
"crate1/Cargo.toml",
1017+
r#"
1018+
[package]
1019+
name = "crate1"
1020+
version.workspace = true
1021+
edition.workspace = true
1022+
publish.workspace = true
1023+
1024+
[dependencies]
1025+
rustdns.workspace = true
1026+
"#,
1027+
)
1028+
.file("crate1/src/lib.rs", "pub foo() {}")
1029+
.build();
1030+
1031+
// First time around we should compile both foo and bar
1032+
p.cargo("generate-lockfile")
1033+
.with_stderr(&format!(
1034+
"[UPDATING] git repository `{}`\n",
1035+
git_project.url(),
1036+
))
1037+
.run();
1038+
// Modify a file manually, shouldn't trigger a recompile
1039+
git_project.change_file("src/lib.rs", r#"pub fn bar() { println!("hello!"); }"#);
1040+
// Commit the changes and make sure we don't trigger a recompile because the
1041+
// lock file says not to change
1042+
let repo = git2::Repository::open(&git_project.root()).unwrap();
1043+
git::add(&repo);
1044+
git::commit(&repo);
1045+
p.change_file("Cargo.toml", &workspace_toml.replace("2.29.8", "2.29.81"));
1046+
1047+
p.cargo("update -p crate2")
1048+
.with_stderr(
1049+
"\
1050+
[UPDATING] crate1 v2.29.8 ([CWD]/crate1) -> v2.29.81
1051+
[UPDATING] crate2 v2.29.8 ([CWD]/crate2) -> v2.29.81",
1052+
)
1053+
.run();
1054+
}

0 commit comments

Comments
 (0)