Skip to content

Commit cb816b1

Browse files
Add a proc_macro_test crate
This exports all 3 kinds of proc macros and is useful for testing
1 parent c2594da commit cb816b1

File tree

6 files changed

+51
-3
lines changed

6 files changed

+51
-3
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/proc_macro_srv/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ test_utils = { path = "../test_utils" }
2121
[dev-dependencies]
2222
cargo_metadata = "0.11.1"
2323
difference = "2.0.0"
24-
# used as proc macro test target
24+
25+
# used as proc macro test targets
2526
serde_derive = "1.0.106"
27+
proc_macro_test = { path = "../proc_macro_test" }
2628

2729
toolchain = { path = "../toolchain" }

crates/proc_macro_srv/src/tests/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,24 @@ SUBTREE $
3535

3636
#[test]
3737
fn test_derive_proc_macro_list() {
38-
let res = list("serde_derive", "1.0").join("\n");
38+
let res = list("serde_derive", "1").join("\n");
3939

4040
assert_eq_text!(
4141
&res,
4242
r#"Serialize [CustomDerive]
4343
Deserialize [CustomDerive]"#
4444
);
4545
}
46+
47+
/// Tests that we find and classify non-derive macros correctly.
48+
#[test]
49+
fn list_test_macros() {
50+
let res = list("proc_macro_test", "0.0.0").join("\n");
51+
52+
assert_eq_text!(
53+
&res,
54+
r#"function_like_macro [FuncLike]
55+
attribute_macro [Attr]
56+
DummyTrait [CustomDerive]"#
57+
);
58+
}

crates/proc_macro_srv/src/tests/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod fixtures {
1313
// Use current project metadata to get the proc-macro dylib path
1414
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
1515
let command = Command::new(toolchain::cargo())
16-
.args(&["check", "--message-format", "json"])
16+
.args(&["check", "--tests", "--message-format", "json"])
1717
.output()
1818
.unwrap()
1919
.stdout;

crates/proc_macro_test/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "proc_macro_test"
3+
version = "0.0.0"
4+
license = "MIT OR Apache-2.0"
5+
authors = ["rust-analyzer developers"]
6+
edition = "2018"
7+
8+
[lib]
9+
doctest = false
10+
proc-macro = true

crates/proc_macro_test/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Exports a few trivial procedural macros for testing.
2+
3+
use proc_macro::TokenStream;
4+
5+
#[proc_macro]
6+
pub fn function_like_macro(args: TokenStream) -> TokenStream {
7+
args
8+
}
9+
10+
#[proc_macro_attribute]
11+
pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream {
12+
item
13+
}
14+
15+
#[proc_macro_derive(DummyTrait)]
16+
pub fn derive_macro(_item: TokenStream) -> TokenStream {
17+
TokenStream::new()
18+
}

0 commit comments

Comments
 (0)