mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-10 07:04:22 +00:00
Add a proc_macro_test crate
This exports all 3 kinds of proc macros and is useful for testing
This commit is contained in:
parent
c2594daf29
commit
cb816b1ea8
6 changed files with 51 additions and 3 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -1097,12 +1097,17 @@ dependencies = [
|
|||
"mbe",
|
||||
"memmap",
|
||||
"proc_macro_api",
|
||||
"proc_macro_test",
|
||||
"serde_derive",
|
||||
"test_utils",
|
||||
"toolchain",
|
||||
"tt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc_macro_test"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "profile"
|
||||
version = "0.0.0"
|
||||
|
|
|
@ -21,7 +21,9 @@ test_utils = { path = "../test_utils" }
|
|||
[dev-dependencies]
|
||||
cargo_metadata = "0.11.1"
|
||||
difference = "2.0.0"
|
||||
# used as proc macro test target
|
||||
|
||||
# used as proc macro test targets
|
||||
serde_derive = "1.0.106"
|
||||
proc_macro_test = { path = "../proc_macro_test" }
|
||||
|
||||
toolchain = { path = "../toolchain" }
|
||||
|
|
|
@ -35,7 +35,7 @@ SUBTREE $
|
|||
|
||||
#[test]
|
||||
fn test_derive_proc_macro_list() {
|
||||
let res = list("serde_derive", "1.0").join("\n");
|
||||
let res = list("serde_derive", "1").join("\n");
|
||||
|
||||
assert_eq_text!(
|
||||
&res,
|
||||
|
@ -43,3 +43,16 @@ fn test_derive_proc_macro_list() {
|
|||
Deserialize [CustomDerive]"#
|
||||
);
|
||||
}
|
||||
|
||||
/// Tests that we find and classify non-derive macros correctly.
|
||||
#[test]
|
||||
fn list_test_macros() {
|
||||
let res = list("proc_macro_test", "0.0.0").join("\n");
|
||||
|
||||
assert_eq_text!(
|
||||
&res,
|
||||
r#"function_like_macro [FuncLike]
|
||||
attribute_macro [Attr]
|
||||
DummyTrait [CustomDerive]"#
|
||||
);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ mod fixtures {
|
|||
// Use current project metadata to get the proc-macro dylib path
|
||||
pub fn dylib_path(crate_name: &str, version: &str) -> std::path::PathBuf {
|
||||
let command = Command::new(toolchain::cargo())
|
||||
.args(&["check", "--message-format", "json"])
|
||||
.args(&["check", "--tests", "--message-format", "json"])
|
||||
.output()
|
||||
.unwrap()
|
||||
.stdout;
|
||||
|
|
10
crates/proc_macro_test/Cargo.toml
Normal file
10
crates/proc_macro_test/Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "proc_macro_test"
|
||||
version = "0.0.0"
|
||||
license = "MIT OR Apache-2.0"
|
||||
authors = ["rust-analyzer developers"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
doctest = false
|
||||
proc-macro = true
|
18
crates/proc_macro_test/src/lib.rs
Normal file
18
crates/proc_macro_test/src/lib.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
//! Exports a few trivial procedural macros for testing.
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
#[proc_macro]
|
||||
pub fn function_like_macro(args: TokenStream) -> TokenStream {
|
||||
args
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn attribute_macro(_args: TokenStream, item: TokenStream) -> TokenStream {
|
||||
item
|
||||
}
|
||||
|
||||
#[proc_macro_derive(DummyTrait)]
|
||||
pub fn derive_macro(_item: TokenStream) -> TokenStream {
|
||||
TokenStream::new()
|
||||
}
|
Loading…
Reference in a new issue