aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_proc_macro_srv/src/tests/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_proc_macro_srv/src/tests/utils.rs')
-rw-r--r--crates/ra_proc_macro_srv/src/tests/utils.rs64
1 files changed, 0 insertions, 64 deletions
diff --git a/crates/ra_proc_macro_srv/src/tests/utils.rs b/crates/ra_proc_macro_srv/src/tests/utils.rs
deleted file mode 100644
index 1b6a0b6fb..000000000
--- a/crates/ra_proc_macro_srv/src/tests/utils.rs
+++ /dev/null
@@ -1,64 +0,0 @@
1//! utils used in proc-macro tests
2
3use crate::dylib;
4use crate::ProcMacroSrv;
5use ra_proc_macro::ListMacrosTask;
6use std::str::FromStr;
7use test_utils::assert_eq_text;
8
9mod fixtures {
10 use cargo_metadata::Message;
11 use std::process::Command;
12
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 {
15 let command = Command::new(toolchain::cargo())
16 .args(&["check", "--message-format", "json"])
17 .output()
18 .unwrap()
19 .stdout;
20
21 for message in Message::parse_stream(command.as_slice()) {
22 match message.unwrap() {
23 Message::CompilerArtifact(artifact) => {
24 if artifact.target.kind.contains(&"proc-macro".to_string()) {
25 let repr = format!("{} {}", crate_name, version);
26 if artifact.package_id.repr.starts_with(&repr) {
27 return artifact.filenames[0].clone();
28 }
29 }
30 }
31 _ => (), // Unknown message
32 }
33 }
34
35 panic!("No proc-macro dylib for {} found!", crate_name);
36 }
37}
38
39fn parse_string(code: &str) -> Option<crate::rustc_server::TokenStream> {
40 Some(crate::rustc_server::TokenStream::from_str(code).unwrap())
41}
42
43pub fn assert_expand(
44 crate_name: &str,
45 macro_name: &str,
46 version: &str,
47 ra_fixture: &str,
48 expect: &str,
49) {
50 let path = fixtures::dylib_path(crate_name, version);
51 let expander = dylib::Expander::new(&path).unwrap();
52 let fixture = parse_string(ra_fixture).unwrap();
53
54 let res = expander.expand(macro_name, &fixture.subtree, None).unwrap();
55 assert_eq_text!(&format!("{:?}", res), &expect.trim());
56}
57
58pub fn list(crate_name: &str, version: &str) -> Vec<String> {
59 let path = fixtures::dylib_path(crate_name, version);
60 let task = ListMacrosTask { lib: path };
61 let mut srv = ProcMacroSrv::default();
62 let res = srv.list_macros(&task).unwrap();
63 res.macros.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()
64}