diff options
author | Aleksey Kladov <[email protected]> | 2020-06-23 19:38:36 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-23 19:38:36 +0100 |
commit | 295c8d4f7f9ce9d3dc67e8a988914d90424c1b7e (patch) | |
tree | a3fc00ca2a19fa1294cf93030ff0d4a8d80f647f /crates | |
parent | a34f9b7fb343114446be08c7867b699b2210710f (diff) |
Complicate
Fixing test fallout unfortunately requires more work, we need to do
it, but let's merge something at least!
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/src/fixture.rs | 51 | ||||
-rw-r--r-- | crates/test_utils/src/fixture.rs | 7 |
2 files changed, 52 insertions, 6 deletions
diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index ea52ec563..20f291568 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs | |||
@@ -74,9 +74,8 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0); | |||
74 | pub trait WithFixture: Default + SourceDatabaseExt + 'static { | 74 | pub trait WithFixture: Default + SourceDatabaseExt + 'static { |
75 | fn with_single_file(text: &str) -> (Self, FileId) { | 75 | fn with_single_file(text: &str) -> (Self, FileId) { |
76 | let mut db = Self::default(); | 76 | let mut db = Self::default(); |
77 | let (_, files) = with_files(&mut db, text); | 77 | let file_id = with_single_file(&mut db, text); |
78 | assert!(files.len() == 1); | 78 | (db, file_id) |
79 | (db, files[0]) | ||
80 | } | 79 | } |
81 | 80 | ||
82 | fn with_files(ra_fixture: &str) -> Self { | 81 | fn with_files(ra_fixture: &str) -> Self { |
@@ -103,6 +102,52 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { | |||
103 | 102 | ||
104 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} | 103 | impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {} |
105 | 104 | ||
105 | fn with_single_file(db: &mut dyn SourceDatabaseExt, ra_fixture: &str) -> FileId { | ||
106 | let file_id = FileId(0); | ||
107 | let mut file_set = vfs::file_set::FileSet::default(); | ||
108 | file_set.insert(file_id, vfs::VfsPath::new_virtual_path("/main.rs".to_string())); | ||
109 | |||
110 | let source_root = SourceRoot::new_local(file_set); | ||
111 | |||
112 | let crate_graph = if let Some(meta) = ra_fixture.lines().find(|it| it.contains("//-")) { | ||
113 | let entry = Fixture::parse_single(meta.trim()); | ||
114 | let meta = match ParsedMeta::from(&entry) { | ||
115 | ParsedMeta::File(it) => it, | ||
116 | }; | ||
117 | |||
118 | let mut crate_graph = CrateGraph::default(); | ||
119 | crate_graph.add_crate_root( | ||
120 | file_id, | ||
121 | meta.edition, | ||
122 | meta.krate.map(|name| { | ||
123 | CrateName::new(&name).expect("Fixture crate name should not contain dashes") | ||
124 | }), | ||
125 | meta.cfg, | ||
126 | meta.env, | ||
127 | Default::default(), | ||
128 | ); | ||
129 | crate_graph | ||
130 | } else { | ||
131 | let mut crate_graph = CrateGraph::default(); | ||
132 | crate_graph.add_crate_root( | ||
133 | file_id, | ||
134 | Edition::Edition2018, | ||
135 | None, | ||
136 | CfgOptions::default(), | ||
137 | Env::default(), | ||
138 | Default::default(), | ||
139 | ); | ||
140 | crate_graph | ||
141 | }; | ||
142 | |||
143 | db.set_file_text(file_id, Arc::new(ra_fixture.to_string())); | ||
144 | db.set_file_source_root(file_id, WORKSPACE); | ||
145 | db.set_source_root(WORKSPACE, Arc::new(source_root)); | ||
146 | db.set_crate_graph(Arc::new(crate_graph)); | ||
147 | |||
148 | file_id | ||
149 | } | ||
150 | |||
106 | fn with_files( | 151 | fn with_files( |
107 | db: &mut dyn SourceDatabaseExt, | 152 | db: &mut dyn SourceDatabaseExt, |
108 | fixture: &str, | 153 | fixture: &str, |
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index ba00607f2..9108e49d9 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs | |||
@@ -55,8 +55,7 @@ The offending line: {:?}"#, | |||
55 | let mut res: Vec<Fixture> = Vec::new(); | 55 | let mut res: Vec<Fixture> = Vec::new(); |
56 | for line in lines.by_ref() { | 56 | for line in lines.by_ref() { |
57 | if line.starts_with("//-") { | 57 | if line.starts_with("//-") { |
58 | let meta = line["//-".len()..].trim().to_string(); | 58 | let meta = Fixture::parse_single(line); |
59 | let meta = Fixture::parse_single(&meta); | ||
60 | res.push(meta) | 59 | res.push(meta) |
61 | } else if let Some(entry) = res.last_mut() { | 60 | } else if let Some(entry) = res.last_mut() { |
62 | entry.text.push_str(line); | 61 | entry.text.push_str(line); |
@@ -67,7 +66,9 @@ The offending line: {:?}"#, | |||
67 | } | 66 | } |
68 | 67 | ||
69 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo | 68 | //- /lib.rs crate:foo deps:bar,baz cfg:foo=a,bar=b env:OUTDIR=path/to,OTHER=foo |
70 | fn parse_single(meta: &str) -> Fixture { | 69 | pub fn parse_single(meta: &str) -> Fixture { |
70 | assert!(meta.starts_with("//-")); | ||
71 | let meta = meta["//-".len()..].trim(); | ||
71 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); | 72 | let components = meta.split_ascii_whitespace().collect::<Vec<_>>(); |
72 | 73 | ||
73 | let path = components[0].to_string(); | 74 | let path = components[0].to_string(); |