2017-09-28 17:43:40 +00:00
use std ::fs ::{ self , File , OpenOptions } ;
2015-10-05 22:29:15 +00:00
use std ::io ::prelude ::* ;
2019-02-03 04:01:23 +00:00
use git2 ;
use crate ::support ;
2018-12-06 19:17:36 +00:00
use crate ::support ::cross_compile ;
use crate ::support ::git ;
use crate ::support ::install ::{ assert_has_installed_exe , assert_has_not_installed_exe , cargo_home } ;
use crate ::support ::paths ;
use crate ::support ::registry ::Package ;
use crate ::support ::{ basic_manifest , cargo_process , project } ;
2015-10-05 22:29:15 +00:00
2015-11-11 02:08:06 +00:00
fn pkg ( name : & str , vers : & str ) {
Package ::new ( name , vers )
. file ( " src/lib.rs " , " " )
2018-08-28 09:20:03 +00:00
. file (
" src/main.rs " ,
& format! ( " extern crate {} ; fn main() {{ }} " , name ) ,
2018-12-08 11:19:47 +00:00
)
. publish ( ) ;
2015-10-05 22:29:15 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn simple ( ) {
2015-11-11 02:08:06 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 09:23:57 +00:00
[ UPDATING ] ` [ .. ] ` index
2018-09-14 20:33:18 +00:00
[ DOWNLOADING ] crates .. .
[ DOWNLOADED ] foo v0 . 0.1 ( registry [ .. ] )
2017-01-24 06:49:50 +00:00
[ INSTALLING ] foo v0 . 0.1
2016-02-03 18:54:07 +00:00
[ COMPILING ] foo v0 . 0.1
2016-07-25 23:30:03 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ INSTALLING ] [ CWD ] / home / . cargo / bin / foo [ EXE ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` foo v0 . 0.1 ` ( executable ` foo [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2015-10-05 22:29:15 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo " )
2018-09-08 02:42:26 +00:00
. with_stderr ( " [REMOVING] [CWD]/home/.cargo/bin/foo[EXE] " )
2018-08-29 17:56:48 +00:00
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_not_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-06-23 23:30:05 +00:00
fn multiple_pkgs ( ) {
2016-04-21 16:23:33 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
2017-07-12 20:28:33 +00:00
pkg ( " bar " , " 0.0.2 " ) ;
2016-04-21 16:23:33 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo bar baz " )
. with_status ( 101 )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 09:23:57 +00:00
[ UPDATING ] ` [ .. ] ` index
2018-09-14 20:33:18 +00:00
[ DOWNLOADING ] crates .. .
[ DOWNLOADED ] foo v0 . 0.1 ( registry ` [ CWD ] / registry ` )
2017-06-23 23:30:05 +00:00
[ INSTALLING ] foo v0 . 0.1
[ COMPILING ] foo v0 . 0.1
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ INSTALLING ] [ CWD ] / home / . cargo / bin / foo [ EXE ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` foo v0 . 0.1 ` ( executable ` foo [ EXE ] ` )
2018-09-14 20:33:18 +00:00
[ DOWNLOADING ] crates .. .
[ DOWNLOADED ] bar v0 . 0.2 ( registry ` [ CWD ] / registry ` )
2017-07-12 20:28:33 +00:00
[ INSTALLING ] bar v0 . 0.2
[ COMPILING ] bar v0 . 0.2
2017-06-23 23:30:05 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ INSTALLING ] [ CWD ] / home / . cargo / bin / bar [ EXE ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` bar v0 . 0.2 ` ( executable ` bar [ EXE ] ` )
[ ERROR ] could not find ` baz ` in registry ` [ .. ] `
2017-12-08 19:31:17 +00:00
[ SUMMARY ] Successfully installed foo , bar ! Failed to install baz ( see error ( s ) above ) .
2019-03-31 00:33:35 +00:00
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
[ ERROR ] some crates failed to install
2016-04-21 16:23:33 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
assert_has_installed_exe ( cargo_home ( ) , " bar " ) ;
2016-04-21 16:23:33 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo bar " )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ REMOVING ] [ CWD ] / home / . cargo / bin / foo [ EXE ]
[ REMOVING ] [ CWD ] / home / . cargo / bin / bar [ EXE ]
2017-12-08 19:31:17 +00:00
[ SUMMARY ] Successfully uninstalled foo , bar !
2016-04-21 16:23:33 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-10-11 19:34:44 +00:00
2018-08-29 06:32:28 +00:00
assert_has_not_installed_exe ( cargo_home ( ) , " foo " ) ;
assert_has_not_installed_exe ( cargo_home ( ) , " bar " ) ;
2017-06-23 23:30:05 +00:00
}
2016-04-21 16:23:33 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-06-23 23:30:05 +00:00
fn pick_max_version ( ) {
2018-05-02 22:26:48 +00:00
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 " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 09:23:57 +00:00
[ UPDATING ] ` [ .. ] ` index
2018-09-14 20:33:18 +00:00
[ DOWNLOADING ] crates .. .
[ DOWNLOADED ] foo v0 . 2.1 ( registry [ .. ] )
2018-05-02 22:26:48 +00:00
[ INSTALLING ] foo v0 . 2.1
[ COMPILING ] foo v0 . 2.1
2016-07-25 23:30:03 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ INSTALLING ] [ CWD ] / home / . cargo / bin / foo [ EXE ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` foo v0 . 2.1 ` ( executable ` foo [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2015-10-05 22:29:15 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-06-07 19:33:03 +00:00
fn installs_beta_version_by_explicit_name_from_git ( ) {
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.3.0-beta.1 " ) )
2018-06-07 19:33:03 +00:00
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git " )
. arg ( p . url ( ) . to_string ( ) )
. arg ( " foo " )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2018-06-07 19:33:03 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn missing ( ) {
2015-11-11 02:08:06 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install bar " )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 09:23:57 +00:00
[ UPDATING ] [ .. ] index
2017-10-04 22:07:01 +00:00
[ ERROR ] could not find ` bar ` in registry ` [ .. ] `
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn bad_version ( ) {
2015-11-11 02:08:06 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --vers=0.2.0 " )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 09:23:57 +00:00
[ UPDATING ] [ .. ] index
2017-10-04 22:07:01 +00:00
[ ERROR ] could not find ` foo ` in registry ` [ .. ] ` with version ` = 0. 2.0 `
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2019-01-17 20:59:43 +00:00
fn bad_paths ( ) {
2018-08-28 09:20:03 +00:00
cargo_process ( " install " )
. with_status ( 101 )
2019-01-17 20:59:43 +00:00
. with_stderr ( " [ERROR] `[CWD]` is not a crate root; specify a crate to install [..] " )
. run ( ) ;
2016-01-25 18:41:44 +00:00
2019-01-17 20:59:43 +00:00
cargo_process ( " install --path . " )
. with_status ( 101 )
. with_stderr ( " [ERROR] `[CWD]` does not contain a Cargo.toml file[..] " )
. run ( ) ;
2016-03-01 16:24:43 +00:00
2019-01-17 20:59:43 +00:00
let toml = paths ::root ( ) . join ( " Cargo.toml " ) ;
fs ::write ( toml , " " ) . unwrap ( ) ;
cargo_process ( " install --path Cargo.toml " )
. with_status ( 101 )
. with_stderr ( " [ERROR] `[CWD]/Cargo.toml` is not a directory[..] " )
. run ( ) ;
cargo_process ( " install --path . " )
. with_status ( 101 )
. with_stderr_contains ( " [ERROR] failed to parse manifest at `[CWD]/Cargo.toml` " )
2018-12-08 11:19:47 +00:00
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn install_location_precedence ( ) {
2015-11-11 02:08:06 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
2015-10-05 22:29:15 +00:00
let root = paths ::root ( ) ;
let t1 = root . join ( " t1 " ) ;
let t2 = root . join ( " t2 " ) ;
let t3 = root . join ( " t3 " ) ;
let t4 = cargo_home ( ) ;
fs ::create_dir ( root . join ( " .cargo " ) ) . unwrap ( ) ;
2018-03-14 15:17:44 +00:00
File ::create ( root . join ( " .cargo/config " ) )
. unwrap ( )
. write_all (
format! (
2019-07-13 23:00:47 +00:00
" [install]
root = ' { } '
" ,
2018-03-14 15:17:44 +00:00
t3 . display ( )
2018-12-08 11:19:47 +00:00
)
. as_bytes ( ) ,
)
. unwrap ( ) ;
2015-10-05 22:29:15 +00:00
println! ( " install --root " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --root " )
. arg ( & t1 )
. env ( " CARGO_INSTALL_ROOT " , & t2 )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( & t1 , " foo " ) ;
assert_has_not_installed_exe ( & t2 , " foo " ) ;
2015-10-05 22:29:15 +00:00
println! ( " install CARGO_INSTALL_ROOT " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " )
. env ( " CARGO_INSTALL_ROOT " , & t2 )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( & t2 , " foo " ) ;
assert_has_not_installed_exe ( & t3 , " foo " ) ;
2015-10-05 22:29:15 +00:00
println! ( " install install.root " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " ) . run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( & t3 , " foo " ) ;
assert_has_not_installed_exe ( & t4 , " foo " ) ;
2015-10-05 22:29:15 +00:00
fs ::remove_file ( root . join ( " .cargo/config " ) ) . unwrap ( ) ;
println! ( " install cargo home " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " ) . run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( & t4 , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn install_path ( ) {
2018-08-28 09:20:03 +00:00
let p = project ( ) . file ( " src/main.rs " , " fn main() {} " ) . build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " ) . arg ( p . root ( ) ) . run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2018-09-06 00:12:53 +00:00
p . cargo ( " install --path . " )
2018-08-28 09:20:03 +00:00
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-07-24 13:01:56 +00:00
[ ERROR ] binary ` foo [ .. ] ` already exists in destination as part of ` foo v0 . 0.1 [ .. ] `
2016-04-15 11:20:45 +00:00
Add - - force to overwrite
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn multiple_crates_error ( ) {
2016-03-01 16:24:43 +00:00
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.1.0 " ) )
2015-10-05 22:29:15 +00:00
. file ( " src/main.rs " , " fn main() {} " )
2018-07-24 22:35:01 +00:00
. file ( " a/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " a/src/main.rs " , " fn main() {} " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git " )
. arg ( p . url ( ) . to_string ( ) )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-05-15 22:16:54 +00:00
[ UPDATING ] git repository [ .. ]
2016-05-11 16:55:43 +00:00
[ ERROR ] multiple packages with binaries found : bar , foo
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn multiple_crates_select ( ) {
2016-03-01 16:24:43 +00:00
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.1.0 " ) )
2015-10-05 22:29:15 +00:00
. file ( " src/main.rs " , " fn main() {} " )
2018-07-24 22:35:01 +00:00
. file ( " a/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " a/src/main.rs " , " fn main() {} " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git " )
. arg ( p . url ( ) . to_string ( ) )
. arg ( " foo " )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
assert_has_not_installed_exe ( cargo_home ( ) , " bar " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git " )
. arg ( p . url ( ) . to_string ( ) )
. arg ( " bar " )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " bar " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-09-20 10:10:24 +00:00
fn multiple_crates_git_all ( ) {
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-12-08 11:19:47 +00:00
. file (
" Cargo.toml " ,
r #" \
2018-09-20 10:10:24 +00:00
[ workspace ]
members = [ " bin1 " , " bin2 " ]
2018-12-08 11:19:47 +00:00
" #,
)
2018-09-20 10:10:24 +00:00
. file ( " bin1/Cargo.toml " , & basic_manifest ( " bin1 " , " 0.1.0 " ) )
. file ( " bin2/Cargo.toml " , & basic_manifest ( " bin2 " , " 0.1.0 " ) )
2018-12-08 11:19:47 +00:00
. file (
" bin1/src/main.rs " ,
r # "fn main() { println!("Hello, world!"); }"# ,
)
. file (
" bin2/src/main.rs " ,
r # "fn main() { println!("Hello, world!"); }"# ,
)
2018-09-20 10:10:24 +00:00
. build ( ) ;
cargo_process ( & format! ( " install --git {} bin1 bin2 " , p . url ( ) . to_string ( ) ) ) . run ( ) ;
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn multiple_crates_auto_binaries ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2015-10-05 22:29:15 +00:00
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
[ dependencies ]
bar = { path = " a " }
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " extern crate bar; fn main() {} " )
2018-07-24 22:35:01 +00:00
. file ( " a/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " ) . arg ( p . root ( ) ) . run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn multiple_crates_auto_examples ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2015-10-05 22:29:15 +00:00
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
[ dependencies ]
bar = { path = " a " }
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " extern crate bar; " )
2018-03-14 15:17:44 +00:00
. file (
" examples/foo.rs " ,
"
2015-10-05 22:29:15 +00:00
extern crate bar ;
extern crate foo ;
fn main ( ) { }
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. file ( " a/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " )
. arg ( p . root ( ) )
. arg ( " --example=foo " )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn no_binaries_or_examples ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2015-10-05 22:29:15 +00:00
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
[ dependencies ]
bar = { path = " a " }
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/lib.rs " , " " )
2018-07-24 22:35:01 +00:00
. file ( " a/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " )
. arg ( p . root ( ) )
. with_status ( 101 )
. with_stderr ( " [ERROR] no packages found with binaries or examples " )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn no_binaries ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2015-10-05 22:29:15 +00:00
. file ( " src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. file ( " examples/foo.rs " , " fn main() {} " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " )
. arg ( p . root ( ) )
. arg ( " foo " )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2019-03-31 00:33:35 +00:00
[ ERROR ] specified package ` foo v0 . 0.1 ( [ .. ] ) ` has no binaries
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn examples ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2015-10-05 22:29:15 +00:00
. file ( " src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. file ( " examples/foo.rs " , " extern crate foo; fn main() {} " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " )
. arg ( p . root ( ) )
. arg ( " --example=foo " )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn install_twice ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2016-04-15 11:20:45 +00:00
. file ( " src/bin/foo-bin1.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " src/bin/foo-bin2.rs " , " fn main() {} " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " ) . arg ( p . root ( ) ) . run ( ) ;
cargo_process ( " install --path " )
. arg ( p . root ( ) )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-07-24 13:01:56 +00:00
[ ERROR ] binary ` foo - bin1 [ .. ] ` already exists in destination as part of ` foo v0 . 0.1 ( [ .. ] ) `
binary ` foo - bin2 [ .. ] ` already exists in destination as part of ` foo v0 . 0.1 ( [ .. ] ) `
2016-04-15 11:20:45 +00:00
Add - - force to overwrite
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn install_force ( ) {
2018-08-28 09:20:03 +00:00
let p = project ( ) . file ( " src/main.rs " , " fn main() {} " ) . build ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " ) . arg ( p . root ( ) ) . run ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
let p = project ( )
. at ( " foo2 " )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.2.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --force --path " )
. arg ( p . root ( ) )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-01-24 06:49:50 +00:00
[ INSTALLING ] foo v0 . 2.0 ( [ .. ] )
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 2.0 ( [ .. ] )
2016-07-25 23:30:03 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ REPLACING ] [ CWD ] / home / . cargo / bin / foo [ EXE ]
2019-03-31 00:33:35 +00:00
[ REPLACED ] package ` foo v0 . 0.1 ( [ .. ] / foo ) ` with ` foo v0 . 2.0 ( [ .. ] / foo2 ) ` ( executable ` foo [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2016-04-15 11:20:45 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --list " )
. with_stdout (
2018-03-14 15:17:44 +00:00
" \
2016-04-15 11:20:45 +00:00
foo v0 . 2.0 ( [ .. ] ) :
foo [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-04-15 11:20:45 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn install_force_partial_overlap ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2016-04-15 11:20:45 +00:00
. file ( " src/bin/foo-bin1.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " src/bin/foo-bin2.rs " , " fn main() {} " )
. build ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " ) . arg ( p . root ( ) ) . run ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
let p = project ( )
. at ( " foo2 " )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.2.0 " ) )
2016-04-15 11:20:45 +00:00
. file ( " src/bin/foo-bin2.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " src/bin/foo-bin3.rs " , " fn main() {} " )
. build ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --force --path " )
. arg ( p . root ( ) )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-01-24 06:49:50 +00:00
[ INSTALLING ] foo v0 . 2.0 ( [ .. ] )
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 2.0 ( [ .. ] )
2016-07-25 23:30:03 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ INSTALLING ] [ CWD ] / home / . cargo / bin / foo - bin3 [ EXE ]
[ REPLACING ] [ CWD ] / home / . cargo / bin / foo - bin2 [ EXE ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` foo v0 . 2.0 ( [ .. ] / foo2 ) ` ( executable ` foo - bin3 [ EXE ] ` )
[ REPLACED ] package ` foo v0 . 0.1 ( [ .. ] / foo ) ` with ` foo v0 . 2.0 ( [ .. ] / foo2 ) ` ( executable ` foo - bin2 [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2016-04-15 11:20:45 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --list " )
. with_stdout (
2018-03-14 15:17:44 +00:00
" \
2018-07-24 13:01:56 +00:00
foo v0 . 0.1 ( [ .. ] ) :
2016-04-15 11:20:45 +00:00
foo - bin1 [ .. ]
foo v0 . 2.0 ( [ .. ] ) :
foo - bin2 [ .. ]
foo - bin3 [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-04-15 11:20:45 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn install_force_bin ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2016-04-15 11:20:45 +00:00
. file ( " src/bin/foo-bin1.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " src/bin/foo-bin2.rs " , " fn main() {} " )
. build ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " ) . arg ( p . root ( ) ) . run ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
let p = project ( )
. at ( " foo2 " )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.2.0 " ) )
2016-04-15 11:20:45 +00:00
. file ( " src/bin/foo-bin1.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " src/bin/foo-bin2.rs " , " fn main() {} " )
. build ( ) ;
2016-04-15 11:20:45 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --force --bin foo-bin2 --path " )
. arg ( p . root ( ) )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-01-24 06:49:50 +00:00
[ INSTALLING ] foo v0 . 2.0 ( [ .. ] )
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 2.0 ( [ .. ] )
2016-07-25 23:30:03 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ REPLACING ] [ CWD ] / home / . cargo / bin / foo - bin2 [ EXE ]
2019-03-31 00:33:35 +00:00
[ REPLACED ] package ` foo v0 . 0.1 ( [ .. ] / foo ) ` with ` foo v0 . 2.0 ( [ .. ] / foo2 ) ` ( executable ` foo - bin2 [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2016-04-15 11:20:45 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --list " )
. with_stdout (
2018-03-14 15:17:44 +00:00
" \
2018-07-24 13:01:56 +00:00
foo v0 . 0.1 ( [ .. ] ) :
2016-04-15 11:20:45 +00:00
foo - bin1 [ .. ]
foo v0 . 2.0 ( [ .. ] ) :
foo - bin2 [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-04-15 11:20:45 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn compile_failure ( ) {
2018-08-28 09:20:03 +00:00
let p = project ( ) . file ( " src/main.rs " , " " ) . build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " )
. arg ( p . root ( ) )
. with_status ( 101 )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2018-07-24 13:01:56 +00:00
[ ERROR ] failed to compile ` foo v0 . 0.1 ( [ .. ] ) ` , intermediate artifacts can be \
2016-02-20 09:18:29 +00:00
found at ` [ .. ] target `
2015-10-05 22:29:15 +00:00
Caused by :
Could not compile ` foo ` .
To learn more , run the command again with - - verbose .
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn git_repo ( ) {
2015-10-05 22:29:15 +00:00
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.1.0 " ) )
2017-07-22 03:12:21 +00:00
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2019-02-03 04:01:23 +00:00
// Use `--locked` to test that we don't even try to write a lock file.
2018-08-28 09:20:03 +00:00
cargo_process ( " install --locked --git " )
. arg ( p . url ( ) . to_string ( ) )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2016-05-11 16:55:43 +00:00
[ UPDATING ] git repository ` [ .. ] `
2017-01-24 06:49:50 +00:00
[ INSTALLING ] foo v0 . 1.0 ( [ .. ] )
2016-05-11 16:55:43 +00:00
[ COMPILING ] foo v0 . 1.0 ( [ .. ] )
2016-07-25 23:30:03 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2018-09-08 02:42:26 +00:00
[ INSTALLING ] [ CWD ] / home / . cargo / bin / foo [ EXE ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` foo v0 . 1.0 ( [ .. ] / foo #[ .. ] ) ` ( executable ` foo [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2015-10-05 22:29:15 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn list ( ) {
2015-11-11 02:08:06 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
pkg ( " bar " , " 0.2.1 " ) ;
pkg ( " bar " , " 0.2.2 " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --list " ) . with_stdout ( " " ) . run ( ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install bar --vers =0.2.1 " ) . run ( ) ;
cargo_process ( " install foo " ) . run ( ) ;
cargo_process ( " install --list " )
. with_stdout (
2018-03-14 15:17:44 +00:00
" \
2016-02-03 18:54:07 +00:00
bar v0 . 2.1 :
2015-10-05 22:29:15 +00:00
bar [ .. ]
2016-02-03 18:54:07 +00:00
foo v0 . 0.1 :
2015-10-05 22:29:15 +00:00
foo [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-09-28 17:43:40 +00:00
fn list_error ( ) {
pkg ( " foo " , " 0.0.1 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " ) . run ( ) ;
cargo_process ( " install --list " )
. with_stdout (
2018-03-14 15:17:44 +00:00
" \
2017-09-28 17:43:40 +00:00
foo v0 . 0.1 :
foo [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-09-28 17:43:40 +00:00
let mut worldfile_path = cargo_home ( ) ;
worldfile_path . push ( " .crates.toml " ) ;
let mut worldfile = OpenOptions ::new ( )
2018-03-14 15:17:44 +00:00
. write ( true )
. open ( worldfile_path )
. expect ( " .crates.toml should be there " ) ;
2017-09-28 17:43:40 +00:00
worldfile . write_all ( b " \x00 " ) . unwrap ( ) ;
drop ( worldfile ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install --list --verbose " )
. with_status ( 101 )
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2017-09-28 17:43:40 +00:00
[ ERROR ] failed to parse crate metadata at ` [ .. ] `
Caused by :
invalid TOML found for metadata
Caused by :
unexpected character [ .. ]
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-09-28 17:43:40 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn uninstall_pkg_does_not_exist ( ) {
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo " )
. with_status ( 101 )
2019-02-03 04:01:23 +00:00
. with_stderr ( " [ERROR] package ID specification `foo` matched no packages " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn uninstall_bin_does_not_exist ( ) {
2015-11-11 02:08:06 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " ) . run ( ) ;
cargo_process ( " uninstall foo --bin=bar " )
. with_status ( 101 )
. with_stderr ( " [ERROR] binary `bar[..]` not installed as part of `foo v0.0.1` " )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-10-05 22:29:15 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn uninstall_piecemeal ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2015-10-05 22:29:15 +00:00
. file ( " src/bin/foo.rs " , " fn main() {} " )
2017-07-22 03:12:21 +00:00
. file ( " src/bin/bar.rs " , " fn main() {} " )
. build ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " ) . arg ( p . root ( ) ) . run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
assert_has_installed_exe ( cargo_home ( ) , " bar " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo --bin=bar " )
. with_stderr ( " [REMOVING] [..]bar[..] " )
. run ( ) ;
2015-10-05 22:29:15 +00:00
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
assert_has_not_installed_exe ( cargo_home ( ) , " bar " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo --bin=foo " )
. with_stderr ( " [REMOVING] [..]foo[..] " )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_not_installed_exe ( cargo_home ( ) , " foo " ) ;
2015-10-05 22:29:15 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo " )
. with_status ( 101 )
2019-02-03 04:01:23 +00:00
. with_stderr ( " [ERROR] package ID specification `foo` matched no packages " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-12-03 23:32:30 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn subcommand_works_out_of_the_box ( ) {
2015-12-03 23:32:30 +00:00
Package ::new ( " cargo-foo " , " 1.0.0 " )
2018-07-25 00:30:32 +00:00
. file ( " src/main.rs " , r # "fn main() { println!("bar"); }"# )
2015-12-03 23:32:30 +00:00
. publish ( ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install cargo-foo " ) . run ( ) ;
cargo_process ( " foo " ) . with_stdout ( " bar \n " ) . run ( ) ;
cargo_process ( " --list " )
. with_stdout_contains ( " foo \n " )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2015-12-17 16:41:05 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn installs_from_cwd_by_default ( ) {
2018-08-28 09:20:03 +00:00
let p = project ( ) . file ( " src/main.rs " , " fn main() {} " ) . build ( ) ;
2015-12-17 16:41:05 +00:00
2018-09-06 00:12:53 +00:00
p . cargo ( " install " )
2018-08-28 09:20:03 +00:00
. with_stderr_contains (
2018-08-22 08:46:50 +00:00
" warning: Using `cargo install` to install the binaries for the \
2018-09-21 06:47:09 +00:00
package in current working directory is deprecated , \
2018-08-22 08:46:50 +00:00
use ` cargo install - - path . ` instead . \
Use ` cargo build ` if you want to simply build the package . " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2016-02-20 09:18:29 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-04-10 00:37:12 +00:00
fn installs_from_cwd_with_2018_warnings ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-04-10 00:37:12 +00:00
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
2018-05-03 16:14:25 +00:00
edition = " 2018 "
2018-04-10 00:37:12 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-04-10 00:37:12 +00:00
. build ( ) ;
2018-09-06 00:12:53 +00:00
p . cargo ( " install " )
2018-08-28 09:20:03 +00:00
. with_status ( 101 )
. with_stderr_contains (
2018-08-22 08:46:50 +00:00
" error: Using `cargo install` to install the binaries for the \
2018-09-21 06:47:09 +00:00
package in current working directory is no longer supported , \
2018-08-22 08:46:50 +00:00
use ` cargo install - - path . ` instead . \
Use ` cargo build ` if you want to simply build the package . " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_not_installed_exe ( cargo_home ( ) , " foo " ) ;
2018-04-10 00:37:12 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-08-22 16:36:53 +00:00
fn uninstall_cwd ( ) {
let p = project ( ) . file ( " src/main.rs " , " fn main() {} " ) . build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " install --path . " )
. with_stderr ( & format! (
" \
2018-09-08 02:42:26 +00:00
[ INSTALLING ] foo v0 . 0.1 ( [ CWD ] )
[ COMPILING ] foo v0 . 0.1 ( [ CWD ] )
2018-08-22 16:36:53 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
[ INSTALLING ] { home } / bin / foo [ EXE ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` foo v0 . 0.1 ( [ .. ] / foo ) ` ( executable ` foo [ EXE ] ` )
[ WARNING ] be sure to add ` { home } / bin ` to your PATH to be able to run the installed binaries " ,
2018-08-22 16:36:53 +00:00
home = cargo_home ( ) . display ( ) ,
2018-12-08 11:19:47 +00:00
) )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2018-08-22 16:36:53 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " uninstall " )
. with_stdout ( " " )
. with_stderr ( & format! (
2019-07-13 23:00:47 +00:00
" [REMOVING] {home}/bin/foo[EXE] " ,
2018-08-22 16:36:53 +00:00
home = cargo_home ( ) . display ( )
2018-12-08 11:19:47 +00:00
) )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_not_installed_exe ( cargo_home ( ) , " foo " ) ;
2018-08-22 16:36:53 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-08-22 16:36:53 +00:00
fn uninstall_cwd_not_installed ( ) {
let p = project ( ) . file ( " src/main.rs " , " fn main() {} " ) . build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " uninstall " )
. with_status ( 101 )
. with_stdout ( " " )
2019-07-13 23:00:47 +00:00
. with_stderr ( " error: package `foo v0.0.1 ([CWD])` is not installed " )
2018-12-08 11:19:47 +00:00
. run ( ) ;
2018-08-22 16:36:53 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-08-22 16:36:53 +00:00
fn uninstall_cwd_no_project ( ) {
2018-08-23 13:00:26 +00:00
let err_msg = if cfg! ( windows ) {
" The system cannot find the file specified. "
} else {
" No such file or directory "
} ;
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall " )
. with_status ( 101 )
. with_stdout ( " " )
. with_stderr ( format! (
" \
2018-09-08 02:42:26 +00:00
[ ERROR ] failed to read ` [ CWD ] / Cargo . toml `
2018-08-22 16:36:53 +00:00
Caused by :
2018-08-23 13:00:26 +00:00
{ err_msg } ( os error 2 ) " ,
err_msg = err_msg ,
2018-12-08 11:19:47 +00:00
) )
. run ( ) ;
2018-08-22 16:36:53 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn do_not_rebuilds_on_local_install ( ) {
2018-08-28 09:20:03 +00:00
let p = project ( ) . file ( " src/main.rs " , " fn main() {} " ) . build ( ) ;
2016-02-20 09:18:29 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build --release " ) . run ( ) ;
cargo_process ( " install --path " )
. arg ( p . root ( ) )
. with_stderr (
2019-03-31 00:33:35 +00:00
" \
[ INSTALLING ] [ .. ]
2017-01-24 06:49:50 +00:00
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
2016-05-12 15:23:53 +00:00
[ INSTALLING ] [ .. ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` foo v0 . 0.1 ( [ .. ] / foo ) ` ( executable ` foo [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-02-20 09:18:29 +00:00
2016-05-26 00:06:25 +00:00
assert! ( p . build_dir ( ) . exists ( ) ) ;
assert! ( p . release_bin ( " foo " ) . exists ( ) ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2016-02-23 17:44:54 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn reports_unsuccessful_subcommand_result ( ) {
2016-02-23 17:44:54 +00:00
Package ::new ( " cargo-fail " , " 1.0.0 " )
2018-07-25 00:30:32 +00:00
. file ( " src/main.rs " , " fn main() { panic!(); } " )
2016-02-23 17:44:54 +00:00
. publish ( ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install cargo-fail " ) . run ( ) ;
cargo_process ( " --list " )
. with_stdout_contains ( " fail \n " )
. run ( ) ;
cargo_process ( " fail " )
. with_status ( 101 )
. with_stderr_contains ( " thread '[..]' panicked at 'explicit panic', [..] " )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-03-11 20:18:17 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn git_with_lockfile ( ) {
2016-03-11 20:18:17 +00:00
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2016-03-11 20:18:17 +00:00
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
[ dependencies ]
bar = { path = " bar " }
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-07-24 22:35:01 +00:00
. file ( " bar/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2016-03-11 20:18:17 +00:00
. file ( " bar/src/lib.rs " , " fn main() {} " )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.lock " ,
r #"
2017-10-03 12:18:08 +00:00
[ [ package ] ]
2016-03-11 20:18:17 +00:00
name = " foo "
version = " 0.1.0 "
2016-08-25 10:10:45 +00:00
dependencies = [ " bar 0.1.0 " ]
2016-03-11 20:18:17 +00:00
[ [ package ] ]
name = " bar "
version = " 0.1.0 "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. build ( ) ;
2016-03-11 20:18:17 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git " )
. arg ( p . url ( ) . to_string ( ) )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-04-14 17:25:25 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn q_silences_warnings ( ) {
2018-08-28 09:20:03 +00:00
let p = project ( ) . file ( " src/main.rs " , " fn main() {} " ) . build ( ) ;
2016-04-14 17:25:25 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install -q --path " )
. arg ( p . root ( ) )
. with_stderr ( " " )
. run ( ) ;
2016-05-25 20:55:42 +00:00
}
2016-04-23 03:33:58 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-05-25 20:55:42 +00:00
fn readonly_dir ( ) {
2016-04-23 03:33:58 +00:00
pkg ( " foo " , " 0.0.1 " ) ;
let root = paths ::root ( ) ;
let dir = & root . join ( " readonly " ) ;
fs ::create_dir ( root . join ( " readonly " ) ) . unwrap ( ) ;
let mut perms = fs ::metadata ( dir ) . unwrap ( ) . permissions ( ) ;
perms . set_readonly ( true ) ;
fs ::set_permissions ( dir , perms ) . unwrap ( ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " ) . cwd ( dir ) . run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2016-05-25 20:55:42 +00:00
}
2016-09-30 20:16:38 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-09-30 20:16:38 +00:00
fn use_path_workspace ( ) {
Package ::new ( " foo " , " 1.0.0 " ) . publish ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2016-09-30 20:16:38 +00:00
[ package ]
name = " bar "
version = " 0.1.0 "
authors = [ ]
[ workspace ]
members = [ " baz " ]
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-03-14 15:17:44 +00:00
. file (
" baz/Cargo.toml " ,
r #"
2016-09-30 20:16:38 +00:00
[ package ]
name = " baz "
version = " 0.1.0 "
authors = [ ]
[ dependencies ]
foo = " 1 "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " baz/src/lib.rs " , " " )
2017-07-22 03:12:21 +00:00
. build ( ) ;
2016-09-30 20:16:38 +00:00
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . run ( ) ;
2016-09-30 20:16:38 +00:00
let lock = p . read_lockfile ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " install " ) . run ( ) ;
2016-09-30 20:16:38 +00:00
let lock2 = p . read_lockfile ( ) ;
2018-02-23 23:27:53 +00:00
assert_eq! ( lock , lock2 , " different lockfiles " ) ;
2016-09-30 20:16:38 +00:00
}
2016-11-28 17:48:14 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-02-15 15:01:36 +00:00
fn dev_dependencies_no_check ( ) {
Package ::new ( " foo " , " 1.0.0 " ) . publish ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2018-02-15 15:01:36 +00:00
[ package ]
name = " bar "
version = " 0.1.0 "
authors = [ ]
[ dev - dependencies ]
baz = " 1.0.0 "
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-02-15 15:01:36 +00:00
. build ( ) ;
2018-12-29 01:47:50 +00:00
p . cargo ( " build " )
. with_status ( 101 )
. with_stderr_contains ( " [..] no matching package named `baz` found " )
. run ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " install " ) . run ( ) ;
2018-02-15 15:01:36 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-02-15 15:01:36 +00:00
fn dev_dependencies_lock_file_untouched ( ) {
Package ::new ( " foo " , " 1.0.0 " ) . publish ( ) ;
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-03-14 15:17:44 +00:00
. file (
" Cargo.toml " ,
r #"
2018-02-15 15:01:36 +00:00
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
[ dev - dependencies ]
bar = { path = " a " }
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-07-24 22:35:01 +00:00
. file ( " a/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2018-02-15 15:01:36 +00:00
. file ( " a/src/lib.rs " , " " )
. build ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " build " ) . run ( ) ;
2018-02-15 15:01:36 +00:00
let lock = p . read_lockfile ( ) ;
2018-08-28 09:20:03 +00:00
p . cargo ( " install " ) . run ( ) ;
2018-02-15 15:01:36 +00:00
let lock2 = p . read_lockfile ( ) ;
assert! ( lock = = lock2 , " different lockfiles " ) ;
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-06-29 01:57:24 +00:00
fn install_target_native ( ) {
pkg ( " foo " , " 0.1.0 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --target " )
. arg ( support ::rustc_host ( ) )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2018-06-29 01:57:24 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-06-29 01:57:24 +00:00
fn install_target_foreign ( ) {
if cross_compile ::disabled ( ) {
return ;
}
pkg ( " foo " , " 0.1.0 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --target " )
. arg ( cross_compile ::alternate ( ) )
. run ( ) ;
2018-08-29 06:32:28 +00:00
assert_has_installed_exe ( cargo_home ( ) , " foo " ) ;
2018-06-29 01:57:24 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-11-28 17:48:14 +00:00
fn vers_precise ( ) {
pkg ( " foo " , " 0.1.1 " ) ;
pkg ( " foo " , " 0.1.2 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --vers 0.1.1 " )
2018-09-14 20:33:18 +00:00
. with_stderr_contains ( " [DOWNLOADED] foo v0.1.1 (registry [..]) " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2016-11-28 17:48:14 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-10-18 06:18:42 +00:00
fn version_too ( ) {
pkg ( " foo " , " 0.1.1 " ) ;
pkg ( " foo " , " 0.1.2 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --version 0.1.1 " )
2018-09-14 20:33:18 +00:00
. with_stderr_contains ( " [DOWNLOADED] foo v0.1.1 (registry [..]) " )
2018-08-28 09:20:03 +00:00
. run ( ) ;
2017-10-18 06:18:42 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-10-18 06:39:11 +00:00
fn not_both_vers_and_version ( ) {
2017-10-18 06:18:42 +00:00
pkg ( " foo " , " 0.1.1 " ) ;
pkg ( " foo " , " 0.1.2 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --version 0.1.1 --vers 0.1.2 " )
. with_status ( 1 )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2018-03-08 18:55:12 +00:00
error : The argument ' - - version < VERSION > ' was provided more than once , \
but cannot be used multiple times
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-10-18 06:18:42 +00:00
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2016-11-28 17:48:14 +00:00
fn legacy_version_requirement ( ) {
pkg ( " foo " , " 0.1.1 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo --vers 0.1 " )
. with_stderr_contains (
2018-03-14 15:17:44 +00:00
" \
2016-11-28 17:48:14 +00:00
warning : the ` - - vers ` provided , ` 0.1 ` , is not a valid semver version
historically Cargo treated this as a semver version requirement accidentally
and will continue to do so , but this behavior will be removed eventually
2018-03-14 15:17:44 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2016-11-28 17:48:14 +00:00
}
2017-08-11 15:39:18 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-08-11 15:39:18 +00:00
fn test_install_git_cannot_be_a_base_url ( ) {
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git github.com:rust-lang-nursery/rustfmt.git " ) . with_status ( 101 ) . with_stderr ( " error: invalid url `github.com:rust-lang-nursery/rustfmt.git`: cannot-be-a-base-URLs are not supported " ) . run ( ) ;
2017-08-11 15:39:18 +00:00
}
2017-10-11 19:35:30 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-10-11 19:35:30 +00:00
fn uninstall_multiple_and_specifying_bin ( ) {
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo bar --bin baz " ) . with_status ( 101 ) . with_stderr ( " error: A binary can only be associated with a single installed package, specifying multiple specs with --bin is redundant. " ) . run ( ) ;
2017-10-11 19:35:30 +00:00
}
2017-10-28 14:36:49 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-10-28 14:36:49 +00:00
fn uninstall_multiple_and_some_pkg_does_not_exist ( ) {
pkg ( " foo " , " 0.0.1 " ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " ) . run ( ) ;
2017-10-28 14:36:49 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " uninstall foo bar " )
. with_status ( 101 )
2018-08-29 17:56:48 +00:00
. with_stderr (
2018-03-14 15:17:44 +00:00
" \
2018-09-08 02:42:26 +00:00
[ REMOVING ] [ CWD ] / home / . cargo / bin / foo [ EXE ]
2019-02-03 04:01:23 +00:00
error : package ID specification ` bar ` matched no packages
2017-12-08 19:31:17 +00:00
[ SUMMARY ] Successfully uninstalled foo ! Failed to uninstall bar ( see error ( s ) above ) .
2017-10-28 14:36:49 +00:00
error : some packages failed to uninstall
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2017-10-28 14:36:49 +00:00
2018-08-29 06:32:28 +00:00
assert_has_not_installed_exe ( cargo_home ( ) , " foo " ) ;
assert_has_not_installed_exe ( cargo_home ( ) , " bar " ) ;
2017-10-28 14:36:49 +00:00
}
2017-12-22 01:14:12 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2017-12-22 01:14:12 +00:00
fn custom_target_dir_for_git_source ( ) {
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.1.0 " ) )
2017-12-22 01:14:12 +00:00
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git " )
. arg ( p . url ( ) . to_string ( ) )
. run ( ) ;
2018-08-29 05:53:01 +00:00
assert! ( ! paths ::root ( ) . join ( " target/release " ) . is_dir ( ) ) ;
2018-03-14 15:17:44 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install --force --git " )
. arg ( p . url ( ) . to_string ( ) )
. env ( " CARGO_TARGET_DIR " , " target " )
. run ( ) ;
2018-08-29 05:53:01 +00:00
assert! ( paths ::root ( ) . join ( " target/release " ) . is_dir ( ) ) ;
2017-12-22 01:14:12 +00:00
}
2018-02-27 15:50:05 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-02-27 15:50:05 +00:00
fn install_respects_lock_file ( ) {
2019-04-13 23:43:53 +00:00
// `cargo install` now requires --locked to use a Cargo.lock.
2018-02-27 15:50:05 +00:00
Package ::new ( " bar " , " 0.1.0 " ) . publish ( ) ;
Package ::new ( " bar " , " 0.1.1 " )
. file ( " src/lib.rs " , " not rust " )
. publish ( ) ;
Package ::new ( " foo " , " 0.1.0 " )
. dep ( " bar " , " 0.1 " )
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
2018-08-28 09:20:03 +00:00
" src/main.rs " ,
" extern crate foo; extern crate bar; fn main() {} " ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" Cargo.lock " ,
r #"
2018-02-27 15:50:05 +00:00
[ [ package ] ]
name = " bar "
version = " 0.1.0 "
source = " registry+https://github.com/rust-lang/crates.io-index "
[ [ package ] ]
name = " foo "
version = " 0.1.0 "
dependencies = [
" bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index) " ,
]
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. publish ( ) ;
2018-02-27 15:50:05 +00:00
2019-04-08 01:26:08 +00:00
cargo_process ( " install foo " )
. with_stderr_contains ( " [..]not rust[..] " )
. with_status ( 101 )
. run ( ) ;
cargo_process ( " install --locked foo " ) . run ( ) ;
}
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2019-04-08 01:26:08 +00:00
fn install_path_respects_lock_file ( ) {
2019-04-13 23:43:53 +00:00
// --path version of install_path_respects_lock_file, --locked is required
// to use Cargo.lock.
2019-04-08 01:26:08 +00:00
Package ::new ( " bar " , " 0.1.0 " ) . publish ( ) ;
Package ::new ( " bar " , " 0.1.1 " )
. file ( " src/lib.rs " , " not rust " )
. publish ( ) ;
let p = project ( )
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
[ dependencies ]
bar = " 0.1 "
" #,
)
. file ( " src/main.rs " , " extern crate bar; fn main() {} " )
. file (
" Cargo.lock " ,
r #"
[ [ package ] ]
name = " bar "
version = " 0.1.0 "
source = " registry+https://github.com/rust-lang/crates.io-index "
[ [ package ] ]
name = " foo "
version = " 0.1.0 "
dependencies = [
" bar 0.1.0 (registry+https://github.com/rust-lang/crates.io-index) " ,
]
" #,
)
. build ( ) ;
2019-04-13 23:43:53 +00:00
p . cargo ( " install --path . " )
. with_stderr_contains ( " [..]not rust[..] " )
. with_status ( 101 )
. run ( ) ;
p . cargo ( " install --path . --locked " ) . run ( ) ;
2018-02-27 15:50:05 +00:00
}
2018-02-27 15:56:04 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-02-27 15:56:04 +00:00
fn lock_file_path_deps_ok ( ) {
Package ::new ( " bar " , " 0.1.0 " ) . publish ( ) ;
Package ::new ( " foo " , " 0.1.0 " )
. dep ( " bar " , " 0.1 " )
. file ( " src/lib.rs " , " " )
2018-03-14 15:17:44 +00:00
. file (
2018-08-28 09:20:03 +00:00
" src/main.rs " ,
" extern crate foo; extern crate bar; fn main() {} " ,
2018-12-08 11:19:47 +00:00
)
. file (
2018-03-14 15:17:44 +00:00
" Cargo.lock " ,
r #"
2018-02-27 15:56:04 +00:00
[ [ package ] ]
name = " bar "
version = " 0.1.0 "
[ [ package ] ]
name = " foo "
version = " 0.1.0 "
dependencies = [
" bar 0.1.0 " ,
]
2018-03-14 15:17:44 +00:00
" #,
2018-12-08 11:19:47 +00:00
)
. publish ( ) ;
2018-02-27 15:56:04 +00:00
2018-08-28 09:20:03 +00:00
cargo_process ( " install foo " ) . run ( ) ;
2018-02-27 15:56:04 +00:00
}
2018-03-23 14:26:50 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-03-23 14:26:50 +00:00
fn install_empty_argument ( ) {
// Bug 5229
2018-08-28 09:20:03 +00:00
cargo_process ( " install " )
. arg ( " " )
. with_status ( 1 )
. with_stderr_contains (
2018-03-23 14:26:50 +00:00
" [ERROR] The argument '<crate>...' requires a value but none was supplied " ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-03-23 14:26:50 +00:00
}
2018-05-24 09:39:56 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-05-24 09:39:56 +00:00
fn git_repo_replace ( ) {
let p = git ::repo ( & paths ::root ( ) . join ( " foo " ) )
2018-07-24 22:35:01 +00:00
. file ( " Cargo.toml " , & basic_manifest ( " foo " , " 0.1.0 " ) )
2018-05-24 09:39:56 +00:00
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
let repo = git2 ::Repository ::open ( & p . root ( ) ) . unwrap ( ) ;
let old_rev = repo . revparse_single ( " HEAD " ) . unwrap ( ) . id ( ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install --git " )
. arg ( p . url ( ) . to_string ( ) )
. run ( ) ;
2018-05-24 09:39:56 +00:00
git ::commit ( & repo ) ;
let new_rev = repo . revparse_single ( " HEAD " ) . unwrap ( ) . id ( ) ;
let mut path = paths ::home ( ) ;
path . push ( " .cargo/.crates.toml " ) ;
assert_ne! ( old_rev , new_rev ) ;
2018-12-08 11:19:47 +00:00
assert! ( fs ::read_to_string ( path . clone ( ) )
. unwrap ( )
. contains ( & format! ( " {} " , old_rev ) ) ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install --force --git " )
. arg ( p . url ( ) . to_string ( ) )
. run ( ) ;
2018-12-08 11:19:47 +00:00
assert! ( fs ::read_to_string ( path )
. unwrap ( )
. contains ( & format! ( " {} " , new_rev ) ) ) ;
2018-05-24 09:39:56 +00:00
}
2018-07-05 19:05:50 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-07-05 19:05:50 +00:00
fn workspace_uses_workspace_target_dir ( ) {
2018-07-20 11:47:47 +00:00
let p = project ( )
2018-07-05 19:05:50 +00:00
. file (
" Cargo.toml " ,
r #"
[ package ]
name = " foo "
version = " 0.1.0 "
authors = [ ]
[ workspace ]
[ dependencies ]
bar = { path = ' bar ' }
" #,
2018-12-08 11:19:47 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
2018-07-24 22:35:01 +00:00
. file ( " bar/Cargo.toml " , & basic_manifest ( " bar " , " 0.1.0 " ) )
2018-07-05 19:05:50 +00:00
. file ( " bar/src/main.rs " , " fn main() {} " )
. build ( ) ;
2019-03-20 23:34:56 +00:00
p . cargo ( " build --release " ) . cwd ( " bar " ) . run ( ) ;
2018-08-28 09:20:03 +00:00
cargo_process ( " install --path " )
. arg ( p . root ( ) . join ( " bar " ) )
. with_stderr (
2018-07-05 19:05:50 +00:00
" [INSTALLING] [..]
[ FINISHED ] release [ optimized ] target ( s ) in [ .. ]
[ INSTALLING ] [ .. ]
2019-03-31 00:33:35 +00:00
[ INSTALLED ] package ` bar v0 . 1.0 ( [ .. ] / bar ) ` ( executable ` bar [ EXE ] ` )
[ WARNING ] be sure to add ` [ .. ] ` to your PATH to be able to run the installed binaries
2018-07-05 19:05:50 +00:00
" ,
2018-12-08 11:19:47 +00:00
)
. run ( ) ;
2018-07-05 19:05:50 +00:00
}
2018-08-08 15:09:54 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-09-14 17:42:27 +00:00
fn install_ignores_local_cargo_config ( ) {
2018-08-08 15:09:54 +00:00
pkg ( " bar " , " 0.0.1 " ) ;
2018-08-09 18:26:11 +00:00
let p = project ( )
2018-08-08 15:09:54 +00:00
. file (
" .cargo/config " ,
r #"
2018-09-14 17:42:27 +00:00
[ build ]
target = " non-existing-target "
" #,
2018-08-08 15:09:54 +00:00
)
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
2018-09-06 06:37:01 +00:00
p . cargo ( " install bar " ) . run ( ) ;
2018-09-01 16:16:49 +00:00
assert_has_installed_exe ( cargo_home ( ) , " bar " ) ;
2018-08-08 15:09:54 +00:00
}
2018-09-14 17:42:27 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2018-09-14 17:42:27 +00:00
fn install_global_cargo_config ( ) {
pkg ( " bar " , " 0.0.1 " ) ;
let config = cargo_home ( ) . join ( " config " ) ;
2019-03-27 02:06:08 +00:00
let mut toml = fs ::read_to_string ( & config ) . unwrap_or_default ( ) ;
2018-09-14 17:42:27 +00:00
2018-12-08 11:19:47 +00:00
toml . push_str (
r #"
2018-09-14 17:42:27 +00:00
[ build ]
target = ' nonexistent '
2018-12-08 11:19:47 +00:00
" #,
) ;
2018-09-14 17:42:27 +00:00
fs ::write ( & config , toml ) . unwrap ( ) ;
cargo_process ( " install bar " )
. with_status ( 101 )
. with_stderr_contains ( " [..]--target nonexistent[..] " )
. run ( ) ;
}
2019-04-01 00:13:44 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2019-04-01 00:13:44 +00:00
fn install_path_config ( ) {
project ( )
. file (
" .cargo/config " ,
r #"
[ build ]
target = ' nonexistent '
" #,
)
. file ( " src/main.rs " , " fn main() {} " )
. build ( ) ;
cargo_process ( " install --path foo " )
. with_status ( 101 )
. with_stderr_contains ( " [..]--target nonexistent[..] " )
. run ( ) ;
}
2019-03-31 00:33:35 +00:00
2019-06-05 18:52:53 +00:00
#[ cargo_test ]
2019-03-31 00:33:35 +00:00
fn install_version_req ( ) {
// Try using a few versionreq styles.
pkg ( " foo " , " 0.0.3 " ) ;
pkg ( " foo " , " 1.0.4 " ) ;
pkg ( " foo " , " 1.0.5 " ) ;
cargo_process ( " install foo --version=* " )
. with_stderr_does_not_contain ( " [WARNING][..]is not a valid semver[..] " )
. with_stderr_contains ( " [INSTALLING] foo v1.0.5 " )
. run ( ) ;
cargo_process ( " uninstall foo " ) . run ( ) ;
cargo_process ( " install foo --version=^1.0 " )
. with_stderr_does_not_contain ( " [WARNING][..]is not a valid semver[..] " )
. with_stderr_contains ( " [INSTALLING] foo v1.0.5 " )
. run ( ) ;
cargo_process ( " uninstall foo " ) . run ( ) ;
cargo_process ( " install foo --version=0.0.* " )
. with_stderr_does_not_contain ( " [WARNING][..]is not a valid semver[..] " )
. with_stderr_contains ( " [INSTALLING] foo v0.0.3 " )
. run ( ) ;
}