From d18d1c05949eaa890e7bb75710816a61b09a93dd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 00:19:59 +0200 Subject: Significantly more glorious marks --- crates/ra_assists/src/handlers/add_turbo_fish.rs | 12 ++-- crates/ra_assists/src/marks.rs | 2 - crates/test_utils/src/lib.rs | 2 + crates/test_utils/src/mark.rs | 78 ++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 crates/test_utils/src/mark.rs (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/add_turbo_fish.rs b/crates/ra_assists/src/handlers/add_turbo_fish.rs index a0363bc78..26acf81f2 100644 --- a/crates/ra_assists/src/handlers/add_turbo_fish.rs +++ b/crates/ra_assists/src/handlers/add_turbo_fish.rs @@ -1,11 +1,11 @@ use ra_ide_db::defs::{classify_name_ref, Definition, NameRefClass}; use ra_syntax::{ast, AstNode, SyntaxKind, T}; +use test_utils::mark; use crate::{ assist_context::{AssistContext, Assists}, AssistId, }; -use test_utils::tested_by; // Assist: add_turbo_fish // @@ -28,7 +28,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<( let ident = ctx.find_token_at_offset(SyntaxKind::IDENT)?; let next_token = ident.next_token()?; if next_token.kind() == T![::] { - tested_by!(add_turbo_fish_one_fish_is_enough); + mark::hit!(add_turbo_fish_one_fish_is_enough); return None; } let name_ref = ast::NameRef::cast(ident.parent())?; @@ -42,7 +42,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<( }; let generics = hir::GenericDef::Function(fun).params(ctx.sema.db); if generics.is_empty() { - tested_by!(add_turbo_fish_non_generic); + mark::hit!(add_turbo_fish_non_generic); return None; } acc.add(AssistId("add_turbo_fish"), "Add `::<>`", ident.text_range(), |builder| { @@ -58,7 +58,7 @@ mod tests { use crate::tests::{check_assist, check_assist_not_applicable}; use super::*; - use test_utils::covers; + use test_utils::mark; #[test] fn add_turbo_fish_function() { @@ -106,7 +106,7 @@ fn main() { #[test] fn add_turbo_fish_one_fish_is_enough() { - covers!(add_turbo_fish_one_fish_is_enough); + mark::check!(add_turbo_fish_one_fish_is_enough); check_assist_not_applicable( add_turbo_fish, r#" @@ -120,7 +120,7 @@ fn main() { #[test] fn add_turbo_fish_non_generic() { - covers!(add_turbo_fish_non_generic); + mark::check!(add_turbo_fish_non_generic); check_assist_not_applicable( add_turbo_fish, r#" diff --git a/crates/ra_assists/src/marks.rs b/crates/ra_assists/src/marks.rs index 722f3c6a4..525ec4abc 100644 --- a/crates/ra_assists/src/marks.rs +++ b/crates/ra_assists/src/marks.rs @@ -10,6 +10,4 @@ test_utils::marks![ test_not_applicable_if_variable_unused change_visibility_field_false_positive test_add_from_impl_already_exists - add_turbo_fish_one_fish_is_enough - add_turbo_fish_non_generic ]; diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index b1e3c328f..4e05d464f 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -8,6 +8,8 @@ #[macro_use] pub mod marks; +#[macro_use] +pub mod mark; use std::{ fs, diff --git a/crates/test_utils/src/mark.rs b/crates/test_utils/src/mark.rs new file mode 100644 index 000000000..7c309a894 --- /dev/null +++ b/crates/test_utils/src/mark.rs @@ -0,0 +1,78 @@ +//! This module implements manually tracked test coverage, which is useful for +//! quickly finding a test responsible for testing a particular bit of code. +//! +//! See +//! for details, but the TL;DR is that you write your test as +//! +//! ``` +//! #[test] +//! fn test_foo() { +//! mark::check!(test_foo); +//! } +//! ``` +//! +//! and in the code under test you write +//! +//! ``` +//! # use test_utils::mark; +//! # fn some_condition() -> bool { true } +//! fn foo() { +//! if some_condition() { +//! mark::hit!(test_foo); +//! } +//! } +//! ``` +//! +//! This module then checks that executing the test indeed covers the specified +//! function. This is useful if you come back to the `foo` function ten years +//! later and wonder where the test are: now you can grep for `test_foo`. +use std::sync::atomic::{AtomicUsize, Ordering}; + +#[macro_export] +macro_rules! _hit { + ($ident:ident) => {{ + #[cfg(test)] + { + extern "C" { + #[no_mangle] + static $ident: std::sync::atomic::AtomicUsize; + } + unsafe { + $ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + } + } + }}; +} +pub use _hit as hit; + +#[macro_export] +macro_rules! _check { + ($ident:ident) => { + #[no_mangle] + static $ident: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + let _checker = $crate::mark::MarkChecker::new(&$ident); + }; +} +pub use _check as check; + +pub struct MarkChecker { + mark: &'static AtomicUsize, + value_on_entry: usize, +} + +impl MarkChecker { + pub fn new(mark: &'static AtomicUsize) -> MarkChecker { + let value_on_entry = mark.load(Ordering::SeqCst); + MarkChecker { mark, value_on_entry } + } +} + +impl Drop for MarkChecker { + fn drop(&mut self) { + if std::thread::panicking() { + return; + } + let value_on_exit = self.mark.load(Ordering::SeqCst); + assert!(value_on_exit > self.value_on_entry, "mark was not hit") + } +} -- cgit v1.2.3 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 --- crates/ra_ide_db/src/defs.rs | 10 ++-------- crates/ra_ide_db/src/lib.rs | 1 - crates/ra_ide_db/src/marks.rs | 12 ------------ crates/ra_ide_db/src/search.rs | 2 -- crates/test_utils/src/marks.rs | 11 +---------- 7 files changed, 4 insertions(+), 45 deletions(-) delete mode 100644 crates/ra_ide_db/src/marks.rs (limited to 'crates') 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; diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index 60c11178e..8b06cbfc5 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -14,7 +14,6 @@ use ra_syntax::{ ast::{self, AstNode}, match_ast, }; -use test_utils::tested_by; use crate::RootDatabase; @@ -118,7 +117,6 @@ fn classify_name_inner(sema: &Semantics, name: &ast::Name) -> Opti match_ast! { match parent { ast::Alias(it) => { - tested_by!(goto_def_for_use_alias; force); let use_tree = it.syntax().parent().and_then(ast::UseTree::cast)?; let path = use_tree.path()?; let path_segment = path.segment()?; @@ -203,6 +201,8 @@ impl NameRefClass { } } +// Note: we don't have unit-tests for this rather important function. +// It is primarily exercised via goto definition tests in `ra_ide`. pub fn classify_name_ref( sema: &Semantics, name_ref: &ast::NameRef, @@ -212,22 +212,18 @@ pub fn classify_name_ref( let parent = name_ref.syntax().parent()?; if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) { - tested_by!(goto_def_for_methods; force); if let Some(func) = sema.resolve_method_call(&method_call) { return Some(NameRefClass::Definition(Definition::ModuleDef(func.into()))); } } if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) { - tested_by!(goto_def_for_fields; force); if let Some(field) = sema.resolve_field(&field_expr) { return Some(NameRefClass::Definition(Definition::Field(field))); } } if let Some(record_field) = ast::RecordField::for_field_name(name_ref) { - tested_by!(goto_def_for_record_fields; force); - tested_by!(goto_def_for_field_init_shorthand; force); if let Some((field, local)) = sema.resolve_record_field(&record_field) { let field = Definition::Field(field); let res = match local { @@ -239,7 +235,6 @@ pub fn classify_name_ref( } if let Some(record_field_pat) = ast::RecordFieldPat::cast(parent.clone()) { - tested_by!(goto_def_for_record_field_pats; force); if let Some(field) = sema.resolve_record_field_pat(&record_field_pat) { let field = Definition::Field(field); return Some(NameRefClass::Definition(field)); @@ -247,7 +242,6 @@ pub fn classify_name_ref( } if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) { - tested_by!(goto_def_for_macros; force); if let Some(macro_def) = sema.resolve_macro_call(¯o_call) { return Some(NameRefClass::Definition(Definition::Macro(macro_def))); } diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 52fcd7b6f..4f37954bf 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs @@ -2,7 +2,6 @@ //! //! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search. -pub mod marks; pub mod line_index; pub mod line_index_utils; pub mod symbol_index; diff --git a/crates/ra_ide_db/src/marks.rs b/crates/ra_ide_db/src/marks.rs deleted file mode 100644 index 386fe605c..000000000 --- a/crates/ra_ide_db/src/marks.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! See test_utils/src/marks.rs - -test_utils::marks![ - goto_def_for_macros - goto_def_for_use_alias - goto_def_for_methods - goto_def_for_fields - goto_def_for_record_fields - goto_def_for_field_init_shorthand - goto_def_for_record_field_pats - search_filters_by_range -]; diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs index b464959fc..589f44771 100644 --- a/crates/ra_ide_db/src/search.rs +++ b/crates/ra_ide_db/src/search.rs @@ -12,7 +12,6 @@ use ra_db::{FileId, FileRange, SourceDatabaseExt}; use ra_prof::profile; use ra_syntax::{ast, match_ast, AstNode, TextRange, TextSize}; use rustc_hash::FxHashMap; -use test_utils::tested_by; use crate::{ defs::{classify_name_ref, Definition, NameRefClass}, @@ -209,7 +208,6 @@ impl Definition { for (idx, _) in text.match_indices(pat) { let offset: TextSize = idx.try_into().unwrap(); if !search_range.contains_inclusive(offset) { - tested_by!(search_filters_by_range; force); continue; } diff --git a/crates/test_utils/src/marks.rs b/crates/test_utils/src/marks.rs index c3185e860..f20fb978e 100644 --- a/crates/test_utils/src/marks.rs +++ b/crates/test_utils/src/marks.rs @@ -30,12 +30,6 @@ use std::sync::atomic::{AtomicUsize, Ordering}; #[macro_export] macro_rules! tested_by { - ($ident:ident; force) => {{ - { - // sic! use call-site crate - crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst); - } - }}; ($ident:ident) => {{ #[cfg(test)] { @@ -49,10 +43,7 @@ macro_rules! tested_by { macro_rules! covers { // sic! use call-site crate ($ident:ident) => { - $crate::covers!(crate::$ident) - }; - ($krate:ident :: $ident:ident) => { - let _checker = $crate::marks::MarkChecker::new(&$krate::marks::$ident); + let _checker = $crate::marks::MarkChecker::new(&crate::marks::$ident); }; } -- 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 --- .../src/handlers/add_from_impl_for_enum.rs | 8 +-- .../ra_assists/src/handlers/change_visibility.rs | 8 +-- crates/ra_assists/src/handlers/fill_match_arms.rs | 9 +-- .../src/handlers/inline_local_variable.rs | 16 ++--- .../ra_assists/src/handlers/introduce_variable.rs | 16 ++--- crates/ra_assists/src/lib.rs | 1 - crates/ra_assists/src/marks.rs | 13 ---- crates/ra_hir_def/src/body/lower.rs | 4 +- crates/ra_hir_def/src/body/scope.rs | 4 +- crates/ra_hir_def/src/find_path.rs | 57 +++++++-------- crates/ra_hir_def/src/lib.rs | 2 - crates/ra_hir_def/src/marks.rs | 17 ----- crates/ra_hir_def/src/nameres/collector.rs | 14 ++-- crates/ra_hir_def/src/nameres/path_resolution.rs | 8 +-- crates/ra_hir_def/src/nameres/raw.rs | 4 +- crates/ra_hir_def/src/nameres/tests.rs | 8 +-- crates/ra_hir_def/src/nameres/tests/globs.rs | 7 +- crates/ra_hir_def/src/nameres/tests/macros.rs | 9 ++- .../ra_hir_def/src/nameres/tests/mod_resolution.rs | 2 +- crates/ra_hir_def/src/path/lower/lower_use.rs | 4 +- crates/ra_hir_ty/src/infer/coerce.rs | 6 +- crates/ra_hir_ty/src/infer/pat.rs | 4 +- crates/ra_hir_ty/src/infer/unify.rs | 8 +-- crates/ra_hir_ty/src/lib.rs | 1 - crates/ra_hir_ty/src/lower.rs | 2 +- crates/ra_hir_ty/src/marks.rs | 12 ---- crates/ra_hir_ty/src/method_resolution.rs | 2 +- crates/ra_hir_ty/src/tests/coercion.rs | 6 +- crates/ra_hir_ty/src/tests/method_resolution.rs | 2 +- crates/ra_hir_ty/src/tests/patterns.rs | 4 +- crates/ra_hir_ty/src/tests/regression.rs | 15 ++-- crates/ra_hir_ty/src/tests/traits.rs | 8 +-- 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 ++-- crates/test_utils/src/lib.rs | 2 - crates/test_utils/src/marks.rs | 81 ---------------------- 42 files changed, 152 insertions(+), 298 deletions(-) delete mode 100644 crates/ra_assists/src/marks.rs delete mode 100644 crates/ra_hir_def/src/marks.rs delete mode 100644 crates/ra_hir_ty/src/marks.rs delete mode 100644 crates/ra_ide/src/marks.rs delete mode 100644 crates/test_utils/src/marks.rs (limited to 'crates') diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs index eb57b7231..5f6c8b19a 100644 --- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs +++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs @@ -1,6 +1,6 @@ use ra_ide_db::RootDatabase; use ra_syntax::ast::{self, AstNode, NameOwner}; -use test_utils::tested_by; +use test_utils::mark; use crate::{utils::FamousDefs, AssistContext, AssistId, Assists}; @@ -39,7 +39,7 @@ pub(crate) fn add_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) -> }; if existing_from_impl(&ctx.sema, &variant).is_some() { - tested_by!(test_add_from_impl_already_exists); + mark::hit!(test_add_from_impl_already_exists); return None; } @@ -90,7 +90,7 @@ fn existing_from_impl( #[cfg(test)] mod tests { - use test_utils::covers; + use test_utils::mark; use crate::tests::{check_assist, check_assist_not_applicable}; @@ -149,7 +149,7 @@ impl From for A { #[test] fn test_add_from_impl_already_exists() { - covers!(test_add_from_impl_already_exists); + mark::check!(test_add_from_impl_already_exists); check_not_applicable( r#" enum A { <|>One(u32), } diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index 40cf4b422..71d55e0c3 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs @@ -9,7 +9,7 @@ use ra_syntax::{ }; use hir::{db::HirDatabase, HasSource, HasVisibility, PathResolution}; -use test_utils::tested_by; +use test_utils::mark; use crate::{AssistContext, AssistId, Assists}; use ra_db::FileId; @@ -55,7 +55,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { } else if let Some(field_name) = ctx.find_node_at_offset::() { let field = field_name.syntax().ancestors().find_map(ast::RecordFieldDef::cast)?; if field.name()? != field_name { - tested_by!(change_visibility_field_false_positive); + mark::hit!(change_visibility_field_false_positive); return None; } if field.visibility().is_some() { @@ -255,7 +255,7 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { #[cfg(test)] mod tests { - use test_utils::covers; + use test_utils::mark; use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; @@ -288,7 +288,7 @@ mod tests { #[test] fn change_visibility_field_false_positive() { - covers!(change_visibility_field_false_positive); + mark::check!(change_visibility_field_false_positive); check_assist_not_applicable( change_visibility, r"struct S { field: [(); { let <|>x = ();}] }", diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index b57ff75ae..bbdcdc626 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -4,7 +4,7 @@ use hir::{Adt, HasSource, ModuleDef, Semantics}; use itertools::Itertools; use ra_ide_db::RootDatabase; use ra_syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat}; -use test_utils::tested_by; +use test_utils::mark; use crate::{utils::FamousDefs, AssistContext, AssistId, Assists}; @@ -58,7 +58,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< .collect::>(); if Some(enum_def) == FamousDefs(&ctx.sema, module.krate()).core_option_Option() { // Match `Some` variant first. - tested_by!(option_order); + mark::hit!(option_order); variants.reverse() } variants @@ -174,13 +174,14 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O #[cfg(test)] mod tests { + use test_utils::mark; + use crate::{ tests::{check_assist, check_assist_not_applicable, check_assist_target}, utils::FamousDefs, }; use super::fill_match_arms; - use test_utils::covers; #[test] fn all_match_arms_provided() { @@ -750,7 +751,7 @@ mod tests { #[test] fn option_order() { - covers!(option_order); + mark::check!(option_order); let before = r#" fn foo(opt: Option) { match opt<|> { diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index 5b26814d3..46d675a4e 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs @@ -3,7 +3,7 @@ use ra_syntax::{ ast::{self, AstNode, AstToken}, TextRange, }; -use test_utils::tested_by; +use test_utils::mark; use crate::{ assist_context::{AssistContext, Assists}, @@ -33,11 +33,11 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O _ => return None, }; if bind_pat.mut_token().is_some() { - tested_by!(test_not_inline_mut_variable); + mark::hit!(test_not_inline_mut_variable); return None; } if !bind_pat.syntax().text_range().contains_inclusive(ctx.offset()) { - tested_by!(not_applicable_outside_of_bind_pat); + mark::hit!(not_applicable_outside_of_bind_pat); return None; } let initializer_expr = let_stmt.initializer()?; @@ -46,7 +46,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O let def = Definition::Local(def); let refs = def.find_usages(ctx.db, None); if refs.is_empty() { - tested_by!(test_not_applicable_if_variable_unused); + mark::hit!(test_not_applicable_if_variable_unused); return None; }; @@ -122,7 +122,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O #[cfg(test)] mod tests { - use test_utils::covers; + use test_utils::mark; use crate::tests::{check_assist, check_assist_not_applicable}; @@ -330,7 +330,7 @@ fn foo() { #[test] fn test_not_inline_mut_variable() { - covers!(test_not_inline_mut_variable); + mark::check!(test_not_inline_mut_variable); check_assist_not_applicable( inline_local_variable, r" @@ -663,7 +663,7 @@ fn foo() { #[test] fn test_not_applicable_if_variable_unused() { - covers!(test_not_applicable_if_variable_unused); + mark::check!(test_not_applicable_if_variable_unused); check_assist_not_applicable( inline_local_variable, r" @@ -676,7 +676,7 @@ fn foo() { #[test] fn not_applicable_outside_of_bind_pat() { - covers!(not_applicable_outside_of_bind_pat); + mark::check!(not_applicable_outside_of_bind_pat); check_assist_not_applicable( inline_local_variable, r" diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs index fdf3ada0d..56c610fed 100644 --- a/crates/ra_assists/src/handlers/introduce_variable.rs +++ b/crates/ra_assists/src/handlers/introduce_variable.rs @@ -7,7 +7,7 @@ use ra_syntax::{ SyntaxNode, TextSize, }; use stdx::format_to; -use test_utils::tested_by; +use test_utils::mark; use crate::{AssistContext, AssistId, Assists}; @@ -33,7 +33,7 @@ pub(crate) fn introduce_variable(acc: &mut Assists, ctx: &AssistContext) -> Opti } let node = ctx.covering_element(); if node.kind() == COMMENT { - tested_by!(introduce_var_in_comment_is_not_applicable); + mark::hit!(introduce_var_in_comment_is_not_applicable); return None; } let expr = node.ancestors().find_map(valid_target_expr)?; @@ -61,7 +61,7 @@ pub(crate) fn introduce_variable(acc: &mut Assists, ctx: &AssistContext) -> Opti false }; if is_full_stmt { - tested_by!(test_introduce_var_expr_stmt); + mark::hit!(test_introduce_var_expr_stmt); if full_stmt.unwrap().semicolon_token().is_none() { buf.push_str(";"); } @@ -113,7 +113,7 @@ fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> { expr.syntax().ancestors().find_map(|node| { if let Some(expr) = node.parent().and_then(ast::BlockExpr::cast).and_then(|it| it.expr()) { if expr.syntax() == &node { - tested_by!(test_introduce_var_last_expr); + mark::hit!(test_introduce_var_last_expr); return Some((node, false)); } } @@ -134,7 +134,7 @@ fn anchor_stmt(expr: ast::Expr) -> Option<(SyntaxNode, bool)> { #[cfg(test)] mod tests { - use test_utils::covers; + use test_utils::mark; use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; @@ -158,13 +158,13 @@ fn foo() { #[test] fn introduce_var_in_comment_is_not_applicable() { - covers!(introduce_var_in_comment_is_not_applicable); + mark::check!(introduce_var_in_comment_is_not_applicable); check_assist_not_applicable(introduce_variable, "fn main() { 1 + /* <|>comment<|> */ 1; }"); } #[test] fn test_introduce_var_expr_stmt() { - covers!(test_introduce_var_expr_stmt); + mark::check!(test_introduce_var_expr_stmt); check_assist( introduce_variable, " @@ -209,7 +209,7 @@ fn foo() { #[test] fn test_introduce_var_last_expr() { - covers!(test_introduce_var_last_expr); + mark::check!(test_introduce_var_last_expr); check_assist( introduce_variable, " diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 339f24100..a4a497c73 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -12,7 +12,6 @@ macro_rules! eprintln { mod assist_config; mod assist_context; -mod marks; #[cfg(test)] mod tests; pub mod utils; diff --git a/crates/ra_assists/src/marks.rs b/crates/ra_assists/src/marks.rs deleted file mode 100644 index 525ec4abc..000000000 --- a/crates/ra_assists/src/marks.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! See test_utils/src/marks.rs - -test_utils::marks![ - option_order - introduce_var_in_comment_is_not_applicable - test_introduce_var_expr_stmt - test_introduce_var_last_expr - not_applicable_outside_of_bind_pat - test_not_inline_mut_variable - test_not_applicable_if_variable_unused - change_visibility_field_false_positive - test_add_from_impl_already_exists -]; diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c69e0efea..e08d62dd6 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -15,7 +15,7 @@ use ra_syntax::{ }, AstNode, AstPtr, }; -use test_utils::tested_by; +use test_utils::mark; use crate::{ adt::StructKind, @@ -226,7 +226,7 @@ impl ExprCollector<'_> { None => self.collect_expr_opt(condition.expr()), // if let -- desugar to match Some(pat) => { - tested_by!(infer_resolve_while_let); + mark::hit!(infer_resolve_while_let); let pat = self.collect_pat(pat); let match_expr = self.collect_expr_opt(condition.expr()); let placeholder_pat = self.missing_pat(); diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 86f953c80..09e92b74e 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs @@ -174,7 +174,7 @@ mod tests { use hir_expand::{name::AsName, InFile}; use ra_db::{fixture::WithFixture, FileId, SourceDatabase}; use ra_syntax::{algo::find_node_at_offset, ast, AstNode}; - use test_utils::{assert_eq_text, covers, extract_offset}; + use test_utils::{assert_eq_text, extract_offset, mark}; use crate::{db::DefDatabase, test_db::TestDB, FunctionId, ModuleDefId}; @@ -388,7 +388,7 @@ mod tests { #[test] fn while_let_desugaring() { - covers!(infer_resolve_while_let); + mark::check!(infer_resolve_while_let); do_check_local_name( r#" fn test() { diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs index 2eb12ec8f..68d3cde08 100644 --- a/crates/ra_hir_def/src/find_path.rs +++ b/crates/ra_hir_def/src/find_path.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use hir_expand::name::{known, AsName, Name}; use ra_prof::profile; -use test_utils::tested_by; +use test_utils::mark; use crate::{ db::DefDatabase, @@ -164,17 +164,19 @@ fn find_path_inner( fn select_best_path(old_path: ModPath, new_path: ModPath, prefer_no_std: bool) -> ModPath { if old_path.starts_with_std() && new_path.can_start_with_std() { - tested_by!(prefer_std_paths); if prefer_no_std { + mark::hit!(prefer_no_std_paths); new_path } else { + mark::hit!(prefer_std_paths); old_path } } else if new_path.starts_with_std() && old_path.can_start_with_std() { - tested_by!(prefer_std_paths); if prefer_no_std { + mark::hit!(prefer_no_std_paths); old_path } else { + mark::hit!(prefer_std_paths); new_path } } else if new_path.len() < old_path.len() { @@ -251,12 +253,14 @@ pub(crate) fn importable_locations_of_query( #[cfg(test)] mod tests { - use super::*; - use crate::test_db::TestDB; use hir_expand::hygiene::Hygiene; use ra_db::fixture::WithFixture; use ra_syntax::ast::AstNode; - use test_utils::covers; + use test_utils::mark; + + use crate::test_db::TestDB; + + use super::*; /// `code` needs to contain a cursor marker; checks that `find_path` for the /// item the `path` refers to returns that same path when called from the @@ -511,7 +515,7 @@ mod tests { #[test] fn prefer_std_paths_over_alloc() { - covers!(prefer_std_paths); + mark::check!(prefer_std_paths); let code = r#" //- /main.rs crate:main deps:alloc,std <|> @@ -530,51 +534,50 @@ mod tests { } #[test] - fn prefer_alloc_paths_over_std() { - covers!(prefer_std_paths); + fn prefer_core_paths_over_std() { + mark::check!(prefer_no_std_paths); let code = r#" - //- /main.rs crate:main deps:alloc,std + //- /main.rs crate:main deps:core,std #![no_std] <|> - //- /std.rs crate:std deps:alloc + //- /std.rs crate:std deps:core - pub mod sync { - pub use alloc::sync::Arc; + pub mod fmt { + pub use core::fmt::Error; } - //- /zzz.rs crate:alloc + //- /zzz.rs crate:core - pub mod sync { - pub struct Arc; + pub mod fmt { + pub struct Error; } "#; - check_found_path(code, "alloc::sync::Arc"); + check_found_path(code, "core::fmt::Error"); } #[test] - fn prefer_core_paths_over_std() { - covers!(prefer_std_paths); + fn prefer_alloc_paths_over_std() { let code = r#" - //- /main.rs crate:main deps:core,std + //- /main.rs crate:main deps:alloc,std #![no_std] <|> - //- /std.rs crate:std deps:core + //- /std.rs crate:std deps:alloc - pub mod fmt { - pub use core::fmt::Error; + pub mod sync { + pub use alloc::sync::Arc; } - //- /zzz.rs crate:core + //- /zzz.rs crate:alloc - pub mod fmt { - pub struct Error; + pub mod sync { + pub struct Arc; } "#; - check_found_path(code, "core::fmt::Error"); + check_found_path(code, "alloc::sync::Arc"); } #[test] diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 518772e8a..5325a2760 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs @@ -46,8 +46,6 @@ pub mod find_path; #[cfg(test)] mod test_db; -#[cfg(test)] -mod marks; use std::hash::Hash; diff --git a/crates/ra_hir_def/src/marks.rs b/crates/ra_hir_def/src/marks.rs deleted file mode 100644 index daa49d5f1..000000000 --- a/crates/ra_hir_def/src/marks.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! See test_utils/src/marks.rs - -test_utils::marks!( - bogus_paths - name_res_works_for_broken_modules - can_import_enum_variant - glob_enum - glob_enum_group - glob_across_crates - std_prelude - macro_rules_from_other_crates_are_visible_with_macro_use - prelude_is_macro_use - macro_dollar_crate_self - macro_dollar_crate_other - infer_resolve_while_let - prefer_std_paths -); diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index db994122a..353a31ad4 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -14,7 +14,7 @@ use ra_cfg::CfgOptions; use ra_db::{CrateId, FileId, ProcMacroId}; use ra_syntax::ast; use rustc_hash::FxHashMap; -use test_utils::tested_by; +use test_utils::mark; use crate::{ attr::Attrs, @@ -302,7 +302,7 @@ impl DefCollector<'_> { ); if let Some(ModuleDefId::ModuleId(m)) = res.take_types() { - tested_by!(macro_rules_from_other_crates_are_visible_with_macro_use); + mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use); self.import_all_macros_exported(current_module_id, m.krate); } } @@ -412,10 +412,10 @@ impl DefCollector<'_> { match def.take_types() { Some(ModuleDefId::ModuleId(m)) => { if import.is_prelude { - tested_by!(std_prelude); + mark::hit!(std_prelude); self.def_map.prelude = Some(m); } else if m.krate != self.def_map.krate { - tested_by!(glob_across_crates); + mark::hit!(glob_across_crates); // glob import from other crate => we can just import everything once let item_map = self.db.crate_def_map(m.krate); let scope = &item_map[m.local_id].scope; @@ -461,7 +461,7 @@ impl DefCollector<'_> { } } Some(ModuleDefId::AdtId(AdtId::EnumId(e))) => { - tested_by!(glob_enum); + mark::hit!(glob_enum); // glob import from enum => just import all the variants // XXX: urgh, so this works by accident! Here, we look at @@ -510,7 +510,7 @@ impl DefCollector<'_> { self.update(module_id, &[(name, def)], vis); } - None => tested_by!(bogus_paths), + None => mark::hit!(bogus_paths), } } } @@ -683,7 +683,7 @@ impl ModCollector<'_, '_> { // Prelude module is always considered to be `#[macro_use]`. if let Some(prelude_module) = self.def_collector.def_map.prelude { if prelude_module.krate != self.def_collector.def_map.krate { - tested_by!(prelude_is_macro_use); + mark::hit!(prelude_is_macro_use); self.def_collector.import_all_macros_exported(self.module_id, prelude_module.krate); } } diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs index 35a0a0c98..19692e70c 100644 --- a/crates/ra_hir_def/src/nameres/path_resolution.rs +++ b/crates/ra_hir_def/src/nameres/path_resolution.rs @@ -14,7 +14,7 @@ use std::iter::successors; use hir_expand::name::Name; use ra_db::Edition; -use test_utils::tested_by; +use test_utils::mark; use crate::{ db::DefDatabase, @@ -108,7 +108,7 @@ impl CrateDefMap { let mut curr_per_ns: PerNs = match path.kind { PathKind::DollarCrate(krate) => { if krate == self.krate { - tested_by!(macro_dollar_crate_self); + mark::hit!(macro_dollar_crate_self); PerNs::types( ModuleId { krate: self.krate, local_id: self.root }.into(), Visibility::Public, @@ -116,7 +116,7 @@ impl CrateDefMap { } else { let def_map = db.crate_def_map(krate); let module = ModuleId { krate, local_id: def_map.root }; - tested_by!(macro_dollar_crate_other); + mark::hit!(macro_dollar_crate_other); PerNs::types(module.into(), Visibility::Public) } } @@ -221,7 +221,7 @@ impl CrateDefMap { } ModuleDefId::AdtId(AdtId::EnumId(e)) => { // enum variant - tested_by!(can_import_enum_variant); + mark::hit!(can_import_enum_variant); let enum_data = db.enum_data(e); match enum_data.variant(&segment) { Some(local_id) => { diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index f2716a295..4e628b14d 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -18,7 +18,7 @@ use ra_syntax::{ ast::{self, AttrsOwner, NameOwner, VisibilityOwner}, AstNode, }; -use test_utils::tested_by; +use test_utils::mark; use crate::{ attr::Attrs, @@ -346,7 +346,7 @@ impl RawItemsCollector { self.push_item(current_module, attrs, RawItemKind::Module(item)); return; } - tested_by!(name_res_works_for_broken_modules); + mark::hit!(name_res_works_for_broken_modules); } fn add_use_item(&mut self, current_module: Option>, use_item: ast::UseItem) { diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 1b66c1aac..05cd0297d 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use insta::assert_snapshot; use ra_db::{fixture::WithFixture, SourceDatabase}; -use test_utils::covers; +use test_utils::mark; use crate::{db::DefDatabase, nameres::*, test_db::TestDB}; @@ -132,7 +132,7 @@ fn crate_def_map_fn_mod_same_name() { #[test] fn bogus_paths() { - covers!(bogus_paths); + mark::check!(bogus_paths); let map = def_map( " //- /lib.rs @@ -247,7 +247,7 @@ fn re_exports() { #[test] fn std_prelude() { - covers!(std_prelude); + mark::check!(std_prelude); let map = def_map( " //- /main.rs crate:main deps:test_crate @@ -271,7 +271,7 @@ fn std_prelude() { #[test] fn can_import_enum_variant() { - covers!(can_import_enum_variant); + mark::check!(can_import_enum_variant); let map = def_map( " //- /lib.rs diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs index ee8df3a26..2b12c0daa 100644 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ b/crates/ra_hir_def/src/nameres/tests/globs.rs @@ -152,7 +152,7 @@ fn glob_privacy_2() { #[test] fn glob_across_crates() { - covers!(glob_across_crates); + mark::check!(glob_across_crates); let map = def_map( r" //- /main.rs crate:main deps:test_crate @@ -171,7 +171,6 @@ fn glob_across_crates() { #[test] fn glob_privacy_across_crates() { - covers!(glob_across_crates); let map = def_map( r" //- /main.rs crate:main deps:test_crate @@ -191,7 +190,7 @@ fn glob_privacy_across_crates() { #[test] fn glob_enum() { - covers!(glob_enum); + mark::check!(glob_enum); let map = def_map( " //- /lib.rs @@ -212,7 +211,7 @@ fn glob_enum() { #[test] fn glob_enum_group() { - covers!(glob_enum_group); + mark::check!(glob_enum_group); let map = def_map( r" //- /lib.rs diff --git a/crates/ra_hir_def/src/nameres/tests/macros.rs b/crates/ra_hir_def/src/nameres/tests/macros.rs index 40289e3ca..84480d9f6 100644 --- a/crates/ra_hir_def/src/nameres/tests/macros.rs +++ b/crates/ra_hir_def/src/nameres/tests/macros.rs @@ -212,7 +212,7 @@ fn unexpanded_macro_should_expand_by_fixedpoint_loop() { #[test] fn macro_rules_from_other_crates_are_visible_with_macro_use() { - covers!(macro_rules_from_other_crates_are_visible_with_macro_use); + mark::check!(macro_rules_from_other_crates_are_visible_with_macro_use); let map = def_map( " //- /main.rs crate:main deps:foo @@ -262,7 +262,7 @@ fn macro_rules_from_other_crates_are_visible_with_macro_use() { #[test] fn prelude_is_macro_use() { - covers!(prelude_is_macro_use); + mark::check!(prelude_is_macro_use); let map = def_map( " //- /main.rs crate:main deps:foo @@ -544,8 +544,7 @@ fn path_qualified_macros() { #[test] fn macro_dollar_crate_is_correct_in_item() { - covers!(macro_dollar_crate_self); - covers!(macro_dollar_crate_other); + mark::check!(macro_dollar_crate_self); let map = def_map( " //- /main.rs crate:main deps:foo @@ -603,7 +602,7 @@ fn macro_dollar_crate_is_correct_in_item() { #[test] fn macro_dollar_crate_is_correct_in_indirect_deps() { - covers!(macro_dollar_crate_other); + mark::check!(macro_dollar_crate_other); // From std let map = def_map( r#" 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 37fcdfb8c..b43b294ca 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs @@ -2,7 +2,7 @@ use super::*; #[test] fn name_res_works_for_broken_modules() { - covers!(name_res_works_for_broken_modules); + mark::check!(name_res_works_for_broken_modules); let map = def_map( r" //- /lib.rs diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index 5b6854b0f..7cc655487 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs @@ -6,7 +6,7 @@ use std::iter; use either::Either; use hir_expand::{hygiene::Hygiene, name::AsName}; use ra_syntax::ast::{self, NameOwner}; -use test_utils::tested_by; +use test_utils::mark; use crate::path::{ImportAlias, ModPath, PathKind}; @@ -54,7 +54,7 @@ pub(crate) fn lower_use_tree( // FIXME: report errors somewhere // We get here if we do } else if is_glob { - tested_by!(glob_enum_group); + mark::hit!(glob_enum_group); if let Some(prefix) = prefix { cb(prefix, &tree, is_glob, None) } diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index 173ec59ed..2ee9adb16 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs @@ -5,7 +5,7 @@ //! See: https://doc.rust-lang.org/nomicon/coercions.html use hir_def::{lang_item::LangItemTarget, type_ref::Mutability}; -use test_utils::tested_by; +use test_utils::mark; use crate::{autoderef, traits::Solution, Obligation, Substs, TraitRef, Ty, TypeCtor}; @@ -34,7 +34,7 @@ impl<'a> InferenceContext<'a> { ty1.clone() } else { if let (ty_app!(TypeCtor::FnDef(_)), ty_app!(TypeCtor::FnDef(_))) = (ty1, ty2) { - tested_by!(coerce_fn_reification); + mark::hit!(coerce_fn_reification); // Special case: two function types. Try to coerce both to // pointers to have a chance at getting a match. See // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 @@ -44,7 +44,7 @@ impl<'a> InferenceContext<'a> { let ptr_ty2 = Ty::fn_ptr(sig2); self.coerce_merge_branch(&ptr_ty1, &ptr_ty2) } else { - tested_by!(coerce_merge_fail_fallback); + mark::hit!(coerce_merge_fail_fallback); // For incompatible types, we use the latter one as result // to be better recovery for `if` without `else`. ty2.clone() diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index 54ec870df..4006f595d 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -10,7 +10,7 @@ use hir_def::{ FieldId, }; use hir_expand::name::Name; -use test_utils::tested_by; +use test_utils::mark; use super::{BindingMode, Expectation, InferenceContext}; use crate::{utils::variant_data, Substs, Ty, TypeCtor}; @@ -111,7 +111,7 @@ impl<'a> InferenceContext<'a> { } } } else if let Pat::Ref { .. } = &body[pat] { - tested_by!(match_ergonomics_ref); + mark::hit!(match_ergonomics_ref); // When you encounter a `&pat` pattern, reset to Move. // This is so that `w` is by value: `let (_, &w) = &(1, &2);` default_bm = BindingMode::Move; diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs index ab0bc8b70..269495ca0 100644 --- a/crates/ra_hir_ty/src/infer/unify.rs +++ b/crates/ra_hir_ty/src/infer/unify.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; -use test_utils::tested_by; +use test_utils::mark; use super::{InferenceContext, Obligation}; use crate::{ @@ -313,7 +313,7 @@ impl InferenceTable { // more than once for i in 0..3 { if i > 0 { - tested_by!(type_var_resolves_to_int_var); + mark::hit!(type_var_resolves_to_int_var); } match &*ty { Ty::Infer(tv) => { @@ -342,7 +342,7 @@ impl InferenceTable { Ty::Infer(tv) => { let inner = tv.to_inner(); if tv_stack.contains(&inner) { - tested_by!(type_var_cycles_resolve_as_possible); + mark::hit!(type_var_cycles_resolve_as_possible); // recursive type return tv.fallback_value(); } @@ -369,7 +369,7 @@ impl InferenceTable { Ty::Infer(tv) => { let inner = tv.to_inner(); if tv_stack.contains(&inner) { - tested_by!(type_var_cycles_resolve_completely); + mark::hit!(type_var_cycles_resolve_completely); // recursive type return tv.fallback_value(); } diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index daea02f88..c87ee06ce 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -42,7 +42,6 @@ pub mod expr; mod tests; #[cfg(test)] mod test_db; -mod marks; mod _match; use std::ops::Deref; diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 9ad6dbe07..35ac86a46 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -812,7 +812,7 @@ impl TraitEnvironment { // add `Self: Trait` to the environment in trait // function default implementations (and hypothetical code // inside consts or type aliases) - test_utils::tested_by!(trait_self_implements_self); + test_utils::mark::hit!(trait_self_implements_self); let substs = Substs::type_params(db, trait_id); let trait_ref = TraitRef { trait_: trait_id, substs }; let pred = GenericPredicate::Implemented(trait_ref); diff --git a/crates/ra_hir_ty/src/marks.rs b/crates/ra_hir_ty/src/marks.rs deleted file mode 100644 index a39740143..000000000 --- a/crates/ra_hir_ty/src/marks.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! See test_utils/src/marks.rs - -test_utils::marks!( - type_var_cycles_resolve_completely - type_var_cycles_resolve_as_possible - type_var_resolves_to_int_var - impl_self_type_match_without_receiver - match_ergonomics_ref - coerce_merge_fail_fallback - coerce_fn_reification - trait_self_implements_self -); diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 0851e16a8..e19628fdf 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs @@ -469,7 +469,7 @@ fn iterate_inherent_methods( // already happens in `is_valid_candidate` above; if not, we // check it here if receiver_ty.is_none() && inherent_impl_substs(db, impl_def, self_ty).is_none() { - test_utils::tested_by!(impl_self_type_match_without_receiver); + test_utils::mark::hit!(impl_self_type_match_without_receiver); continue; } if let Some(result) = callback(&self_ty.value, item) { diff --git a/crates/ra_hir_ty/src/tests/coercion.rs b/crates/ra_hir_ty/src/tests/coercion.rs index 6dc4b2cd1..2cc4f4bf9 100644 --- a/crates/ra_hir_ty/src/tests/coercion.rs +++ b/crates/ra_hir_ty/src/tests/coercion.rs @@ -1,6 +1,6 @@ use super::infer_with_mismatches; use insta::assert_snapshot; -use test_utils::covers; +use test_utils::mark; // Infer with some common definitions and impls. fn infer(source: &str) -> String { @@ -339,7 +339,7 @@ fn test(i: i32) { #[test] fn coerce_merge_one_by_one1() { - covers!(coerce_merge_fail_fallback); + mark::check!(coerce_merge_fail_fallback); assert_snapshot!( infer(r#" @@ -547,7 +547,7 @@ fn test() { #[test] fn coerce_fn_items_in_match_arms() { - covers!(coerce_fn_reification); + mark::check!(coerce_fn_reification); assert_snapshot!( infer_with_mismatches(r#" fn foo1(x: u32) -> isize { 1 } diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs index 9c2c9e1d2..558a70022 100644 --- a/crates/ra_hir_ty/src/tests/method_resolution.rs +++ b/crates/ra_hir_ty/src/tests/method_resolution.rs @@ -984,7 +984,7 @@ fn test() { S2.into()<|>; } #[test] fn method_resolution_overloaded_method() { - test_utils::covers!(impl_self_type_match_without_receiver); + test_utils::mark::check!(impl_self_type_match_without_receiver); let t = type_at( r#" //- main.rs diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index d83ff5e0e..0c5f972a2 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs @@ -1,5 +1,5 @@ use insta::assert_snapshot; -use test_utils::covers; +use test_utils::mark; use super::{infer, infer_with_mismatches}; @@ -197,7 +197,7 @@ fn test() { #[test] fn infer_pattern_match_ergonomics_ref() { - covers!(match_ergonomics_ref); + mark::check!(match_ergonomics_ref); assert_snapshot!( infer(r#" fn test() { diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index c2168222e..1f004bd63 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs @@ -1,9 +1,10 @@ use insta::assert_snapshot; -use test_utils::covers; +use ra_db::fixture::WithFixture; +use test_utils::mark; -use super::infer; use crate::test_db::TestDB; -use ra_db::fixture::WithFixture; + +use super::infer; #[test] fn bug_484() { @@ -89,8 +90,8 @@ fn quux() { #[test] fn recursive_vars() { - covers!(type_var_cycles_resolve_completely); - covers!(type_var_cycles_resolve_as_possible); + mark::check!(type_var_cycles_resolve_completely); + mark::check!(type_var_cycles_resolve_as_possible); assert_snapshot!( infer(r#" fn test() { @@ -112,8 +113,6 @@ fn test() { #[test] fn recursive_vars_2() { - covers!(type_var_cycles_resolve_completely); - covers!(type_var_cycles_resolve_as_possible); assert_snapshot!( infer(r#" fn test() { @@ -170,7 +169,7 @@ fn write() { #[test] fn infer_std_crash_2() { - covers!(type_var_resolves_to_int_var); + mark::check!(type_var_resolves_to_int_var); // caused "equating two type variables, ...", taken from std assert_snapshot!( infer(r#" diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index c49aacf98..34f4b9039 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs @@ -1,10 +1,11 @@ use insta::assert_snapshot; - use ra_db::fixture::WithFixture; +use test_utils::mark; -use super::{infer, infer_with_mismatches, type_at, type_at_pos}; use crate::test_db::TestDB; +use super::{infer, infer_with_mismatches, type_at, type_at_pos}; + #[test] fn infer_await() { let (db, pos) = TestDB::with_position( @@ -301,7 +302,7 @@ fn test() { #[test] fn trait_default_method_self_bound_implements_trait() { - test_utils::covers!(trait_self_implements_self); + mark::check!(trait_self_implements_self); assert_snapshot!( infer(r#" trait Trait { @@ -324,7 +325,6 @@ trait Trait { #[test] fn trait_default_method_self_bound_implements_super_trait() { - test_utils::covers!(trait_self_implements_self); assert_snapshot!( infer(r#" trait SuperTrait { 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 { diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 4e05d464f..be2cfbaa2 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -6,8 +6,6 @@ //! * Extracting markup (mainly, `<|>` markers) out of fixture strings. //! * marks (see the eponymous module). -#[macro_use] -pub mod marks; #[macro_use] pub mod mark; diff --git a/crates/test_utils/src/marks.rs b/crates/test_utils/src/marks.rs deleted file mode 100644 index f20fb978e..000000000 --- a/crates/test_utils/src/marks.rs +++ /dev/null @@ -1,81 +0,0 @@ -//! This module implements manually tracked test coverage, which is useful for -//! quickly finding a test responsible for testing a particular bit of code. -//! -//! See -//! for details, but the TL;DR is that you write your test as -//! -//! ``` -//! #[test] -//! fn test_foo() { -//! covers!(test_foo); -//! } -//! ``` -//! -//! and in the code under test you write -//! -//! ``` -//! # use test_utils::tested_by; -//! # fn some_condition() -> bool { true } -//! fn foo() { -//! if some_condition() { -//! tested_by!(test_foo); -//! } -//! } -//! ``` -//! -//! This module then checks that executing the test indeed covers the specified -//! function. This is useful if you come back to the `foo` function ten years -//! later and wonder where the test are: now you can grep for `test_foo`. -use std::sync::atomic::{AtomicUsize, Ordering}; - -#[macro_export] -macro_rules! tested_by { - ($ident:ident) => {{ - #[cfg(test)] - { - // sic! use call-site crate - crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst); - } - }}; -} - -#[macro_export] -macro_rules! covers { - // sic! use call-site crate - ($ident:ident) => { - let _checker = $crate::marks::MarkChecker::new(&crate::marks::$ident); - }; -} - -#[macro_export] -macro_rules! marks { - ($($ident:ident)*) => { - $( - #[allow(bad_style)] - pub static $ident: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); - )* - }; -} - -pub struct MarkChecker { - mark: &'static AtomicUsize, - value_on_entry: usize, -} - -impl MarkChecker { - pub fn new(mark: &'static AtomicUsize) -> MarkChecker { - let value_on_entry = mark.load(Ordering::SeqCst); - MarkChecker { mark, value_on_entry } - } -} - -impl Drop for MarkChecker { - fn drop(&mut self) { - if std::thread::panicking() { - return; - } - let value_on_exit = self.mark.load(Ordering::SeqCst); - assert!(value_on_exit > self.value_on_entry, "mark was not hit") - } -} -- cgit v1.2.3