Skip to content

Commit 2a94b4a

Browse files
committed
Add some tests
1 parent 8254ed4 commit 2a94b4a

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

tests/testsuite/tool_paths.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,93 @@ fn pathless_tools() {
3232
.run();
3333
}
3434

35+
// can set a custom linker via `target.'cfg(..)'.linker`
36+
#[cargo_test]
37+
fn custom_linker_cfg() {
38+
let foo = project()
39+
.file("Cargo.toml", &basic_lib_manifest("foo"))
40+
.file("src/lib.rs", "")
41+
.file(
42+
".cargo/config",
43+
r#"
44+
[target.'cfg(not(target_os = "none"))']
45+
linker = "nonexistent-linker"
46+
"#,
47+
)
48+
.build();
49+
50+
foo.cargo("build --verbose")
51+
.with_stderr(
52+
"\
53+
[COMPILING] foo v0.5.0 ([CWD])
54+
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
55+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
56+
",
57+
)
58+
.run();
59+
}
60+
61+
// custom linker set via `target.$triple.linker` have precede over `target.'cfg(..)'.linker`
62+
#[cargo_test]
63+
fn custom_linker_cfg_precedence() {
64+
let target = rustc_host();
65+
66+
let foo = project()
67+
.file("Cargo.toml", &basic_lib_manifest("foo"))
68+
.file("src/lib.rs", "")
69+
.file(
70+
".cargo/config",
71+
&format!(
72+
r#"
73+
[target.'cfg(not(target_os = "none"))']
74+
linker = "ignored-linker"
75+
[target.{}]
76+
linker = "nonexistent-linker"
77+
"#,
78+
target
79+
),
80+
)
81+
.build();
82+
83+
foo.cargo("build --verbose")
84+
.with_stderr(
85+
"\
86+
[COMPILING] foo v0.5.0 ([CWD])
87+
[RUNNING] `rustc [..] -C linker=nonexistent-linker [..]`
88+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
89+
",
90+
)
91+
.run();
92+
}
93+
94+
#[cargo_test]
95+
fn custom_linker_cfg_collision() {
96+
let foo = project()
97+
.file("Cargo.toml", &basic_lib_manifest("foo"))
98+
.file("src/lib.rs", "")
99+
.file(
100+
".cargo/config",
101+
r#"
102+
[target.'cfg(not(target_arch = "avr"))']
103+
linker = "nonexistent-linker1"
104+
[target.'cfg(not(target_os = "none"))']
105+
linker = "nonexistent-linker2"
106+
"#,
107+
)
108+
.build();
109+
110+
foo.cargo("build --verbose")
111+
.with_status(101)
112+
.with_stderr(&format!(
113+
"\
114+
[ERROR] several matching instances of `target.'cfg(..)'.linker` in configurations
115+
first match `cfg(not(target_arch = \"avr\"))` located in [..]/foo/.cargo/config
116+
second match `cfg(not(target_os = \"none\"))` located in [..]/foo/.cargo/config
117+
",
118+
))
119+
.run();
120+
}
121+
35122
#[cargo_test]
36123
fn absolute_tools() {
37124
let target = rustc_host();

0 commit comments

Comments
 (0)