diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | crates/ra_db/src/fixture.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/mock_analysis.rs | 7 | ||||
-rw-r--r-- | crates/test_utils/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/test_utils/src/fixture.rs | 28 | ||||
-rw-r--r-- | crates/test_utils/src/lib.rs | 1 |
6 files changed, 31 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock index f2069c55e..9ea1765cb 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1664,7 +1664,6 @@ name = "test_utils" | |||
1664 | version = "0.1.0" | 1664 | version = "0.1.0" |
1665 | dependencies = [ | 1665 | dependencies = [ |
1666 | "difference", | 1666 | "difference", |
1667 | "ra_cfg", | ||
1668 | "rustc-hash", | 1667 | "rustc-hash", |
1669 | "serde_json", | 1668 | "serde_json", |
1670 | "stdx", | 1669 | "stdx", |
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 6c13e62bb..ea52ec563 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -203,11 +203,15 @@ struct FileMeta { | |||
203 | 203 | ||
204 | impl From<&Fixture> for ParsedMeta { | 204 | impl From<&Fixture> for ParsedMeta { |
205 | fn from(f: &Fixture) -> Self { | 205 | fn from(f: &Fixture) -> Self { |
206 | let mut cfg = CfgOptions::default(); | ||
207 | f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); | ||
208 | f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); | ||
209 | |||
206 | Self::File(FileMeta { | 210 | Self::File(FileMeta { |
207 | path: f.path.to_owned(), | 211 | path: f.path.to_owned(), |
208 | krate: f.crate_name.to_owned(), | 212 | krate: f.crate_name.to_owned(), |
209 | deps: f.deps.to_owned(), | 213 | deps: f.deps.to_owned(), |
210 | cfg: f.cfg.to_owned(), | 214 | cfg, |
211 | edition: f | 215 | edition: f |
212 | .edition | 216 | .edition |
213 | .as_ref() | 217 | .as_ref() |
diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index f15990158..981bdf924 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs | |||
@@ -38,7 +38,12 @@ impl MockFileData { | |||
38 | 38 | ||
39 | fn cfg_options(&self) -> CfgOptions { | 39 | fn cfg_options(&self) -> CfgOptions { |
40 | match self { | 40 | match self { |
41 | MockFileData::Fixture(f) => f.cfg.clone(), | 41 | MockFileData::Fixture(f) => { |
42 | let mut cfg = CfgOptions::default(); | ||
43 | f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); | ||
44 | f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); | ||
45 | cfg | ||
46 | } | ||
42 | _ => CfgOptions::default(), | 47 | _ => CfgOptions::default(), |
43 | } | 48 | } |
44 | } | 49 | } |
diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index afd2005f8..6821db1e8 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml | |||
@@ -8,10 +8,9 @@ authors = ["rust-analyzer developers"] | |||
8 | doctest = false | 8 | doctest = false |
9 | 9 | ||
10 | [dependencies] | 10 | [dependencies] |
11 | # Avoid adding deps here, this crate is widely used in tests it should compile fast! | ||
11 | difference = "2.0.0" | 12 | difference = "2.0.0" |
12 | text-size = "1.0.0" | 13 | text-size = "1.0.0" |
13 | serde_json = "1.0.48" | 14 | serde_json = "1.0.48" |
14 | rustc-hash = "1.1.0" | 15 | rustc-hash = "1.1.0" |
15 | |||
16 | ra_cfg = { path = "../ra_cfg" } | ||
17 | stdx = { path = "../stdx" } | 16 | stdx = { path = "../stdx" } |
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 2a51bb559..44cf835b3 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -1,4 +1,3 @@ | |||
1 | use ra_cfg::CfgOptions; | ||
2 | use rustc_hash::FxHashMap; | 1 | use rustc_hash::FxHashMap; |
3 | use stdx::split1; | 2 | use stdx::split1; |
4 | 3 | ||
@@ -8,7 +7,8 @@ pub struct Fixture { | |||
8 | pub text: String, | 7 | pub text: String, |
9 | pub crate_name: Option<String>, | 8 | pub crate_name: Option<String>, |
10 | pub deps: Vec<String>, | 9 | pub deps: Vec<String>, |
11 | pub cfg: CfgOptions, | 10 | pub cfg_atoms: Vec<String>, |
11 | pub cfg_key_values: Vec<(String, String)>, | ||
12 | pub edition: Option<String>, | 12 | pub edition: Option<String>, |
13 | pub env: FxHashMap<String, String>, | 13 | pub env: FxHashMap<String, String>, |
14 | } | 14 | } |
@@ -73,7 +73,8 @@ The offending line: {:?}"#, | |||
73 | let mut krate = None; | 73 | let mut krate = None; |
74 | let mut deps = Vec::new(); | 74 | let mut deps = Vec::new(); |
75 | let mut edition = None; | 75 | let mut edition = None; |
76 | let mut cfg = CfgOptions::default(); | 76 | let mut cfg_atoms = Vec::new(); |
77 | let mut cfg_key_values = Vec::new(); | ||
77 | let mut env = FxHashMap::default(); | 78 | let mut env = FxHashMap::default(); |
78 | for component in components[1..].iter() { | 79 | for component in components[1..].iter() { |
79 | let (key, value) = split1(component, ':').unwrap(); | 80 | let (key, value) = split1(component, ':').unwrap(); |
@@ -82,10 +83,10 @@ The offending line: {:?}"#, | |||
82 | "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), | 83 | "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), |
83 | "edition" => edition = Some(value.to_string()), | 84 | "edition" => edition = Some(value.to_string()), |
84 | "cfg" => { | 85 | "cfg" => { |
85 | for key in value.split(',') { | 86 | for entry in value.split(',') { |
86 | match split1(key, '=') { | 87 | match split1(entry, '=') { |
87 | None => cfg.insert_atom(key.into()), | 88 | Some((k, v)) => cfg_key_values.push((k.to_string(), v.to_string())), |
88 | Some((k, v)) => cfg.insert_key_value(k.into(), v.into()), | 89 | None => cfg_atoms.push(entry.to_string()), |
89 | } | 90 | } |
90 | } | 91 | } |
91 | } | 92 | } |
@@ -100,7 +101,16 @@ The offending line: {:?}"#, | |||
100 | } | 101 | } |
101 | } | 102 | } |
102 | 103 | ||
103 | Fixture { path, text: String::new(), crate_name: krate, deps, edition, cfg, env } | 104 | Fixture { |
105 | path, | ||
106 | text: String::new(), | ||
107 | crate_name: krate, | ||
108 | deps, | ||
109 | cfg_atoms, | ||
110 | cfg_key_values, | ||
111 | edition, | ||
112 | env, | ||
113 | } | ||
104 | } | 114 | } |
105 | } | 115 | } |
106 | 116 | ||
@@ -152,7 +162,7 @@ fn indent_len(s: &str) -> usize { | |||
152 | #[test] | 162 | #[test] |
153 | #[should_panic] | 163 | #[should_panic] |
154 | fn parse_fixture_checks_further_indented_metadata() { | 164 | fn parse_fixture_checks_further_indented_metadata() { |
155 | parse_fixture( | 165 | Fixture::parse( |
156 | r" | 166 | r" |
157 | //- /lib.rs | 167 | //- /lib.rs |
158 | mod bar; | 168 | mod bar; |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 316f3d501..3fd8505ed 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -19,7 +19,6 @@ use serde_json::Value; | |||
19 | use text_size::{TextRange, TextSize}; | 19 | use text_size::{TextRange, TextSize}; |
20 | 20 | ||
21 | pub use difference::Changeset as __Changeset; | 21 | pub use difference::Changeset as __Changeset; |
22 | pub use ra_cfg::CfgOptions; | ||
23 | pub use rustc_hash::FxHashMap; | 22 | pub use rustc_hash::FxHashMap; |
24 | 23 | ||
25 | pub use crate::fixture::Fixture; | 24 | pub use crate::fixture::Fixture; |