Skip to content

Commit 14e8794

Browse files
committed
Added more tests to ensure proc-macro crates use sysroot
1 parent a022179 commit 14e8794

File tree

1 file changed

+106
-1
lines changed

1 file changed

+106
-1
lines changed

tests/testsuite/standard_lib.rs

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,121 @@ fn target_proc_macro() {
396396
"src/lib.rs",
397397
r#"
398398
extern crate proc_macro;
399-
pub fn f() {
399+
fn f() {
400400
let _ts = proc_macro::TokenStream::new();
401401
}
402402
"#,
403403
)
404+
.file(
405+
"Cargo.toml",
406+
r#"
407+
[package]
408+
name = "pm"
409+
version = "0.1.0"
410+
411+
[lib]
412+
proc-macro = true
413+
"#,
414+
)
404415
.build();
405416

406417
p.cargo("build -v").build_std(&setup).target_host().run();
407418
}
408419

420+
// We already have `basic` which uses `proc_macro::custom_api()`. This case attempts to use
421+
// `TokenStream` which would error because we are using the sysroot version.
422+
#[cargo_test]
423+
fn non_proc_macro_crate_uses_non_sysroot_proc_macro() {
424+
let setup = match setup() {
425+
Some(s) => s,
426+
None => return,
427+
};
428+
let p = project()
429+
.file(
430+
"src/lib.rs",
431+
r#"
432+
extern crate proc_macro;
433+
fn f() {
434+
let _ts = proc_macro::TokenStream::new();
435+
}
436+
"#,
437+
)
438+
.file(
439+
"Cargo.toml",
440+
r#"
441+
[package]
442+
name = "pm"
443+
version = "0.1.0"
444+
"#,
445+
)
446+
.build();
447+
p.cargo("build -v")
448+
.build_std(&setup)
449+
.target_host()
450+
.run_expect_error();
451+
}
452+
453+
#[cargo_test]
454+
fn intergrated_proc_macro() {
455+
let setup = match setup() {
456+
Some(s) => s,
457+
None => return,
458+
};
459+
let p = project()
460+
.file(
461+
"src/main.rs",
462+
r#"
463+
fn main() {
464+
println!("The answer is {}", pm::m!());
465+
}
466+
"#,
467+
)
468+
.file(
469+
"pm/src/lib.rs",
470+
r#"
471+
extern crate proc_macro;
472+
use proc_macro::TokenStream;
473+
474+
#[proc_macro]
475+
pub fn m(_item: TokenStream) -> TokenStream {
476+
"42".parse().unwrap()
477+
}
478+
"#,
479+
)
480+
.file(
481+
"Cargo.toml",
482+
r#"
483+
[package]
484+
name = "foo"
485+
version = "0.1.0"
486+
487+
[workspace]
488+
members = ["pm"]
489+
490+
[dependencies]
491+
pm = { path = "./pm" }
492+
"#,
493+
)
494+
.file(
495+
"pm/Cargo.toml",
496+
r#"
497+
[package]
498+
name = "pm"
499+
version = "0.1.0"
500+
501+
[lib]
502+
proc-macro = true
503+
"#,
504+
)
505+
.build();
506+
507+
p.cargo("run -v")
508+
.build_std(&setup)
509+
.target_host()
510+
.with_stdout_contains("The answer is 42")
511+
.run();
512+
}
513+
409514
#[cargo_test]
410515
fn bench() {
411516
let setup = match setup() {

0 commit comments

Comments
 (0)