aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-08-14 23:19:47 +0100
committerJonas Schievink <[email protected]>2020-08-14 23:27:32 +0100
commitcb816b1ea87b24f34eeecfdd98aeeb629915d661 (patch)
tree4928418a4f8d49f030e0689131f4d48dd59dc555
parentc2594daf2974dbd4ce3d9b7ec72481764abaceb5 (diff)
Add a proc_macro_test crate
This exports all 3 kinds of proc macros and is useful for testing
-rw-r--r--Cargo.lock5
-rw-r--r--crates/proc_macro_srv/Cargo.toml4
-rw-r--r--crates/proc_macro_srv/src/tests/mod.rs15
-rw-r--r--crates/proc_macro_srv/src/tests/utils.rs2
-rw-r--r--crates/proc_macro_test/Cargo.toml10
-rw-r--r--crates/proc_macro_test/src/lib.rs18
6 files changed, 51 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2386c8f3a..c7809a65a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1097,6 +1097,7 @@ dependencies = [
1097 "mbe", 1097 "mbe",
1098 "memmap", 1098 "memmap",
1099 "proc_macro_api", 1099 "proc_macro_api",
1100 "proc_macro_test",
1100 "serde_derive", 1101 "serde_derive",
1101 "test_utils", 1102 "test_utils",
1102 "toolchain", 1103 "toolchain",
@@ -1104,6 +1105,10 @@ dependencies = [
1104] 1105]
1105 1106
1106[[package]] 1107[[package]]
1108name = "proc_macro_test"
1109version = "0.0.0"
1110
1111[[package]]
1107name = "profile" 1112name = "profile"
1108version = "0.0.0" 1113version = "0.0.0"
1109dependencies = [ 1114dependencies = [
diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml
index 7171f0808..a468b5560 100644
--- a/crates/proc_macro_srv/Cargo.toml
+++ b/crates/proc_macro_srv/Cargo.toml
@@ -21,7 +21,9 @@ test_utils = { path = "../test_utils" }
21[dev-dependencies] 21[dev-dependencies]
22cargo_metadata = "0.11.1" 22cargo_metadata = "0.11.1"
23difference = "2.0.0" 23difference = "2.0.0"
24# used as proc macro test target 24
25# used as proc macro test targets
25serde_derive = "1.0.106" 26serde_derive = "1.0.106"
27proc_macro_test = { path = "../proc_macro_test" }
26 28
27toolchain = { path = "../toolchain" } 29toolchain = { path = "../toolchain" }
diff --git a/crates/proc_macro_srv/src/tests/mod.rs b/crates/proc_macro_srv/src/tests/mod.rs
index 8e6f28abd..1a827cbd7 100644
--- a/crates/proc_macro_srv/src/tests/mod.rs
+++ b/crates/proc_macro_srv/src/tests/mod.rs
@@ -35,7 +35,7 @@ SUBTREE $
35 35
36#[test] 36#[test]
37fn test_derive_proc_macro_list() { 37fn test_derive_proc_macro_list() {
38 let res = list("serde_derive", "1.0").join("\n"); 38 let res = list("serde_derive", "1").join("\n");
39 39
40 assert_eq_text!( 40 assert_eq_text!(
41 &res, 41 &res,
@@ -43,3 +43,16 @@ fn test_derive_proc_macro_list() {
43Deserialize [CustomDerive]"# 43Deserialize [CustomDerive]"#
44 ); 44 );
45} 45}
46
47/// Tests that we find and classify non-derive macros correctly.
48#[test]
49fn 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]
55attribute_macro [Attr]
56DummyTrait [CustomDerive]"#
57 );
58}
diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs
index 5828512d6..36942147d 100644
--- a/crates/proc_macro_srv/src/tests/utils.rs
+++ b/crates/proc_macro_srv/src/tests/utils.rs
@@ -13,7 +13,7 @@ mod fixtures {
13 // Use current project metadata to get the proc-macro dylib path 13 // Use current project metadata to get the proc-macro dylib path
14 pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf { 14 pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
15 let command = Command::new(toolchain::cargo()) 15 let command = Command::new(toolchain::cargo())
16 .args(&["check", "--message-format", "json"]) 16 .args(&["check", "--tests", "--message-format", "json"])
17 .output() 17 .output()
18 .unwrap() 18 .unwrap()
19 .stdout; 19 .stdout;
diff --git a/crates/proc_macro_test/Cargo.toml b/crates/proc_macro_test/Cargo.toml
new file mode 100644
index 000000000..7b0f64f31
--- /dev/null
+++ b/crates/proc_macro_test/Cargo.toml
@@ -0,0 +1,10 @@
1[package]
2name = "proc_macro_test"
3version = "0.0.0"
4license = "MIT OR Apache-2.0"
5authors = ["rust-analyzer developers"]
6edition = "2018"
7
8[lib]
9doctest = false
10proc-macro = true
diff --git a/crates/proc_macro_test/src/lib.rs b/crates/proc_macro_test/src/lib.rs
new file mode 100644
index 000000000..ec2a114a3
--- /dev/null
+++ b/crates/proc_macro_test/src/lib.rs
@@ -0,0 +1,18 @@
1//! Exports a few trivial procedural macros for testing.
2
3use proc_macro::TokenStream;
4
5#[proc_macro]
6pub fn function_like_macro(args: TokenStream) -> TokenStream {
7 args
8}
9
10#[proc_macro_attribute]
11pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream {
12 item
13}
14
15#[proc_macro_derive(DummyTrait)]
16pub fn derive_macro(_item: TokenStream) -> TokenStream {
17 TokenStream::new()
18}