From 58a6ec549d638455f5b5447bbbc174993e51e288 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 17 Apr 2021 21:34:14 +0200 Subject: Add some more error messages to fixture failure cases --- crates/base_db/src/fixture.rs | 4 ++-- crates/ide_assists/src/tests.rs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/base_db/src/fixture.rs b/crates/base_db/src/fixture.rs index 30f85bf3a..0132565e4 100644 --- a/crates/base_db/src/fixture.rs +++ b/crates/base_db/src/fixture.rs @@ -35,7 +35,7 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { fn with_position(ra_fixture: &str) -> (Self, FilePosition) { let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); let offset = match range_or_offset { - RangeOrOffset::Range(_) => panic!(), + RangeOrOffset::Range(_) => panic!("Expected a cursor position, got a range instead"), RangeOrOffset::Offset(it) => it, }; (db, FilePosition { file_id, offset }) @@ -45,7 +45,7 @@ pub trait WithFixture: Default + SourceDatabaseExt + 'static { let (db, file_id, range_or_offset) = Self::with_range_or_offset(ra_fixture); let range = match range_or_offset { RangeOrOffset::Range(it) => it, - RangeOrOffset::Offset(_) => panic!(), + RangeOrOffset::Offset(_) => panic!("Expected a cursor range, got a position instead"), }; (db, FileRange { file_id, range }) } diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index a7a923beb..60e3a1474 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs @@ -84,7 +84,8 @@ fn check_doc_test(assist_id: &str, before: &str, after: &str) { }); let actual = { - let source_change = assist.source_change.unwrap(); + let source_change = + assist.source_change.expect("Assist did not contain any source changes"); let mut actual = before; if let Some(source_file_edit) = source_change.get_source_edit(file_id) { source_file_edit.apply(&mut actual); @@ -121,7 +122,8 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label: match (assist, expected) { (Some(assist), ExpectedResult::After(after)) => { - let source_change = assist.source_change.unwrap(); + let source_change = + assist.source_change.expect("Assist did not contain any source changes"); assert!(!source_change.source_file_edits.is_empty()); let skip_header = source_change.source_file_edits.len() == 1 && source_change.file_system_edits.len() == 0; -- cgit v1.2.3