diff options
author | Edwin Cheng <[email protected]> | 2021-03-15 15:38:22 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2021-03-15 15:38:22 +0000 |
commit | a8c9c882921c052be4e8ef65557c2946d013e425 (patch) | |
tree | c17cd44a26bb891dabfc420978d3f106b1644337 /crates | |
parent | 5f6d71cf0c41ac063bdb35dffe7ec713b1dbac42 (diff) |
Add test for proc-macro meta info retrieval
Diffstat (limited to 'crates')
-rw-r--r-- | crates/proc_macro_api/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/proc_macro_api/src/version.rs | 13 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/mod.rs | 7 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/utils.rs | 2 |
4 files changed, 17 insertions, 8 deletions
diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index 941d0fe9e..2dd2a8541 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs | |||
@@ -23,6 +23,7 @@ use tt::{SmolStr, Subtree}; | |||
23 | use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; | 23 | use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; |
24 | 24 | ||
25 | pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; | 25 | pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; |
26 | pub use version::{read_dylib_info, RustCInfo}; | ||
26 | 27 | ||
27 | #[derive(Debug, Clone)] | 28 | #[derive(Debug, Clone)] |
28 | struct ProcMacroProcessExpander { | 29 | struct ProcMacroProcessExpander { |
@@ -76,7 +77,7 @@ impl ProcMacroClient { | |||
76 | } | 77 | } |
77 | 78 | ||
78 | pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> { | 79 | pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> { |
79 | match version::read_info(dylib_path) { | 80 | match version::read_dylib_info(dylib_path) { |
80 | Ok(info) => { | 81 | Ok(info) => { |
81 | if info.version.0 < 1 || info.version.1 < 47 { | 82 | if info.version.0 < 1 || info.version.1 < 47 { |
82 | eprintln!("proc-macro {} built by {:#?} is not supported by Rust Analyzer, please update your rust version.", dylib_path.to_string_lossy(), info); | 83 | eprintln!("proc-macro {} built by {:#?} is not supported by Rust Analyzer, please update your rust version.", dylib_path.to_string_lossy(), info); |
diff --git a/crates/proc_macro_api/src/version.rs b/crates/proc_macro_api/src/version.rs index b903658fb..dcf8fae8f 100644 --- a/crates/proc_macro_api/src/version.rs +++ b/crates/proc_macro_api/src/version.rs | |||
@@ -11,14 +11,15 @@ use object::read::{File as BinaryFile, Object, ObjectSection}; | |||
11 | use snap::read::FrameDecoder as SnapDecoder; | 11 | use snap::read::FrameDecoder as SnapDecoder; |
12 | 12 | ||
13 | #[derive(Debug)] | 13 | #[derive(Debug)] |
14 | pub(crate) struct RustCInfo { | 14 | pub struct RustCInfo { |
15 | pub(crate) version: (usize, usize, usize), | 15 | pub version: (usize, usize, usize), |
16 | pub(crate) channel: String, | 16 | pub channel: String, |
17 | pub(crate) commit: String, | 17 | pub commit: String, |
18 | pub(crate) date: String, | 18 | pub date: String, |
19 | } | 19 | } |
20 | 20 | ||
21 | pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> { | 21 | /// Read rustc dylib information |
22 | pub fn read_dylib_info(dylib_path: &Path) -> io::Result<RustCInfo> { | ||
22 | macro_rules! err { | 23 | macro_rules! err { |
23 | ($e:literal) => { | 24 | ($e:literal) => { |
24 | io::Error::new(io::ErrorKind::InvalidData, $e) | 25 | io::Error::new(io::ErrorKind::InvalidData, $e) |
diff --git a/crates/proc_macro_srv/src/tests/mod.rs b/crates/proc_macro_srv/src/tests/mod.rs index fd54f8dfd..b4ab4c077 100644 --- a/crates/proc_macro_srv/src/tests/mod.rs +++ b/crates/proc_macro_srv/src/tests/mod.rs | |||
@@ -56,3 +56,10 @@ DummyTrait [CustomDerive]"#, | |||
56 | &res | 56 | &res |
57 | ); | 57 | ); |
58 | } | 58 | } |
59 | |||
60 | #[test] | ||
61 | fn test_version_check() { | ||
62 | let path = fixtures::dylib_path("proc_macro_test", "0.0.0"); | ||
63 | let info = proc_macro_api::read_dylib_info(&path).unwrap(); | ||
64 | assert!(info.version.1 >= 50); | ||
65 | } | ||
diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs index 0484c3af4..f15381f0f 100644 --- a/crates/proc_macro_srv/src/tests/utils.rs +++ b/crates/proc_macro_srv/src/tests/utils.rs | |||
@@ -6,7 +6,7 @@ use proc_macro_api::ListMacrosTask; | |||
6 | use std::str::FromStr; | 6 | use std::str::FromStr; |
7 | use test_utils::assert_eq_text; | 7 | use test_utils::assert_eq_text; |
8 | 8 | ||
9 | mod fixtures { | 9 | pub mod fixtures { |
10 | use cargo_metadata::Message; | 10 | use cargo_metadata::Message; |
11 | use std::path::PathBuf; | 11 | use std::path::PathBuf; |
12 | use std::process::Command; | 12 | use std::process::Command; |