Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/bin/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Options {
flag_list: bool,
flag_force: bool,

arg_crate: Option<String>,
arg_crate: Vec<String>,
flag_vers: Option<String>,

flag_git: Option<String>,
Expand All @@ -32,7 +32,7 @@ pub const USAGE: &'static str = "
Install a Rust binary

Usage:
cargo install [options] [<crate>]
cargo install [options] [<crate>...]
cargo install [options] --list

Specifying what crate to install:
Expand Down Expand Up @@ -123,20 +123,20 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
SourceId::for_git(&url, gitref)
} else if let Some(path) = options.flag_path {
try!(SourceId::for_path(&config.cwd().join(path)))
} else if options.arg_crate == None {
} else if options.arg_crate.is_empty() {
try!(SourceId::for_path(&config.cwd()))
} else {
try!(SourceId::for_central(config))
};

let krate = options.arg_crate.as_ref().map(|s| &s[..]);
let krates = options.arg_crate.iter().map(|s| &s[..]).collect::<Vec<_>>();
let vers = options.flag_vers.as_ref().map(|s| &s[..]);
let root = options.flag_root.as_ref().map(|s| &s[..]);

if options.flag_list {
try!(ops::install_list(root, config));
} else {
try!(ops::install(root, krate, &source, vers, &compile_opts, options.flag_force));
try!(ops::install(root, krates, &source, vers, &compile_opts, options.flag_force));
}
Ok(None)
}
40 changes: 39 additions & 1 deletion tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,45 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
}

#[test]
fn pick_max_version() {
test!(multiple_pkgs {
pkg("foo", "0.0.1");
pkg("bar", "0.0.1");

assert_that(cargo_process("install").arg("foo").arg("bar"),
execs().with_status(0).with_stdout(&format!("\
{updating} registry `[..]`
{downloading} foo v0.0.1 (registry file://[..])
{compiling} foo v0.0.1 (registry file://[..])
{installing} {home}[..]bin[..]foo[..]
{downloading} bar v0.0.1 (registry file://[..])
{compiling} bar v0.0.1 (registry file://[..])
{installing} {home}[..]bin[..]bar[..]
",
updating = UPDATING,
downloading = DOWNLOADING,
compiling = COMPILING,
installing = INSTALLING,
home = cargo_home().display())));
assert_that(cargo_home(), has_installed_exe("foo"));
assert_that(cargo_home(), has_installed_exe("bar"));

assert_that(cargo_process("uninstall").arg("foo"),
execs().with_status(0).with_stdout(&format!("\
{removing} {home}[..]bin[..]foo[..]
",
removing = REMOVING,
home = cargo_home().display())));
assert_that(cargo_process("uninstall").arg("bar"),
execs().with_status(0).with_stdout(&format!("\
{removing} {home}[..]bin[..]bar[..]
",
removing = REMOVING,
home = cargo_home().display())));
assert_that(cargo_home(), is_not(has_installed_exe("foo")));
assert_that(cargo_home(), is_not(has_installed_exe("bar")));
});

test!(pick_max_version {
pkg("foo", "0.0.1");
pkg("foo", "0.0.2");

Expand Down