cargo/tests/testsuite/update.rs

398 lines
9.5 KiB
Rust
Raw Normal View History

use std::fs::File;
use std::io::prelude::*;
use support::registry::Package;
use support::{basic_manifest, project};
#[test]
fn minor_update_two_places() {
Package::new("log", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
log = "0.1"
foo = { path = "foo" }
"#,
).file("src/lib.rs", "")
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
log = "0.1"
"#,
).file("foo/src/lib.rs", "")
.build();
p.cargo("build").run();
Package::new("log", "0.1.1").publish();
File::create(p.root().join("foo/Cargo.toml"))
.unwrap()
.write_all(
br#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
log = "0.1.1"
"#,
).unwrap();
p.cargo("build").run();
}
#[test]
fn transitive_minor_update() {
Package::new("log", "0.1.0").publish();
Package::new("serde", "0.1.0").dep("log", "0.1").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
serde = "0.1"
log = "0.1"
foo = { path = "foo" }
"#,
).file("src/lib.rs", "")
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
serde = "0.1"
"#,
).file("foo/src/lib.rs", "")
.build();
p.cargo("build").run();
Package::new("log", "0.1.1").publish();
Package::new("serde", "0.1.1").dep("log", "0.1.1").publish();
// Note that `serde` isn't actually updated here! The default behavior for
// `update` right now is to as conservatively as possible attempt to satisfy
// an update. In this case we previously locked the dependency graph to `log
// 0.1.0`, but nothing on the command line says we're allowed to update
// that. As a result the update of `serde` here shouldn't update to `serde
// 0.1.1` as that would also force an update to `log 0.1.1`.
//
// Also note that this is probably counterintuitive and weird. We may wish
// to change this one day.
p.cargo("update -p serde")
.with_stderr(
"\
[UPDATING] `[..]` index
",
).run();
}
#[test]
fn conservative() {
Package::new("log", "0.1.0").publish();
Package::new("serde", "0.1.0").dep("log", "0.1").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
serde = "0.1"
log = "0.1"
foo = { path = "foo" }
"#,
).file("src/lib.rs", "")
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
serde = "0.1"
"#,
).file("foo/src/lib.rs", "")
.build();
p.cargo("build").run();
Package::new("log", "0.1.1").publish();
Package::new("serde", "0.1.1").dep("log", "0.1").publish();
p.cargo("update -p serde")
.with_stderr(
"\
[UPDATING] `[..]` index
[UPDATING] serde v0.1.0 -> v0.1.1
",
).run();
}
#[test]
fn update_via_new_dep() {
Package::new("log", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
log = "0.1"
# foo = { path = "foo" }
"#,
).file("src/lib.rs", "")
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
log = "0.1.1"
"#,
).file("foo/src/lib.rs", "")
.build();
p.cargo("build").run();
Package::new("log", "0.1.1").publish();
p.uncomment_root_manifest();
p.cargo("build").env("RUST_LOG", "cargo=trace").run();
}
#[test]
fn update_via_new_member() {
Package::new("log", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[workspace]
# members = [ "foo" ]
[dependencies]
log = "0.1"
"#,
).file("src/lib.rs", "")
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
log = "0.1.1"
"#,
).file("foo/src/lib.rs", "")
.build();
p.cargo("build").run();
Package::new("log", "0.1.1").publish();
p.uncomment_root_manifest();
p.cargo("build").run();
}
#[test]
fn add_dep_deep_new_requirement() {
Package::new("log", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
log = "0.1"
# bar = "0.1"
"#,
).file("src/lib.rs", "")
.build();
p.cargo("build").run();
Package::new("log", "0.1.1").publish();
Package::new("bar", "0.1.0").dep("log", "0.1.1").publish();
p.uncomment_root_manifest();
p.cargo("build").run();
}
#[test]
fn everything_real_deep() {
Package::new("log", "0.1.0").publish();
Package::new("foo", "0.1.0").dep("log", "0.1").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
foo = "0.1"
# bar = "0.1"
"#,
).file("src/lib.rs", "")
.build();
p.cargo("build").run();
Package::new("log", "0.1.1").publish();
Package::new("bar", "0.1.0").dep("log", "0.1.1").publish();
p.uncomment_root_manifest();
p.cargo("build").run();
}
#[test]
fn change_package_version() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "a-foo"
version = "0.2.0-alpha"
authors = []
[dependencies]
bar = { path = "bar", version = "0.2.0-alpha" }
"#,
).file("src/lib.rs", "")
2018-07-24 22:35:01 +00:00
.file("bar/Cargo.toml", &basic_manifest("bar", "0.2.0-alpha"))
.file("bar/src/lib.rs", "")
.file(
"Cargo.lock",
r#"
[[package]]
name = "foo"
version = "0.2.0"
dependencies = ["bar 0.2.0"]
[[package]]
name = "bar"
version = "0.2.0"
"#,
).build();
p.cargo("build").run();
}
2018-03-24 19:04:19 +00:00
#[test]
fn update_precise() {
Package::new("log", "0.1.0").publish();
Package::new("serde", "0.1.0").publish();
Package::new("serde", "0.2.1").publish();
let p = project()
2018-03-24 19:04:19 +00:00
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
[dependencies]
serde = "0.2"
foo = { path = "foo" }
"#,
).file("src/lib.rs", "")
2018-03-24 19:04:19 +00:00
.file(
"foo/Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
serde = "0.1"
"#,
).file("foo/src/lib.rs", "")
2018-03-24 19:04:19 +00:00
.build();
p.cargo("build").run();
2018-03-24 19:04:19 +00:00
Package::new("serde", "0.2.0").publish();
p.cargo("update -p serde:0.2.1 --precise 0.2.0")
.with_stderr(
2018-03-24 19:04:19 +00:00
"\
[UPDATING] `[..]` index
2018-03-24 19:04:19 +00:00
[UPDATING] serde v0.2.1 -> v0.2.0
",
).run();
2018-03-24 19:04:19 +00:00
}
2018-10-17 20:29:51 +00:00
#[test]
fn preserve_top_comment() {
let p = project().file("src/lib.rs", "").build();
p.cargo("update").run();
let mut lockfile = p.read_file("Cargo.lock");
lockfile.insert_str(0, "# @generated\n");
2018-10-18 05:44:12 +00:00
lockfile.insert_str(0, "# some other comment\n");
2018-10-17 20:29:51 +00:00
println!("saving Cargo.lock contents:\n{}", lockfile);
p.change_file("Cargo.lock", &lockfile);
p.cargo("update").run();
let lockfile2 = p.read_file("Cargo.lock");
2018-10-17 20:29:51 +00:00
println!("loaded Cargo.lock contents:\n{}", lockfile2);
assert!(lockfile == lockfile2);
2018-10-17 20:29:51 +00:00
}