2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for configuration values that point to programs.
|
|
|
|
|
2021-11-17 11:03:31 +00:00
|
|
|
use cargo_test_support::{basic_lib_manifest, project, rustc_host, rustc_host_env};
|
2015-07-24 06:35:53 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn pathless_tools() {
|
2016-05-26 00:06:25 +00:00
|
|
|
let target = rustc_host();
|
2015-07-24 06:35:53 +00:00
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-07-24 13:01:56 +00:00
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
2015-07-24 06:35:53 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-03-14 15:17:44 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{}]
|
|
|
|
linker = "nonexistent-linker"
|
|
|
|
"#,
|
2018-03-14 15:17:44 +00:00
|
|
|
target
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-07-24 06:35:53 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
foo.cargo("build --verbose")
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2020-01-02 18:25:54 +00:00
|
|
|
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
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-07-24 06:35:53 +00:00
|
|
|
|
2023-08-22 03:01:33 +00:00
|
|
|
// can set a custom linker via `target.'cfg(..)'.linker`
|
|
|
|
#[cargo_test]
|
|
|
|
fn custom_linker_cfg() {
|
|
|
|
let foo = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2023-08-22 03:01:33 +00:00
|
|
|
r#"
|
|
|
|
[target.'cfg(not(target_os = "none"))']
|
|
|
|
linker = "nonexistent-linker"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
foo.cargo("build --verbose")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
|
|
|
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
// custom linker set via `target.$triple.linker` have precede over `target.'cfg(..)'.linker`
|
|
|
|
#[cargo_test]
|
|
|
|
fn custom_linker_cfg_precedence() {
|
|
|
|
let target = rustc_host();
|
|
|
|
|
|
|
|
let foo = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2023-08-22 03:01:33 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[target.'cfg(not(target_os = "none"))']
|
|
|
|
linker = "ignored-linker"
|
|
|
|
[target.{}]
|
|
|
|
linker = "nonexistent-linker"
|
|
|
|
"#,
|
|
|
|
target
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
foo.cargo("build --verbose")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
|
|
|
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
|
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn custom_linker_cfg_collision() {
|
|
|
|
let foo = project()
|
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2023-08-22 03:01:33 +00:00
|
|
|
r#"
|
|
|
|
[target.'cfg(not(target_arch = "avr"))']
|
|
|
|
linker = "nonexistent-linker1"
|
|
|
|
[target.'cfg(not(target_os = "none"))']
|
|
|
|
linker = "nonexistent-linker2"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
foo.cargo("build --verbose")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[ERROR] several matching instances of `target.'cfg(..)'.linker` in configurations
|
2024-01-26 19:40:46 +00:00
|
|
|
first match `cfg(not(target_arch = \"avr\"))` located in [..]/foo/.cargo/config.toml
|
|
|
|
second match `cfg(not(target_os = \"none\"))` located in [..]/foo/.cargo/config.toml
|
2023-08-22 03:01:33 +00:00
|
|
|
",
|
|
|
|
))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn absolute_tools() {
|
2016-05-26 00:06:25 +00:00
|
|
|
let target = rustc_host();
|
2015-07-24 06:35:53 +00:00
|
|
|
|
|
|
|
// Escaped as they appear within a TOML config file
|
2020-01-02 18:25:54 +00:00
|
|
|
let linker = if cfg!(windows) {
|
|
|
|
r#"C:\\bogus\\nonexistent-linker"#
|
2015-07-24 06:35:53 +00:00
|
|
|
} else {
|
2020-01-02 18:25:54 +00:00
|
|
|
r#"/bogus/nonexistent-linker"#
|
2015-07-24 06:35:53 +00:00
|
|
|
};
|
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let foo = project()
|
2018-07-24 13:01:56 +00:00
|
|
|
.file("Cargo.toml", &basic_lib_manifest("foo"))
|
2015-07-24 06:35:53 +00:00
|
|
|
.file("src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-03-14 15:17:44 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{target}]
|
|
|
|
linker = "{linker}"
|
|
|
|
"#,
|
2018-03-14 15:17:44 +00:00
|
|
|
target = target,
|
2020-01-02 18:25:54 +00:00
|
|
|
linker = linker
|
2018-03-14 15:17:44 +00:00
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-07-24 06:35:53 +00:00
|
|
|
|
2019-07-18 15:35:25 +00:00
|
|
|
foo.cargo("build --verbose")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.5.0 ([CWD])
|
2020-01-02 18:25:54 +00:00
|
|
|
[RUNNING] `rustc [..] -C linker=[..]bogus/nonexistent-linker [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2019-07-18 15:35:25 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2015-07-24 06:35:53 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2016-05-25 20:55:42 +00:00
|
|
|
fn relative_tools() {
|
2016-05-26 00:06:25 +00:00
|
|
|
let target = rustc_host();
|
2015-07-24 06:35:53 +00:00
|
|
|
|
|
|
|
// Escaped as they appear within a TOML config file
|
2020-01-02 18:25:54 +00:00
|
|
|
let linker = if cfg!(windows) {
|
|
|
|
r#".\\tools\\nonexistent-linker"#
|
2015-07-24 06:35:53 +00:00
|
|
|
} else {
|
2020-01-02 18:25:54 +00:00
|
|
|
r#"./tools/nonexistent-linker"#
|
2015-07-24 06:35:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Funky directory structure to test that relative tool paths are made absolute
|
|
|
|
// by reference to the `.cargo/..` directory and not to (for example) the CWD.
|
2018-07-20 17:41:44 +00:00
|
|
|
let p = project()
|
2018-07-24 12:59:42 +00:00
|
|
|
.no_manifest()
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
|
2018-07-20 17:41:44 +00:00
|
|
|
.file("bar/src/lib.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-03-14 15:17:44 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{target}]
|
|
|
|
linker = "{linker}"
|
|
|
|
"#,
|
2018-03-14 15:17:44 +00:00
|
|
|
target = target,
|
2020-01-02 18:25:54 +00:00
|
|
|
linker = linker
|
2018-03-14 15:17:44 +00:00
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2015-07-24 06:35:53 +00:00
|
|
|
|
2018-07-20 17:41:44 +00:00
|
|
|
let prefix = p.root().into_os_string().into_string().unwrap();
|
2015-07-24 06:35:53 +00:00
|
|
|
|
2020-01-02 18:25:54 +00:00
|
|
|
p.cargo("build --verbose")
|
|
|
|
.cwd("bar")
|
|
|
|
.with_stderr(&format!(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] bar v0.5.0 ([CWD])
|
2020-01-02 18:25:54 +00:00
|
|
|
[RUNNING] `rustc [..] -C linker={prefix}/./tools/nonexistent-linker [..]`
|
2017-01-12 01:03:36 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-08-18 09:19:39 +00:00
|
|
|
prefix = prefix,
|
2020-01-02 18:25:54 +00:00
|
|
|
))
|
|
|
|
.run();
|
2016-05-25 20:55:42 +00:00
|
|
|
}
|
2017-04-26 00:16:17 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2017-04-26 00:16:17 +00:00
|
|
|
fn custom_runner() {
|
|
|
|
let target = rustc_host();
|
|
|
|
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2017-04-26 00:16:17 +00:00
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("tests/test.rs", "")
|
|
|
|
.file("benches/bench.rs", "")
|
2018-03-14 15:17:44 +00:00
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-03-14 15:17:44 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{}]
|
|
|
|
runner = "nonexistent-runner -r"
|
|
|
|
"#,
|
2018-03-14 15:17:44 +00:00
|
|
|
target
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2017-04-26 00:16:17 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("run -- --param")
|
|
|
|
.with_status(101)
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-04-26 00:16:17 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-04-26 00:16:17 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("test --test test --verbose -- --param")
|
|
|
|
.with_status(101)
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-04-26 00:16:17 +00:00
|
|
|
[RUNNING] `rustc [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `nonexistent-runner -r [..]/target/debug/deps/test-[..][EXE] --param`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-04-26 00:16:17 +00:00
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
p.cargo("bench --bench bench --verbose -- --param")
|
|
|
|
.with_status(101)
|
2018-09-03 09:38:29 +00:00
|
|
|
.with_stderr_contains(
|
2018-03-14 15:17:44 +00:00
|
|
|
"\
|
2018-09-08 02:42:26 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2017-04-26 00:16:17 +00:00
|
|
|
[RUNNING] `rustc [..]`
|
|
|
|
[RUNNING] `rustc [..]`
|
2019-06-07 18:09:47 +00:00
|
|
|
[FINISHED] bench [optimized] target(s) in [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `nonexistent-runner -r [..]/target/release/deps/bench-[..][EXE] --param --bench`
|
2018-03-14 15:17:44 +00:00
|
|
|
",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2017-04-26 00:16:17 +00:00
|
|
|
}
|
2018-09-01 16:01:47 +00:00
|
|
|
|
|
|
|
// can set a custom runner via `target.'cfg(..)'.runner`
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-01 16:01:47 +00:00
|
|
|
fn custom_runner_cfg() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-09-01 16:01:47 +00:00
|
|
|
r#"
|
|
|
|
[target.'cfg(not(target_os = "none"))']
|
|
|
|
runner = "nonexistent-runner -r"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-09-01 16:01:47 +00:00
|
|
|
|
|
|
|
p.cargo("run -- --param")
|
|
|
|
.with_status(101)
|
2019-04-05 19:55:01 +00:00
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
2018-09-09 23:51:23 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2018-09-01 16:01:47 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param`
|
2019-04-05 19:55:01 +00:00
|
|
|
",
|
|
|
|
)
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2018-09-01 16:01:47 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 14:31:26 +00:00
|
|
|
// custom runner set via `target.$triple.runner` have precedence over `target.'cfg(..)'.runner`
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-01 16:01:47 +00:00
|
|
|
fn custom_runner_cfg_precedence() {
|
|
|
|
let target = rustc_host();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-09-01 16:01:47 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.'cfg(not(target_os = "none"))']
|
|
|
|
runner = "ignored-runner"
|
2018-09-01 16:01:47 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{}]
|
|
|
|
runner = "nonexistent-runner -r"
|
|
|
|
"#,
|
2018-09-01 16:01:47 +00:00
|
|
|
target
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-09-01 16:01:47 +00:00
|
|
|
|
|
|
|
p.cargo("run -- --param")
|
|
|
|
.with_status(101)
|
2019-04-05 19:55:01 +00:00
|
|
|
.with_stderr_contains(
|
|
|
|
"\
|
2019-07-13 23:00:47 +00:00
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
2018-09-01 16:01:47 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
|
|
[RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param`
|
2019-04-05 19:55:01 +00:00
|
|
|
",
|
|
|
|
)
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2018-09-01 16:01:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-09-01 16:01:47 +00:00
|
|
|
fn custom_runner_cfg_collision() {
|
|
|
|
let p = project()
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2018-09-01 16:01:47 +00:00
|
|
|
r#"
|
|
|
|
[target.'cfg(not(target_arch = "avr"))']
|
|
|
|
runner = "true"
|
|
|
|
|
|
|
|
[target.'cfg(not(target_os = "none"))']
|
|
|
|
runner = "false"
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.build();
|
2018-09-01 16:01:47 +00:00
|
|
|
|
|
|
|
p.cargo("run -- --param")
|
|
|
|
.with_status(101)
|
2019-11-24 17:43:59 +00:00
|
|
|
.with_stderr(
|
2019-04-05 19:55:01 +00:00
|
|
|
"\
|
2022-08-10 15:19:35 +00:00
|
|
|
[ERROR] several matching instances of `target.'cfg(..)'.runner` in configurations
|
2024-01-26 19:40:46 +00:00
|
|
|
first match `cfg(not(target_arch = \"avr\"))` located in [..]/foo/.cargo/config.toml
|
|
|
|
second match `cfg(not(target_os = \"none\"))` located in [..]/foo/.cargo/config.toml
|
2019-11-24 17:43:59 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn custom_runner_env() {
|
|
|
|
let p = project().file("src/main.rs", "fn main() {}").build();
|
|
|
|
|
2021-07-02 03:33:48 +00:00
|
|
|
let key = format!("CARGO_TARGET_{}_RUNNER", rustc_host_env());
|
2019-11-24 17:43:59 +00:00
|
|
|
|
|
|
|
p.cargo("run")
|
|
|
|
.env(&key, "nonexistent-runner --foo")
|
|
|
|
.with_status(101)
|
2021-11-17 11:03:31 +00:00
|
|
|
// FIXME: Update "Caused by" error message once rust/pull/87704 is merged.
|
|
|
|
// On Windows, changing to a custom executable resolver has changed the
|
|
|
|
// error messages.
|
2020-08-17 15:43:19 +00:00
|
|
|
.with_stderr(&format!(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo [..]
|
|
|
|
[FINISHED] dev [..]
|
|
|
|
[RUNNING] `nonexistent-runner --foo target/debug/foo[EXE]`
|
|
|
|
[ERROR] could not execute process `nonexistent-runner --foo target/debug/foo[EXE]` (never executed)
|
|
|
|
|
|
|
|
Caused by:
|
2021-11-17 11:03:31 +00:00
|
|
|
[..]
|
|
|
|
"
|
2020-08-17 15:43:19 +00:00
|
|
|
))
|
2019-11-24 17:43:59 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-08-17 17:23:49 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn custom_runner_env_overrides_config() {
|
|
|
|
let target = rustc_host();
|
|
|
|
let p = project()
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
".cargo/config.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[target.{}]
|
|
|
|
runner = "should-not-run -r"
|
|
|
|
"#,
|
2020-08-17 17:23:49 +00:00
|
|
|
target
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2021-07-02 03:33:48 +00:00
|
|
|
let key = format!("CARGO_TARGET_{}_RUNNER", rustc_host_env());
|
2020-08-17 17:23:49 +00:00
|
|
|
|
|
|
|
p.cargo("run")
|
|
|
|
.env(&key, "should-run --foo")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[RUNNING] `should-run --foo target/debug/foo[EXE]`")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-02-16 23:29:59 +00:00
|
|
|
#[cargo_test]
|
|
|
|
#[cfg(unix)] // Assumes `true` is in PATH.
|
|
|
|
fn custom_runner_env_true() {
|
|
|
|
// Check for a bug where "true" was interpreted as a boolean instead of
|
|
|
|
// the executable.
|
|
|
|
let p = project().file("src/main.rs", "fn main() {}").build();
|
|
|
|
|
2021-07-02 03:33:48 +00:00
|
|
|
let key = format!("CARGO_TARGET_{}_RUNNER", rustc_host_env());
|
2020-02-16 23:29:59 +00:00
|
|
|
|
|
|
|
p.cargo("run")
|
|
|
|
.env(&key, "true")
|
|
|
|
.with_stderr_contains("[RUNNING] `true target/debug/foo[EXE]`")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2020-01-02 18:25:54 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn custom_linker_env() {
|
|
|
|
let p = project().file("src/main.rs", "fn main() {}").build();
|
|
|
|
|
2021-07-02 03:33:48 +00:00
|
|
|
let key = format!("CARGO_TARGET_{}_LINKER", rustc_host_env());
|
2020-01-02 18:25:54 +00:00
|
|
|
|
|
|
|
p.cargo("build -v")
|
|
|
|
.env(&key, "nonexistent-linker")
|
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]-C linker=nonexistent-linker [..]")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2021-02-13 10:46:13 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn target_in_environment_contains_lower_case() {
|
|
|
|
let p = project().file("src/main.rs", "fn main() {}").build();
|
|
|
|
|
2021-02-24 03:51:42 +00:00
|
|
|
let target = rustc_host();
|
|
|
|
let env_key = format!(
|
|
|
|
"CARGO_TARGET_{}_LINKER",
|
|
|
|
target.to_lowercase().replace('-', "_")
|
|
|
|
);
|
|
|
|
|
2021-07-02 02:41:13 +00:00
|
|
|
p.cargo("build -v --target")
|
|
|
|
.arg(target)
|
|
|
|
.env(&env_key, "nonexistent-linker")
|
|
|
|
.with_stderr_contains(format!(
|
|
|
|
"warning: Environment variables are expected to use uppercase \
|
|
|
|
letters and underscores, the variable `{}` will be ignored and \
|
|
|
|
have no effect",
|
2021-02-24 03:51:42 +00:00
|
|
|
env_key
|
2021-07-02 02:41:13 +00:00
|
|
|
))
|
|
|
|
.run();
|
2021-02-13 20:17:18 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 17:43:59 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn cfg_ignored_fields() {
|
|
|
|
// Test for some ignored fields in [target.'cfg()'] tables.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2019-11-24 17:43:59 +00:00
|
|
|
r#"
|
|
|
|
# Try some empty tables.
|
|
|
|
[target.'cfg(not(foo))']
|
|
|
|
[target.'cfg(not(bar))'.somelib]
|
|
|
|
|
|
|
|
# A bunch of unused fields.
|
|
|
|
[target.'cfg(not(target_os = "none"))']
|
|
|
|
linker = 'false'
|
|
|
|
ar = 'false'
|
|
|
|
foo = {rustc-flags = "-l foo"}
|
|
|
|
invalid = 1
|
|
|
|
runner = 'false'
|
|
|
|
rustflags = ''
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[WARNING] unused key `somelib` in [target] config table `cfg(not(bar))`
|
|
|
|
[WARNING] unused key `ar` in [target] config table `cfg(not(target_os = \"none\"))`
|
|
|
|
[WARNING] unused key `foo` in [target] config table `cfg(not(target_os = \"none\"))`
|
|
|
|
[WARNING] unused key `invalid` in [target] config table `cfg(not(target_os = \"none\"))`
|
|
|
|
[CHECKING] foo v0.0.1 ([..])
|
|
|
|
[FINISHED] [..]
|
2019-04-05 19:55:01 +00:00
|
|
|
",
|
|
|
|
)
|
2018-12-08 11:19:47 +00:00
|
|
|
.run();
|
2018-09-01 16:01:47 +00:00
|
|
|
}
|