Skip to content

Commit 6ab7019

Browse files
committed
Add custom target tests
1 parent 0a9a344 commit 6ab7019

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed

tests/testsuite/custom_target.rs

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
use cargotest::is_nightly;
2+
use cargotest::support::{execs, project};
3+
use hamcrest::assert_that;
4+
5+
#[test]
6+
fn custom_target_minimal() {
7+
if !is_nightly() {
8+
return;
9+
}
10+
let p = project("foo")
11+
.file(
12+
"Cargo.toml",
13+
r#"
14+
[package]
15+
16+
name = "foo"
17+
version = "0.0.1"
18+
authors = ["author@example.com"]
19+
"#,
20+
)
21+
.file(
22+
"src/lib.rs",
23+
r#"
24+
#![feature(no_core)]
25+
#![feature(lang_items)]
26+
#![no_core]
27+
28+
pub fn foo() -> u32 {
29+
42
30+
}
31+
32+
#[lang = "sized"]
33+
pub trait Sized {
34+
// Empty.
35+
}
36+
#[lang = "copy"]
37+
pub trait Copy {
38+
// Empty.
39+
}
40+
"#,
41+
)
42+
.file(
43+
"custom-target.json",
44+
r#"
45+
{
46+
"llvm-target": "x86_64-unknown-none-gnu",
47+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
48+
"arch": "x86_64",
49+
"target-endian": "little",
50+
"target-pointer-width": "64",
51+
"target-c-int-width": "32",
52+
"os": "none",
53+
"linker-flavor": "ld.lld"
54+
}
55+
"#,
56+
)
57+
.build();
58+
59+
assert_that(
60+
p.cargo("build")
61+
.arg("--lib")
62+
.arg("--target")
63+
.arg("custom-target.json")
64+
.arg("-v"),
65+
execs().with_status(0),
66+
);
67+
assert_that(
68+
p.cargo("build")
69+
.arg("--lib")
70+
.arg("--target")
71+
.arg("src/../custom-target.json")
72+
.arg("-v"),
73+
execs().with_status(0),
74+
);
75+
}
76+
77+
#[test]
78+
fn custom_target_dependency() {
79+
if !is_nightly() {
80+
return;
81+
}
82+
let p = project("foo")
83+
.file(
84+
"Cargo.toml",
85+
r#"
86+
[package]
87+
88+
name = "foo"
89+
version = "0.0.1"
90+
authors = ["author@example.com"]
91+
92+
[dependencies]
93+
bar = { path = "bar" }
94+
"#,
95+
)
96+
.file(
97+
"src/lib.rs",
98+
r#"
99+
#![feature(no_core)]
100+
#![feature(lang_items)]
101+
#![feature(optin_builtin_traits)]
102+
#![no_core]
103+
104+
extern crate bar;
105+
106+
pub fn foo() -> u32 {
107+
bar::bar()
108+
}
109+
110+
#[lang = "freeze"]
111+
unsafe auto trait Freeze {}
112+
"#,
113+
)
114+
.file(
115+
"bar/Cargo.toml",
116+
r#"
117+
[package]
118+
119+
name = "bar"
120+
version = "0.0.1"
121+
authors = ["author@example.com"]
122+
"#,
123+
)
124+
.file(
125+
"bar/src/lib.rs",
126+
r#"
127+
#![feature(no_core)]
128+
#![feature(lang_items)]
129+
#![no_core]
130+
131+
pub fn bar() -> u32 {
132+
42
133+
}
134+
135+
#[lang = "sized"]
136+
pub trait Sized {
137+
// Empty.
138+
}
139+
#[lang = "copy"]
140+
pub trait Copy {
141+
// Empty.
142+
}
143+
"#,
144+
)
145+
.file(
146+
"custom-target.json",
147+
r#"
148+
{
149+
"llvm-target": "x86_64-unknown-none-gnu",
150+
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
151+
"arch": "x86_64",
152+
"target-endian": "little",
153+
"target-pointer-width": "64",
154+
"target-c-int-width": "32",
155+
"os": "none",
156+
"linker-flavor": "ld.lld"
157+
}
158+
"#,
159+
)
160+
.build();
161+
162+
assert_that(
163+
p.cargo("build")
164+
.arg("--lib")
165+
.arg("--target")
166+
.arg("custom-target.json")
167+
.arg("-v"),
168+
execs().with_status(0),
169+
);
170+
}

tests/testsuite/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ mod config;
4343
mod corrupt_git;
4444
mod cross_compile;
4545
mod cross_publish;
46+
mod custom_target;
4647
mod death;
4748
mod dep_info;
4849
mod directory;

0 commit comments

Comments
 (0)