]> git.proxmox.com Git - cargo.git/commitdiff
add test for failing package
authorAlex Burka <aburka@seas.upenn.edu>
Wed, 12 Jul 2017 20:28:33 +0000 (16:28 -0400)
committerAlex Burka <aburka@seas.upenn.edu>
Wed, 12 Jul 2017 20:28:33 +0000 (16:28 -0400)
src/cargo/ops/cargo_install.rs
tests/install.rs

index afde6edde1bef8bb2ccfac79518e7fbd609af354..7d91d032d96e9f7c09ed56e2d3a656c5dbd646b8 100644 (file)
@@ -10,7 +10,6 @@ use std::sync::Arc;
 
 use semver::Version;
 use tempdir::TempDir;
-use termcolor::Color::Red;
 use toml;
 
 use core::{SourceId, Source, Package, Dependency, PackageIdSpec};
@@ -64,9 +63,9 @@ pub fn install(root: Option<&str>,
     let root = resolve_root(root, opts.config)?;
     let map = SourceConfigMap::new(opts.config)?;
 
-    if krates.len() <= 1 {
+    let installed_anything = if krates.len() <= 1 {
         install_one(root.clone(), map, krates.into_iter().next(), source_id, vers, opts,
-                    force, true)?;
+                    force, true).is_ok()
     } else {
         let mut succeeded = vec![];
         let mut failed = vec![];
@@ -84,27 +83,35 @@ pub fn install(root: Option<&str>,
             first = false;
         }
 
+        let mut summary = vec![];
         if !succeeded.is_empty() {
-            opts.config.shell().status("Successfully installed", succeeded.join(", "))?;
+            summary.push(format!("Successfully installed {}!", succeeded.join(", ")));
         }
         if !failed.is_empty() {
-            opts.config.shell().status_with_color("Failed to install", failed.join(", "), Red)?;
+            summary.push(format!("Failed to install {} (see error(s) above).", failed.join(", ")));
         }
-    }
+        if !succeeded.is_empty() || !failed.is_empty() {
+            opts.config.shell().status("\nSummary:", summary.join(" "))?;
+        }
+
+        !succeeded.is_empty()
+    };
 
-    // Print a warning that if this directory isn't in PATH that they won't be
-    // able to run these commands.
-    let dst = metadata(opts.config, &root)?.parent().join("bin");
-    let path = env::var_os("PATH").unwrap_or(OsString::new());
-    for path in env::split_paths(&path) {
-        if path == dst {
-            return Ok(())
+    if installed_anything {
+        // Print a warning that if this directory isn't in PATH that they won't be
+        // able to run these commands.
+        let dst = metadata(opts.config, &root)?.parent().join("bin");
+        let path = env::var_os("PATH").unwrap_or(OsString::new());
+        for path in env::split_paths(&path) {
+            if path == dst {
+                return Ok(())
+            }
         }
-    }
 
-    opts.config.shell().warn(&format!("be sure to add `{}` to your PATH to be \
-                                       able to run the installed binaries",
-                                       dst.display()))?;
+        opts.config.shell().warn(&format!("be sure to add `{}` to your PATH to be \
+                                           able to run the installed binaries",
+                                           dst.display()))?;
+    }
 
     Ok(())
 }
index 93dd71fc137166977cb34366af2fbe29987a067b..bd4b20a63fc9ed42536cf9c12cba9c269bff6143 100644 (file)
@@ -57,9 +57,9 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
 #[test]
 fn multiple_pkgs() {
     pkg("foo", "0.0.1");
-    pkg("bar", "0.0.1");
+    pkg("bar", "0.0.2");
 
-    assert_that(cargo_process("install").arg("foo").arg("bar"),
+    assert_that(cargo_process("install").args(&["foo", "bar", "baz"]),
                 execs().with_status(0).with_stderr(&format!("\
 [UPDATING] registry `[..]`
 [DOWNLOADING] foo v0.0.1 (registry file://[..])
@@ -67,12 +67,14 @@ fn multiple_pkgs() {
 [COMPILING] foo v0.0.1
 [FINISHED] release [optimized] target(s) in [..]
 [INSTALLING] {home}[..]bin[..]foo[..]
-[DOWNLOADING] bar v0.0.1 (registry file://[..])
-[INSTALLING] bar v0.0.1
-[COMPILING] bar v0.0.1
+[DOWNLOADING] bar v0.0.2 (registry file://[..])
+[INSTALLING] bar v0.0.2
+[COMPILING] bar v0.0.2
 [FINISHED] release [optimized] target(s) in [..]
 [INSTALLING] {home}[..]bin[..]bar[..]
-Successfully installed foo, bar
+error: could not find `baz` in `registry [..]`
+   
+Summary: Successfully installed foo, bar! Failed to install baz (see error(s) above).
 warning: be sure to add `[..]` to your PATH to be able to run the installed binaries
 ",
         home = cargo_home().display())));