From 5766ceab0629acc4464dcc57d00d9cc5c12f1c6b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 13:16:16 +0300 Subject: Add convenience method for testing --- crates/ra_db/src/fixture.rs | 12 ++++++++++-- crates/ra_hir_def/src/nameres/collector.rs | 2 +- crates/ra_hir_def/src/nameres/tests/incremental.rs | 6 +++--- crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) (limited to 'crates') diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index ee883b615..ade187629 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs @@ -8,8 +8,8 @@ use rustc_hash::FxHashMap; use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; use crate::{ - CrateGraph, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, SourceRoot, - SourceRootId, + CrateGraph, CrateId, Edition, FileId, FilePosition, RelativePathBuf, SourceDatabaseExt, + SourceRoot, SourceRootId, }; pub const WORKSPACE: SourceRootId = SourceRootId(0); @@ -33,6 +33,14 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { let pos = with_files(&mut db, fixture); (db, pos.unwrap()) } + + fn test_crate(&self) -> CrateId { + let crate_graph = self.crate_graph(); + let mut it = crate_graph.iter(); + let res = it.next().unwrap(); + assert!(it.next().is_none()); + res + } } impl WithFixture for DB {} diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 37d0f3093..83eef821f 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -798,7 +798,7 @@ mod tests { fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { let (db, _file_id) = TestDB::with_single_file(&code); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); let def_map = { let edition = db.crate_graph().edition(krate); diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs index 80dcec62f..903a22771 100644 --- a/crates/ra_hir_def/src/nameres/tests/incremental.rs +++ b/crates/ra_hir_def/src/nameres/tests/incremental.rs @@ -1,12 +1,12 @@ use std::sync::Arc; -use ra_db::{SourceDatabase, SourceDatabaseExt}; +use ra_db::SourceDatabaseExt; use super::*; fn check_def_map_is_not_recomputed(initial: &str, file_change: &str) { let (mut db, pos) = TestDB::with_position(initial); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); { let events = db.log_executed(|| { db.crate_def_map(krate); @@ -111,7 +111,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { m!(X); ", ); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); { let events = db.log_executed(|| { let crate_def_map = db.crate_def_map(krate); diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs index dee364a14..eb7b85c07 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs @@ -656,7 +656,7 @@ fn unresolved_module_diagnostics() { //- /foo.rs ", ); - let krate = db.crate_graph().iter().next().unwrap(); + let krate = db.test_crate(); let crate_def_map = db.crate_def_map(krate); -- cgit v1.2.3