2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for the `cargo fetch` command.
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::registry::Package;
|
|
|
|
use cargo_test_support::rustc_host;
|
|
|
|
use cargo_test_support::{basic_manifest, cross_compile, project};
|
2014-09-11 18:50:57 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn no_deps() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("src/main.rs", "mod a; fn main() {}")
|
2017-07-22 03:12:21 +00:00
|
|
|
.file("src/a.rs", "")
|
|
|
|
.build();
|
2014-09-11 18:50:57 +00:00
|
|
|
|
2023-11-15 22:33:27 +00:00
|
|
|
p.cargo("fetch").with_stderr("").run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2018-04-09 18:31:04 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-09 18:31:04 +00:00
|
|
|
fn fetch_all_platform_dependencies_when_no_target_is_given() {
|
2018-08-06 17:04:53 +00:00
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-09 18:31:04 +00:00
|
|
|
Package::new("d1", "1.2.3")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("d1", "1.2.3"))
|
2018-04-09 18:31:04 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
Package::new("d2", "0.1.2")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("d2", "0.1.2"))
|
2018-04-09 18:31:04 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
let target = cross_compile::alternate();
|
|
|
|
let host = rustc_host();
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-09 18:31:04 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-04-09 18:31:04 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{host}.dependencies]
|
|
|
|
d1 = "1.2.3"
|
2018-04-09 18:31:04 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{target}.dependencies]
|
|
|
|
d2 = "0.1.2"
|
|
|
|
"#,
|
2018-04-09 18:31:04 +00:00
|
|
|
host = host,
|
|
|
|
target = target
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-09 18:31:04 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fetch")
|
2018-09-14 20:33:18 +00:00
|
|
|
.with_stderr_contains("[DOWNLOADED] d1 v1.2.3 [..]")
|
|
|
|
.with_stderr_contains("[DOWNLOADED] d2 v0.1.2 [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-04-09 18:31:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-09 18:31:04 +00:00
|
|
|
fn fetch_platform_specific_dependencies() {
|
2018-08-06 17:04:53 +00:00
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-09 18:31:04 +00:00
|
|
|
Package::new("d1", "1.2.3")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("d1", "1.2.3"))
|
2018-04-09 18:31:04 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
Package::new("d2", "0.1.2")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("d2", "0.1.2"))
|
2018-04-09 18:31:04 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
let target = cross_compile::alternate();
|
|
|
|
let host = rustc_host();
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-09 18:31:04 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-04-09 18:31:04 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{host}.dependencies]
|
|
|
|
d1 = "1.2.3"
|
2018-04-09 18:31:04 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{target}.dependencies]
|
|
|
|
d2 = "0.1.2"
|
|
|
|
"#,
|
2018-04-09 18:31:04 +00:00
|
|
|
host = host,
|
|
|
|
target = target
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-09 18:31:04 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("fetch --target")
|
|
|
|
.arg(&host)
|
2018-09-14 20:33:18 +00:00
|
|
|
.with_stderr_contains("[DOWNLOADED] d1 v1.2.3 [..]")
|
|
|
|
.with_stderr_does_not_contain("[DOWNLOADED] d2 v0.1.2 [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("fetch --target")
|
|
|
|
.arg(&target)
|
2018-09-14 20:33:18 +00:00
|
|
|
.with_stderr_contains("[DOWNLOADED] d2 v0.1.2[..]")
|
|
|
|
.with_stderr_does_not_contain("[DOWNLOADED] d1 v1.2.3 [..]")
|
2018-08-28 09:20:03 +00:00
|
|
|
.run();
|
2018-04-09 18:31:04 +00:00
|
|
|
}
|
2019-08-12 23:03:15 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn fetch_warning() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "1.0.0"
|
|
|
|
misspelled = "wut"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
p.cargo("fetch")
|
|
|
|
.with_stderr("[WARNING] unused manifest key: package.misspelled")
|
|
|
|
.run();
|
|
|
|
}
|