aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/base_db/src/fixture.rs4
-rw-r--r--crates/hir_def/src/nameres/tests/mod_resolution.rs17
-rw-r--r--crates/test_utils/src/fixture.rs4
3 files changed, 22 insertions, 3 deletions
diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs
index 66e6443cb..3c6c516b2 100644
--- a/crates/base_db/src/fixture.rs
+++ b/crates/base_db/src/fixture.rs
@@ -150,6 +150,8 @@ impl ChangeFixture {
150 entry.text.clone() 150 entry.text.clone()
151 }; 151 };
152 152
153 let explicit_root = entry.explicit_root;
154
153 let meta = FileMeta::from(entry); 155 let meta = FileMeta::from(entry);
154 assert!(meta.path.starts_with(&source_root_prefix)); 156 assert!(meta.path.starts_with(&source_root_prefix));
155 157
@@ -169,7 +171,7 @@ impl ChangeFixture {
169 let dep = CrateName::normalize_dashes(&dep); 171 let dep = CrateName::normalize_dashes(&dep);
170 crate_deps.push((crate_name.clone(), dep)) 172 crate_deps.push((crate_name.clone(), dep))
171 } 173 }
172 } else if meta.path == "/main.rs" || meta.path == "/lib.rs" { 174 } else if meta.path == "/main.rs" || meta.path == "/lib.rs" || explicit_root {
173 assert!(default_crate_root.is_none()); 175 assert!(default_crate_root.is_none());
174 default_crate_root = Some(file_id); 176 default_crate_root = Some(file_id);
175 default_cfg = meta.cfg; 177 default_cfg = meta.cfg;
diff --git a/crates/hir_def/src/nameres/tests/mod_resolution.rs b/crates/hir_def/src/nameres/tests/mod_resolution.rs
index f93337a6e..0b2b4429d 100644
--- a/crates/hir_def/src/nameres/tests/mod_resolution.rs
+++ b/crates/hir_def/src/nameres/tests/mod_resolution.rs
@@ -323,13 +323,26 @@ pub struct Baz;
323fn module_resolution_relative_path_outside_root() { 323fn module_resolution_relative_path_outside_root() {
324 check( 324 check(
325 r#" 325 r#"
326//- /main.rs 326//- /a/b/c/d/e/main.rs root:
327#[path="../../../../../outside.rs"] 327#[path="../../../../../outside.rs"]
328mod foo; 328mod foo;
329
330//- /outside.rs
331mod bar;
332
333//- /bar.rs
334pub struct Baz;
329"#, 335"#,
330 expect![[r#" 336 expect![[r#"
331 crate 337 crate
332 "#]], 338 foo: t
339
340 crate::foo
341 bar: t
342
343 crate::foo::bar
344 Baz: t v
345"#]],
333 ); 346 );
334} 347}
335 348
diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs
index e40b61a94..806ab06c1 100644
--- a/crates/test_utils/src/fixture.rs
+++ b/crates/test_utils/src/fixture.rs
@@ -8,6 +8,7 @@ use stdx::{lines_with_ends, split_once, trim_indent};
8pub struct Fixture { 8pub struct Fixture {
9 pub path: String, 9 pub path: String,
10 pub text: String, 10 pub text: String,
11 pub explicit_root: bool,
11 pub krate: Option<String>, 12 pub krate: Option<String>,
12 pub deps: Vec<String>, 13 pub deps: Vec<String>,
13 pub cfg_atoms: Vec<String>, 14 pub cfg_atoms: Vec<String>,
@@ -64,6 +65,7 @@ impl Fixture {
64 let path = components[0].to_string(); 65 let path = components[0].to_string();
65 assert!(path.starts_with('/')); 66 assert!(path.starts_with('/'));
66 67
68 let mut explicit_root = false;
67 let mut krate = None; 69 let mut krate = None;
68 let mut deps = Vec::new(); 70 let mut deps = Vec::new();
69 let mut edition = None; 71 let mut edition = None;
@@ -73,6 +75,7 @@ impl Fixture {
73 for component in components[1..].iter() { 75 for component in components[1..].iter() {
74 let (key, value) = split_once(component, ':').unwrap(); 76 let (key, value) = split_once(component, ':').unwrap();
75 match key { 77 match key {
78 "root" => explicit_root = true,
76 "crate" => krate = Some(value.to_string()), 79 "crate" => krate = Some(value.to_string()),
77 "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), 80 "deps" => deps = value.split(',').map(|it| it.to_string()).collect(),
78 "edition" => edition = Some(value.to_string()), 81 "edition" => edition = Some(value.to_string()),
@@ -98,6 +101,7 @@ impl Fixture {
98 Fixture { 101 Fixture {
99 path, 102 path,
100 text: String::new(), 103 text: String::new(),
104 explicit_root: explicit_root,
101 krate: krate, 105 krate: krate,
102 deps, 106 deps,
103 cfg_atoms, 107 cfg_atoms,