Skip to content

Commit 3597f4c

Browse files
committed
test: build-std proc_macro test case without --target requirement
Add a new test case for building a crate with -Zbuild-std, without the requirement for the --target flag, and that uses a proc_macro.
1 parent 879efa6 commit 3597f4c

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/build-std/main.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,66 @@ fn basic() {
154154
assert_eq!(p.glob(deps_dir.join("*.dylib")).count(), 0);
155155
}
156156

157+
#[cargo_test(build_std_real)]
158+
fn host_proc_macro() {
159+
let p = project()
160+
.file(
161+
"Cargo.toml",
162+
r#"
163+
[package]
164+
name = "foo"
165+
version = "0.1.0"
166+
edition = "2021"
167+
168+
[dependencies]
169+
macro_test = { path = "macro_test" }
170+
"#,
171+
)
172+
.file(
173+
"src/main.rs",
174+
r#"
175+
extern crate macro_test;
176+
use macro_test::make_answer;
177+
178+
make_answer!();
179+
180+
fn main() {
181+
println!("Hello, World: {}", answer());
182+
}
183+
"#,
184+
)
185+
.file(
186+
"macro_test/Cargo.toml",
187+
r#"
188+
[package]
189+
name = "macro_test"
190+
version = "0.1.0"
191+
edition = "2021"
192+
193+
[lib]
194+
proc-macro = true
195+
"#,
196+
)
197+
.file(
198+
"macro_test/src/lib.rs",
199+
r#"
200+
extern crate proc_macro;
201+
use proc_macro::TokenStream;
202+
203+
#[proc_macro]
204+
pub fn make_answer(_item: TokenStream) -> TokenStream {
205+
"fn answer() -> u32 { 42 }".parse().unwrap()
206+
}
207+
"#,
208+
)
209+
.build();
210+
211+
p.cargo("build")
212+
.build_std_arg("std")
213+
.build_std_arg("proc_macro")
214+
.run();
215+
}
216+
157217
#[cargo_test(build_std_real)]
158218
fn cross_custom() {
159219
let p = project()

0 commit comments

Comments
 (0)