Skip to content

Commit 3948de3

Browse files
bors[bot]matklad
andauthored
Merge #2255
2255: Add convenience method for testing r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents e1b7af4 + 5766cea commit 3948de3

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

crates/ra_db/src/fixture.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use rustc_hash::FxHashMap;
88
use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER};
99

1010
use crate::{
11-
CrateGraph, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, SourceRoot,
12-
SourceRootId,
11+
CrateGraph, CrateId, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt,
12+
SourceRoot, SourceRootId,
1313
};
1414

1515
pub const WORKSPACE: SourceRootId = SourceRootId(0);
@@ -33,6 +33,14 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static {
3333
let pos = with_files(&mut db, fixture);
3434
(db, pos.unwrap())
3535
}
36+
37+
fn test_crate(&self) -> CrateId {
38+
let crate_graph = self.crate_graph();
39+
let mut it = crate_graph.iter();
40+
let res = it.next().unwrap();
41+
assert!(it.next().is_none());
42+
res
43+
}
3644
}
3745

3846
impl<DB: SourceDatabaseExt + Default + 'static> WithFixture for DB {}

crates/ra_hir_def/src/nameres/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ mod tests {
798798

799799
fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap {
800800
let (db, _file_id) = TestDB::with_single_file(&code);
801-
let krate = db.crate_graph().iter().next().unwrap();
801+
let krate = db.test_crate();
802802

803803
let def_map = {
804804
let edition = db.crate_graph().edition(krate);

crates/ra_hir_def/src/nameres/tests/incremental.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::sync::Arc;
22

3-
use ra_db::{SourceDatabase, SourceDatabaseExt};
3+
use ra_db::SourceDatabaseExt;
44

55
use super::*;
66

77
fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) {
88
let (mut db, pos) = TestDB::with_position(initial);
9-
let krate = db.crate_graph().iter().next().unwrap();
9+
let krate = db.test_crate();
1010
{
1111
let events = db.log_executed(|| {
1212
db.crate_def_map(krate);
@@ -111,7 +111,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
111111
m!(X);
112112
",
113113
);
114-
let krate = db.crate_graph().iter().next().unwrap();
114+
let krate = db.test_crate();
115115
{
116116
let events = db.log_executed(|| {
117117
let crate_def_map = db.crate_def_map(krate);

crates/ra_hir_def/src/nameres/tests/mod_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ fn unresolved_module_diagnostics() {
656656
//- /foo.rs
657657
",
658658
);
659-
let krate = db.crate_graph().iter().next().unwrap();
659+
let krate = db.test_crate();
660660

661661
let crate_def_map = db.crate_def_map(krate);
662662

0 commit comments

Comments
 (0)