cargo/tests/testsuite/tool_paths.rs

170 lines
4.6 KiB
Rust
Raw Normal View History

use support::rustc_host;
use support::{basic_lib_manifest, project};
#[test]
fn pathless_tools() {
let target = rustc_host();
let foo = project()
2018-07-24 13:01:56 +00:00
.file("Cargo.toml", &basic_lib_manifest("foo"))
.file("src/lib.rs", "")
2018-03-14 15:17:44 +00:00
.file(
".cargo/config",
&format!(
r#"
[target.{}]
ar = "nonexistent-ar"
linker = "nonexistent-linker"
2018-03-14 15:17:44 +00:00
"#,
target
),
).build();
foo.cargo("build --verbose")
.with_stderr(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.5.0 (CWD)
[RUNNING] `rustc [..] -C ar=nonexistent-ar -C linker=nonexistent-linker [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
)).run();
}
#[test]
fn absolute_tools() {
let target = rustc_host();
2018-08-18 11:20:00 +00:00
let root = if cfg!(windows) { r#"C:\"# } else { "/" };
// Escaped as they appear within a TOML config file
let config = if cfg!(windows) {
2018-03-14 15:17:44 +00:00
(
r#"C:\\bogus\\nonexistent-ar"#,
r#"C:\\bogus\\nonexistent-linker"#,
)
} else {
(r#"/bogus/nonexistent-ar"#, r#"/bogus/nonexistent-linker"#)
};
let foo = project()
2018-07-24 13:01:56 +00:00
.file("Cargo.toml", &basic_lib_manifest("foo"))
.file("src/lib.rs", "")
2018-03-14 15:17:44 +00:00
.file(
".cargo/config",
&format!(
r#"
[target.{target}]
ar = "{ar}"
linker = "{linker}"
2018-03-14 15:17:44 +00:00
"#,
target = target,
ar = config.0,
linker = config.1
),
).build();
foo.cargo("build --verbose").with_stderr(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.5.0 (CWD)
[RUNNING] `rustc [..] -C ar={root}bogus/nonexistent-ar -C linker={root}bogus/nonexistent-linker [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
root = root,
)).run();
}
#[test]
fn relative_tools() {
let target = rustc_host();
// Escaped as they appear within a TOML config file
let config = if cfg!(windows) {
(r#".\\nonexistent-ar"#, r#".\\tools\\nonexistent-linker"#)
} else {
(r#"./nonexistent-ar"#, r#"./tools/nonexistent-linker"#)
};
// 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.
let p = project()
.no_manifest()
2018-07-24 22:35:01 +00:00
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
.file("bar/src/lib.rs", "")
2018-03-14 15:17:44 +00:00
.file(
".cargo/config",
&format!(
r#"
[target.{target}]
ar = "{ar}"
linker = "{linker}"
2018-03-14 15:17:44 +00:00
"#,
target = target,
ar = config.0,
linker = config.1
),
).build();
let prefix = p.root().into_os_string().into_string().unwrap();
p.cargo("build --verbose").cwd(p.root().join("bar")).with_stderr(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] bar v0.5.0 (CWD)
[RUNNING] `rustc [..] -C ar={prefix}/./nonexistent-ar -C linker={prefix}/./tools/nonexistent-linker [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2018-03-14 15:17:44 +00:00
",
prefix = prefix,
)).run();
}
#[test]
fn custom_runner() {
let target = rustc_host();
let p = project()
.file("src/main.rs", "fn main() {}")
.file("tests/test.rs", "")
.file("benches/bench.rs", "")
2018-03-14 15:17:44 +00:00
.file(
".cargo/config",
&format!(
r#"
[target.{}]
2017-05-12 22:07:42 +00:00
runner = "nonexistent-runner -r"
2018-03-14 15:17:44 +00:00
"#,
target
),
).build();
p.cargo("run -- --param")
.with_status(101)
.with_stderr_contains(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.0.1 (CWD)
[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
",
)).run();
p.cargo("test --test test --verbose -- --param")
.with_status(101)
.with_stderr_contains(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.0.1 (CWD)
[RUNNING] `rustc [..]`
[FINISHED] dev [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
",
)).run();
p.cargo("bench --bench bench --verbose -- --param")
.with_status(101)
.with_stderr_contains(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.0.1 (CWD)
[RUNNING] `rustc [..]`
[RUNNING] `rustc [..]`
[FINISHED] release [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
",
)).run();
}