Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Aug 24, 2023
1 parent f791293 commit 6d57b16
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/testsuite/tool_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,91 @@ fn pathless_tools() {
.run();
}

// can set a custom runner 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(
".cargo/config",
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 runner 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(
".cargo/config",
&format!(
r#"
[target.'cfg(not(target_os = "none"))']
linker = "ignored-runner"
[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(
".cargo/config",
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_contains(&format!(
"\
[ERROR] several matching instances of `target.'cfg(..)'.linker` in configurations
",
))
.run();
}

#[cargo_test]
fn absolute_tools() {
let target = rustc_host();
Expand Down

0 comments on commit 6d57b16

Please sign in to comment.