From 5258c817f78ecdfe12d7eec44ab3169134cba71d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 11:54:57 +0200 Subject: Remove cross-crate marks They create quite a bit of friction. Really, we should just move the tests to the same crate, rather than paper over existing split. --- crates/ra_ide/src/goto_definition.rs | 10 +--------- crates/ra_ide/src/references.rs | 3 --- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 150895abb..90e85d419 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -93,7 +93,7 @@ pub(crate) fn reference_definition( #[cfg(test)] mod tests { - use test_utils::{assert_eq_text, covers}; + use test_utils::assert_eq_text; use crate::mock_analysis::analysis_and_position; @@ -208,7 +208,6 @@ mod tests { #[test] fn goto_def_for_macros() { - covers!(ra_ide_db::goto_def_for_macros); check_goto( " //- /lib.rs @@ -225,7 +224,6 @@ mod tests { #[test] fn goto_def_for_macros_from_other_crates() { - covers!(ra_ide_db::goto_def_for_macros); check_goto( " //- /lib.rs @@ -245,7 +243,6 @@ mod tests { #[test] fn goto_def_for_use_alias() { - covers!(ra_ide_db::goto_def_for_use_alias); check_goto( " //- /lib.rs @@ -370,7 +367,6 @@ mod tests { #[test] fn goto_def_for_methods() { - covers!(ra_ide_db::goto_def_for_methods); check_goto( " //- /lib.rs @@ -390,7 +386,6 @@ mod tests { #[test] fn goto_def_for_fields() { - covers!(ra_ide_db::goto_def_for_fields); check_goto( r" //- /lib.rs @@ -409,7 +404,6 @@ mod tests { #[test] fn goto_def_for_record_fields() { - covers!(ra_ide_db::goto_def_for_record_fields); check_goto( r" //- /lib.rs @@ -430,7 +424,6 @@ mod tests { #[test] fn goto_def_for_record_pat_fields() { - covers!(ra_ide_db::goto_def_for_record_field_pats); check_goto( r" //- /lib.rs @@ -873,7 +866,6 @@ mod tests { #[test] fn goto_def_for_field_init_shorthand() { - covers!(ra_ide_db::goto_def_for_field_init_shorthand); check_goto( " //- /lib.rs diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 074284b42..96444bf6a 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -190,8 +190,6 @@ fn get_struct_def_name_for_struct_literal_search( #[cfg(test)] mod tests { - use test_utils::covers; - use crate::{ mock_analysis::{analysis_and_position, single_file_with_position, MockAnalysis}, Declaration, Reference, ReferenceSearchResult, SearchScope, @@ -301,7 +299,6 @@ mod tests { #[test] fn search_filters_by_range() { - covers!(ra_ide_db::search_filters_by_range); let code = r#" fn foo() { let spam<|> = 92; -- cgit v1.2.3 From ecac5d7de2192873c24b7b06d4964d188d8abe6a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 12:59:20 +0200 Subject: Switch to new magic marks --- crates/ra_ide/src/call_info.rs | 8 ++++---- .../src/completion/complete_qualified_path.rs | 8 ++++---- .../src/completion/complete_unqualified_path.rs | 8 ++++---- crates/ra_ide/src/completion/presentation.rs | 24 +++++++++++----------- crates/ra_ide/src/lib.rs | 2 -- crates/ra_ide/src/marks.rs | 16 --------------- crates/ra_ide/src/parent_module.rs | 8 ++++---- crates/ra_ide/src/references/rename.rs | 12 +++++------ 8 files changed, 34 insertions(+), 52 deletions(-) delete mode 100644 crates/ra_ide/src/marks.rs (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 780a03c13..aa039e6fc 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -5,7 +5,7 @@ use ra_syntax::{ ast::{self, ArgListOwner}, match_ast, AstNode, SyntaxNode, SyntaxToken, }; -use test_utils::tested_by; +use test_utils::mark; use crate::{CallInfo, FilePosition, FunctionSignature}; @@ -84,7 +84,7 @@ fn call_info_for_token(sema: &Semantics, token: SyntaxToken) -> Op let arg_list_range = arg_list.syntax().text_range(); if !arg_list_range.contains_inclusive(token.text_range().start()) { - tested_by!(call_info_bad_offset); + mark::hit!(call_info_bad_offset); return None; } @@ -213,7 +213,7 @@ impl CallInfo { #[cfg(test)] mod tests { - use test_utils::covers; + use test_utils::mark; use crate::mock_analysis::single_file_with_position; @@ -529,7 +529,7 @@ By default this method stops actor's `Context`."# #[test] fn call_info_bad_offset() { - covers!(call_info_bad_offset); + mark::check!(call_info_bad_offset); let (analysis, position) = single_file_with_position( r#"fn foo(x: u32, y: u32) -> u32 {x + y} fn bar() { foo <|> (3, ); }"#, diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs index db7430454..02ac0166b 100644 --- a/crates/ra_ide/src/completion/complete_qualified_path.rs +++ b/crates/ra_ide/src/completion/complete_qualified_path.rs @@ -3,7 +3,7 @@ use hir::{Adt, HasVisibility, PathResolution, ScopeDef}; use ra_syntax::AstNode; use rustc_hash::FxHashSet; -use test_utils::tested_by; +use test_utils::mark; use crate::completion::{CompletionContext, Completions}; @@ -40,7 +40,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon if let Some(name_ref) = ctx.name_ref_syntax.as_ref() { if name_ref.syntax().text() == name.to_string().as_str() { // for `use self::foo<|>`, don't suggest `foo` as a completion - tested_by!(dont_complete_current_use); + mark::hit!(dont_complete_current_use); continue; } } @@ -147,7 +147,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon #[cfg(test)] mod tests { - use test_utils::covers; + use test_utils::mark; use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; use insta::assert_debug_snapshot; @@ -158,7 +158,7 @@ mod tests { #[test] fn dont_complete_current_use() { - covers!(dont_complete_current_use); + mark::check!(dont_complete_current_use); let completions = do_completion(r"use self::foo<|>;", CompletionKind::Reference); assert!(completions.is_empty()); } diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index bd40af1cb..db791660a 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs @@ -1,7 +1,7 @@ //! Completion of names from the current scope, e.g. locals and imported items. use hir::ScopeDef; -use test_utils::tested_by; +use test_utils::mark; use crate::completion::{CompletionContext, Completions}; use hir::{Adt, ModuleDef, Type}; @@ -30,7 +30,7 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC if ctx.use_item_syntax.is_some() { if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { if name_ref.syntax().text() == name.to_string().as_str() { - tested_by!(self_fulfilling_completion); + mark::hit!(self_fulfilling_completion); return; } } @@ -66,7 +66,7 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T #[cfg(test)] mod tests { use insta::assert_debug_snapshot; - use test_utils::covers; + use test_utils::mark; use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; @@ -76,7 +76,7 @@ mod tests { #[test] fn self_fulfilling_completion() { - covers!(self_fulfilling_completion); + mark::check!(self_fulfilling_completion); assert_debug_snapshot!( do_reference_completion( r#" diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 077cf9647..440ffa31d 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -3,7 +3,7 @@ use hir::{Docs, HasAttrs, HasSource, HirDisplay, ModPath, ScopeDef, StructKind, Type}; use ra_syntax::ast::NameOwner; use stdx::SepBy; -use test_utils::tested_by; +use test_utils::mark; use crate::{ completion::{ @@ -121,7 +121,7 @@ impl Completions { _ => false, }; if has_non_default_type_params { - tested_by!(inserts_angle_brackets_for_generics); + mark::hit!(inserts_angle_brackets_for_generics); completion_item = completion_item .lookup_by(local_name.clone()) .label(format!("{}<…>", local_name)) @@ -176,7 +176,7 @@ impl Completions { } None if needs_bang => builder.insert_text(format!("{}!", name)), _ => { - tested_by!(dont_insert_macro_call_parens_unncessary); + mark::hit!(dont_insert_macro_call_parens_unncessary); builder.insert_text(name) } }; @@ -330,14 +330,14 @@ pub(crate) fn compute_score( // FIXME: this should not fall back to string equality. let ty = &ty.display(ctx.db).to_string(); let (active_name, active_type) = if let Some(record_field) = &ctx.record_field_syntax { - tested_by!(test_struct_field_completion_in_record_lit); + mark::hit!(test_struct_field_completion_in_record_lit); let (struct_field, _local) = ctx.sema.resolve_record_field(record_field)?; ( struct_field.name(ctx.db).to_string(), struct_field.signature_ty(ctx.db).display(ctx.db).to_string(), ) } else if let Some(active_parameter) = &ctx.active_parameter { - tested_by!(test_struct_field_completion_in_func_call); + mark::hit!(test_struct_field_completion_in_func_call); (active_parameter.name.clone(), active_parameter.ty.clone()) } else { return None; @@ -398,7 +398,7 @@ impl Builder { None => return self, }; // If not an import, add parenthesis automatically. - tested_by!(inserts_parens_for_function_calls); + mark::hit!(inserts_parens_for_function_calls); let (snippet, label) = if params.is_empty() { (format!("{}()$0", name), format!("{}()", name)) @@ -457,7 +457,7 @@ fn guess_macro_braces(macro_name: &str, docs: &str) -> (&'static str, &'static s #[cfg(test)] mod tests { use insta::assert_debug_snapshot; - use test_utils::covers; + use test_utils::mark; use crate::completion::{ test_utils::{do_completion, do_completion_with_options}, @@ -607,7 +607,7 @@ mod tests { #[test] fn inserts_parens_for_function_calls() { - covers!(inserts_parens_for_function_calls); + mark::check!(inserts_parens_for_function_calls); assert_debug_snapshot!( do_reference_completion( r" @@ -992,7 +992,7 @@ mod tests { #[test] fn inserts_angle_brackets_for_generics() { - covers!(inserts_angle_brackets_for_generics); + mark::check!(inserts_angle_brackets_for_generics); assert_debug_snapshot!( do_reference_completion( r" @@ -1115,7 +1115,7 @@ mod tests { #[test] fn dont_insert_macro_call_parens_unncessary() { - covers!(dont_insert_macro_call_parens_unncessary); + mark::check!(dont_insert_macro_call_parens_unncessary); assert_debug_snapshot!( do_reference_completion( r" @@ -1181,7 +1181,7 @@ mod tests { #[test] fn test_struct_field_completion_in_func_call() { - covers!(test_struct_field_completion_in_func_call); + mark::check!(test_struct_field_completion_in_func_call); assert_debug_snapshot!( do_reference_completion( r" @@ -1271,7 +1271,7 @@ mod tests { #[test] fn test_struct_field_completion_in_record_lit() { - covers!(test_struct_field_completion_in_record_lit); + mark::check!(test_struct_field_completion_in_record_lit); assert_debug_snapshot!( do_reference_completion( r" diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 66125f2f5..83cb498f7 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -42,8 +42,6 @@ mod inlay_hints; mod expand_macro; mod ssr; -#[cfg(test)] -mod marks; #[cfg(test)] mod test_utils; diff --git a/crates/ra_ide/src/marks.rs b/crates/ra_ide/src/marks.rs deleted file mode 100644 index 51ca4dde3..000000000 --- a/crates/ra_ide/src/marks.rs +++ /dev/null @@ -1,16 +0,0 @@ -//! See test_utils/src/marks.rs - -test_utils::marks!( - inserts_angle_brackets_for_generics - inserts_parens_for_function_calls - call_info_bad_offset - dont_complete_current_use - test_resolve_parent_module_on_module_decl - search_filters_by_range - dont_insert_macro_call_parens_unncessary - self_fulfilling_completion - test_struct_field_completion_in_func_call - test_struct_field_completion_in_record_lit - test_rename_struct_field_for_shorthand - test_rename_local_for_field_shorthand -); diff --git a/crates/ra_ide/src/parent_module.rs b/crates/ra_ide/src/parent_module.rs index aaf4460df..a083fb1eb 100644 --- a/crates/ra_ide/src/parent_module.rs +++ b/crates/ra_ide/src/parent_module.rs @@ -7,7 +7,7 @@ use ra_syntax::{ algo::find_node_at_offset, ast::{self, AstNode}, }; -use test_utils::tested_by; +use test_utils::mark; use crate::NavigationTarget; @@ -25,7 +25,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec Vec { mod tests { use ra_cfg::CfgOptions; use ra_db::Env; - use test_utils::covers; + use test_utils::mark; use crate::{ mock_analysis::{analysis_and_position, MockAnalysis}, @@ -81,7 +81,7 @@ mod tests { #[test] fn test_resolve_parent_module_on_module_decl() { - covers!(test_resolve_parent_module_on_module_decl); + mark::check!(test_resolve_parent_module_on_module_decl); let (analysis, pos) = analysis_and_position( " //- /lib.rs diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index 68a53ad4b..62ec8d85d 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs @@ -9,7 +9,7 @@ use ra_syntax::{ }; use ra_text_edit::TextEdit; use std::convert::TryInto; -use test_utils::tested_by; +use test_utils::mark; use crate::{ references::find_all_refs, FilePosition, FileSystemEdit, RangeInfo, Reference, ReferenceKind, @@ -57,13 +57,13 @@ fn source_edit_from_reference(reference: Reference, new_name: &str) -> SourceFil let file_id = reference.file_range.file_id; let range = match reference.kind { ReferenceKind::FieldShorthandForField => { - tested_by!(test_rename_struct_field_for_shorthand); + mark::hit!(test_rename_struct_field_for_shorthand); replacement_text.push_str(new_name); replacement_text.push_str(": "); TextRange::new(reference.file_range.range.start(), reference.file_range.range.start()) } ReferenceKind::FieldShorthandForLocal => { - tested_by!(test_rename_local_for_field_shorthand); + mark::hit!(test_rename_local_for_field_shorthand); replacement_text.push_str(": "); replacement_text.push_str(new_name); TextRange::new(reference.file_range.range.end(), reference.file_range.range.end()) @@ -260,7 +260,7 @@ fn rename_reference( mod tests { use insta::assert_debug_snapshot; use ra_text_edit::TextEditBuilder; - use test_utils::{assert_eq_text, covers}; + use test_utils::{assert_eq_text, mark}; use crate::{ mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId, @@ -492,7 +492,7 @@ mod tests { #[test] fn test_rename_struct_field_for_shorthand() { - covers!(test_rename_struct_field_for_shorthand); + mark::check!(test_rename_struct_field_for_shorthand); test_rename( r#" struct Foo { @@ -522,7 +522,7 @@ mod tests { #[test] fn test_rename_local_for_field_shorthand() { - covers!(test_rename_local_for_field_shorthand); + mark::check!(test_rename_local_for_field_shorthand); test_rename( r#" struct Foo { -- cgit v1.2.3