From 658343aa10e3c458a5e54aa2612f09893390014e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 3 May 2018 01:26:48 +0300 Subject: [PATCH] Don't install pre-releases by default --- src/cargo/ops/cargo_install.rs | 6 ++++- tests/testsuite/install.rs | 13 +++++---- tests/testsuite/patch.rs | 49 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index a793826cb6e..87fd1470357 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -475,7 +475,11 @@ where None => None, }; let vers = vers.as_ref().map(|s| &**s); - let dep = Dependency::parse_no_deprecated(name, vers, source.source_id())?; + let dep = Dependency::parse_no_deprecated( + name, + Some(vers.unwrap_or("*")), + source.source_id(), + )?; let deps = source.query_vec(&dep)?; match deps.iter().map(|p| p.package_id()).max() { Some(pkgid) => { diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 738b16f6a4b..d3a18999d96 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -113,17 +113,20 @@ error: some crates failed to install #[test] fn pick_max_version() { - pkg("foo", "0.0.1"); - pkg("foo", "0.0.2"); + pkg("foo", "0.1.0"); + pkg("foo", "0.2.0"); + pkg("foo", "0.2.1"); + pkg("foo", "0.2.1-pre.1"); + pkg("foo", "0.3.0-pre.2"); assert_that( cargo_process("install").arg("foo"), execs().with_status(0).with_stderr(&format!( "\ [UPDATING] registry `[..]` -[DOWNLOADING] foo v0.0.2 (registry [..]) -[INSTALLING] foo v0.0.2 -[COMPILING] foo v0.0.2 +[DOWNLOADING] foo v0.2.1 (registry [..]) +[INSTALLING] foo v0.2.1 +[COMPILING] foo v0.2.1 [FINISHED] release [optimized] target(s) in [..] [INSTALLING] {home}[..]bin[..]foo[..] warning: be sure to add `[..]` to your PATH to be able to run the installed binaries diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index 2e47ba84f08..f30f19e098f 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -1109,3 +1109,52 @@ fn patch_depends_on_another_patch() { execs().with_status(0).with_stderr("[FINISHED] [..]"), ); } + +#[test] +fn replace_prerelease() { + Package::new("bar", "1.1.0-pre.1").publish(); + let p = project("foo") + .file( + "Cargo.toml", + r#" + [workspace] + members = ["foo"] + + [patch.crates-io] + bar = { path = "./bar" } + "#, + ) + .file( + "foo/Cargo.toml", + r#" + [project] + name = "foo" + version = "0.5.0" + authors = [] + + [dependencies] + bar = "1.1.0-pre.1" + "#, + ) + .file( + "foo/src/main.rs", + " + extern crate bar; + fn main() { bar::bar() } + ", + ) + .file( + "bar/Cargo.toml", + r#" + [project] + name = "bar" + version = "1.1.0-pre.1" + authors = [] + [workspace] + "#, + ) + .file("bar/src/lib.rs", "pub fn bar() {}") + .build(); + + assert_that(p.cargo("build"), execs().with_status(0)); +}