2020-04-27 19:28:39 +00:00
|
|
|
//! Tests for multiple `--target` flags to subcommands
|
|
|
|
|
|
|
|
use cargo_test_support::{basic_manifest, cross_compile, project, rustc_host};
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn simple_build() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t1 = cross_compile::alternate();
|
|
|
|
let t2 = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("build")
|
2020-04-27 19:28:39 +00:00
|
|
|
.arg("--target")
|
|
|
|
.arg(&t1)
|
|
|
|
.arg("--target")
|
|
|
|
.arg(&t2)
|
|
|
|
.run();
|
|
|
|
|
2020-04-30 22:48:38 +00:00
|
|
|
assert!(p.target_bin(t1, "foo").is_file());
|
2021-04-02 10:30:36 +00:00
|
|
|
assert!(p.target_bin(t2, "foo").is_file());
|
2020-04-27 19:28:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-11 17:23:18 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn simple_build_with_config() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t1 = cross_compile::alternate();
|
|
|
|
let t2 = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[build]
|
|
|
|
target = ["{t1}", "{t2}"]
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("build").run();
|
2022-03-11 17:23:18 +00:00
|
|
|
|
|
|
|
assert!(p.target_bin(t1, "foo").is_file());
|
|
|
|
assert!(p.target_bin(t2, "foo").is_file());
|
|
|
|
}
|
|
|
|
|
2020-04-27 19:28:39 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn simple_test() {
|
|
|
|
if !cross_compile::can_run_on_host() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t1 = cross_compile::alternate();
|
|
|
|
let t2 = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/lib.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("test")
|
2020-04-27 19:28:39 +00:00
|
|
|
.arg("--target")
|
|
|
|
.arg(&t1)
|
|
|
|
.arg("--target")
|
|
|
|
.arg(&t2)
|
|
|
|
.with_stderr_contains(&format!("[RUNNING] [..]{}[..]", t1))
|
|
|
|
.with_stderr_contains(&format!("[RUNNING] [..]{}[..]", t2))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn simple_run() {
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("run --target a --target b")
|
2022-03-11 17:23:18 +00:00
|
|
|
.with_stderr("[ERROR] only one `--target` argument is supported")
|
2020-04-27 19:28:39 +00:00
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn simple_doc() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t1 = cross_compile::alternate();
|
|
|
|
let t2 = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/lib.rs", "//! empty lib")
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("doc")
|
2020-04-27 19:28:39 +00:00
|
|
|
.arg("--target")
|
|
|
|
.arg(&t1)
|
|
|
|
.arg("--target")
|
|
|
|
.arg(&t2)
|
|
|
|
.run();
|
|
|
|
|
|
|
|
assert!(p.build_dir().join(&t1).join("doc/foo/index.html").is_file());
|
|
|
|
assert!(p.build_dir().join(&t2).join("doc/foo/index.html").is_file());
|
|
|
|
}
|
|
|
|
|
2023-10-19 15:40:49 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn simple_doc_open() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t1 = cross_compile::alternate();
|
|
|
|
let t2 = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/lib.rs", "//! empty lib")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("doc")
|
|
|
|
.arg("--open")
|
|
|
|
.arg("--target")
|
|
|
|
.arg(&t1)
|
|
|
|
.arg("--target")
|
|
|
|
.arg(&t2)
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[DOCUMENTING] foo v1.0.0 ([..])
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[ERROR] only one `--target` argument is supported",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-04-27 19:28:39 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn simple_check() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t1 = cross_compile::alternate();
|
|
|
|
let t2 = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("check")
|
2020-04-27 19:28:39 +00:00
|
|
|
.arg("--target")
|
|
|
|
.arg(&t1)
|
|
|
|
.arg("--target")
|
|
|
|
.arg(&t2)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn same_value_twice() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("build")
|
2020-04-27 19:28:39 +00:00
|
|
|
.arg("--target")
|
|
|
|
.arg(&t)
|
|
|
|
.arg("--target")
|
|
|
|
.arg(&t)
|
|
|
|
.run();
|
|
|
|
|
2021-04-02 10:30:36 +00:00
|
|
|
assert!(p.target_bin(t, "foo").is_file());
|
2020-04-27 19:28:39 +00:00
|
|
|
}
|
2022-03-11 17:23:18 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn same_value_twice_with_config() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[build]
|
|
|
|
target = ["{t}", "{t}"]
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("build").run();
|
2022-03-11 17:23:18 +00:00
|
|
|
|
|
|
|
assert!(p.target_bin(t, "foo").is_file());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn works_with_config_in_both_string_or_list() {
|
|
|
|
if cross_compile::disabled() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let t = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[build]
|
|
|
|
target = "{t}"
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("build").run();
|
2022-03-11 17:23:18 +00:00
|
|
|
|
|
|
|
assert!(p.target_bin(t, "foo").is_file());
|
|
|
|
|
|
|
|
p.cargo("clean").run();
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
".cargo/config.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[build]
|
|
|
|
target = ["{t}"]
|
|
|
|
"#
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-06-17 11:53:12 +00:00
|
|
|
p.cargo("build").run();
|
2022-03-11 17:23:18 +00:00
|
|
|
|
|
|
|
assert!(p.target_bin(t, "foo").is_file());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn works_with_env() {
|
|
|
|
let t = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2022-03-29 05:15:11 +00:00
|
|
|
p.cargo("build").env("CARGO_BUILD_TARGET", t).run();
|
2022-03-11 17:23:18 +00:00
|
|
|
|
|
|
|
assert!(p.target_bin(t, "foo").is_file());
|
|
|
|
}
|