Use upstream cov-mark

This commit is contained in:
Laurențiu Nicola 2021-03-08 22:19:44 +02:00
parent c5189a22cc
commit fc9eed4836
101 changed files with 354 additions and 514 deletions

View file

@ -11,7 +11,6 @@ use ide_db::{
use itertools::Itertools;
use stdx::format_to;
use syntax::{ast, match_ast, AstNode, SyntaxKind::*, SyntaxToken, TokenAtOffset, T};
use test_utils::mark;
use crate::{
display::{macro_label, ShortLabel, TryToNav},
@ -193,8 +192,8 @@ fn runnable_action(
ModuleDef::Function(func) => {
let src = func.source(sema.db)?;
if src.file_id != file_id.into() {
mark::hit!(hover_macro_generated_struct_fn_doc_comment);
mark::hit!(hover_macro_generated_struct_fn_doc_attr);
cov_mark::hit!(hover_macro_generated_struct_fn_doc_comment);
cov_mark::hit!(hover_macro_generated_struct_fn_doc_attr);
return None;
}
@ -2101,7 +2100,7 @@ pub fn fo$0o() {}
#[test]
fn test_hover_macro_generated_struct_fn_doc_comment() {
mark::check!(hover_macro_generated_struct_fn_doc_comment);
cov_mark::check!(hover_macro_generated_struct_fn_doc_comment);
check(
r#"
@ -2139,7 +2138,7 @@ fn foo() { let bar = Bar; bar.fo$0o(); }
#[test]
fn test_hover_macro_generated_struct_fn_doc_attr() {
mark::check!(hover_macro_generated_struct_fn_doc_attr);
cov_mark::check!(hover_macro_generated_struct_fn_doc_attr);
check(
r#"

View file

@ -7,7 +7,7 @@ use syntax::{
SyntaxKind::{self, USE_TREE, WHITESPACE},
SyntaxNode, SyntaxToken, TextRange, TextSize, T,
};
use test_utils::mark;
use text_edit::{TextEdit, TextEditBuilder};
// Feature: Join Lines
@ -60,7 +60,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
let mut string_open_quote = false;
if let Some(string) = ast::String::cast(token.clone()) {
if let Some(range) = string.open_quote_text_range() {
mark::hit!(join_string_literal);
cov_mark::hit!(join_string_literal);
string_open_quote = range.end() == offset;
}
}
@ -206,7 +206,7 @@ fn compute_ws(left: SyntaxKind, right: SyntaxKind) -> &'static str {
#[cfg(test)]
mod tests {
use syntax::SourceFile;
use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range, mark};
use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range};
use super::*;
@ -786,7 +786,7 @@ fn foo() {
#[test]
fn join_string_literal() {
mark::check!(join_string_literal);
cov_mark::check!(join_string_literal);
check_join_lines(
r#"
fn main() {

View file

@ -2,7 +2,6 @@ use syntax::{
ast::{self, AstNode},
SourceFile, SyntaxKind, TextSize, T,
};
use test_utils::mark;
// Feature: Matching Brace
//
@ -28,7 +27,7 @@ pub(crate) fn matching_brace(file: &SourceFile, offset: TextSize) -> Option<Text
.next()?;
let parent = brace_token.parent();
if brace_token.kind() == T![|] && !ast::ParamList::can_cast(parent.kind()) {
mark::hit!(pipes_not_braces);
cov_mark::hit!(pipes_not_braces);
return None;
}
let matching_kind = BRACES[brace_idx ^ 1];
@ -63,7 +62,7 @@ mod tests {
do_check("fn main() { $0|x: i32| x * 2;}", "fn main() { |x: i32$0| x * 2;}");
{
mark::check!(pipes_not_braces);
cov_mark::check!(pipes_not_braces);
do_check(
"fn main() { match 92 { 1 | 2 |$0 3 => 92 } }",
"fn main() { match 92 { 1 | 2 |$0 3 => 92 } }",

View file

@ -5,7 +5,6 @@ use syntax::{
algo::find_node_at_offset,
ast::{self, AstNode},
};
use test_utils::mark;
use crate::NavigationTarget;
@ -33,7 +32,7 @@ pub(crate) fn parent_module(db: &RootDatabase, position: FilePosition) -> Vec<Na
.item_list()
.map_or(false, |it| it.syntax().text_range().contains_inclusive(position.offset))
{
mark::hit!(test_resolve_parent_module_on_module_decl);
cov_mark::hit!(test_resolve_parent_module_on_module_decl);
module = m.syntax().ancestors().skip(1).find_map(ast::Module::cast);
}
}
@ -64,7 +63,6 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
#[cfg(test)]
mod tests {
use ide_db::base_db::FileRange;
use test_utils::mark;
use crate::fixture;
@ -92,7 +90,7 @@ $0// empty
#[test]
fn test_resolve_parent_module_on_module_decl() {
mark::check!(test_resolve_parent_module_on_module_decl);
cov_mark::check!(test_resolve_parent_module_on_module_decl);
check(
r#"
//- /lib.rs

View file

@ -14,7 +14,7 @@ use syntax::{
ast::{self, NameOwner},
lex_single_syntax_kind, AstNode, SyntaxKind, SyntaxNode, T,
};
use test_utils::mark;
use text_edit::TextEdit;
use crate::{display::TryToNav, FilePosition, FileSystemEdit, RangeInfo, SourceChange, TextRange};
@ -226,34 +226,36 @@ fn rename_reference(
| (IdentifierKind::Ident, _)
if def_is_lbl_or_lt =>
{
mark::hit!(rename_not_a_lifetime_ident_ref);
cov_mark::hit!(rename_not_a_lifetime_ident_ref);
bail!("Invalid name `{}`: not a lifetime identifier", new_name)
}
(IdentifierKind::Lifetime, _) if def_is_lbl_or_lt => mark::hit!(rename_lifetime),
(IdentifierKind::Lifetime, _) if def_is_lbl_or_lt => cov_mark::hit!(rename_lifetime),
(IdentifierKind::Lifetime, _) => {
mark::hit!(rename_not_an_ident_ref);
cov_mark::hit!(rename_not_an_ident_ref);
bail!("Invalid name `{}`: not an identifier", new_name)
}
(IdentifierKind::ToSelf, Definition::Local(local)) if local.is_self(sema.db) => {
// no-op
mark::hit!(rename_self_to_self);
cov_mark::hit!(rename_self_to_self);
return Ok(SourceChange::default());
}
(ident_kind, Definition::Local(local)) if local.is_self(sema.db) => {
mark::hit!(rename_self_to_param);
cov_mark::hit!(rename_self_to_param);
return rename_self_to_param(sema, local, new_name, ident_kind);
}
(IdentifierKind::ToSelf, Definition::Local(local)) => {
mark::hit!(rename_to_self);
cov_mark::hit!(rename_to_self);
return rename_to_self(sema, local);
}
(IdentifierKind::ToSelf, _) => bail!("Invalid name `{}`: not an identifier", new_name),
(IdentifierKind::Ident, _) | (IdentifierKind::Underscore, _) => mark::hit!(rename_ident),
(IdentifierKind::Ident, _) | (IdentifierKind::Underscore, _) => {
cov_mark::hit!(rename_ident)
}
}
let usages = def.usages(sema).all();
if !usages.is_empty() && ident_kind == IdentifierKind::Underscore {
mark::hit!(rename_underscore_multiple);
cov_mark::hit!(rename_underscore_multiple);
bail!("Cannot rename reference to `_` as it is being referenced multiple times");
}
let mut source_change = SourceChange::default();
@ -444,7 +446,7 @@ fn source_edit_from_name_ref(
(Some(field_name), Some(init)) => {
if field_name == *name_ref {
if init.text() == new_name {
mark::hit!(test_rename_field_put_init_shorthand);
cov_mark::hit!(test_rename_field_put_init_shorthand);
// same names, we can use a shorthand here instead.
// we do not want to erase attributes hence this range start
let s = field_name.syntax().text_range().start();
@ -453,7 +455,7 @@ fn source_edit_from_name_ref(
}
} else if init == *name_ref {
if field_name.text() == new_name {
mark::hit!(test_rename_local_put_init_shorthand);
cov_mark::hit!(test_rename_local_put_init_shorthand);
// same names, we can use a shorthand here instead.
// we do not want to erase attributes hence this range start
let s = field_name.syntax().text_range().start();
@ -467,12 +469,12 @@ fn source_edit_from_name_ref(
// FIXME: instead of splitting the shorthand, recursively trigger a rename of the
// other name https://github.com/rust-analyzer/rust-analyzer/issues/6547
(None, Some(_)) if matches!(def, Definition::Field(_)) => {
mark::hit!(test_rename_field_in_field_shorthand);
cov_mark::hit!(test_rename_field_in_field_shorthand);
let s = name_ref.syntax().text_range().start();
Some((TextRange::empty(s), format!("{}: ", new_name)))
}
(None, Some(_)) if matches!(def, Definition::Local(_)) => {
mark::hit!(test_rename_local_in_field_shorthand);
cov_mark::hit!(test_rename_local_in_field_shorthand);
let s = name_ref.syntax().text_range().end();
Some((TextRange::empty(s), format!(": {}", new_name)))
}
@ -486,7 +488,7 @@ fn source_edit_from_name_ref(
(Some(field_name), Some(ast::Pat::IdentPat(pat))) if field_name == *name_ref => {
// field name is being renamed
if pat.name().map_or(false, |it| it.text() == new_name) {
mark::hit!(test_rename_field_put_init_shorthand_pat);
cov_mark::hit!(test_rename_field_put_init_shorthand_pat);
// same names, we can use a shorthand here instead/
// we do not want to erase attributes hence this range start
let s = field_name.syntax().text_range().start();
@ -538,7 +540,7 @@ fn source_edit_from_def(
mod tests {
use expect_test::{expect, Expect};
use stdx::trim_indent;
use test_utils::{assert_eq_text, mark};
use test_utils::assert_eq_text;
use text_edit::TextEdit;
use crate::{fixture, FileId};
@ -627,7 +629,7 @@ mod tests {
#[test]
fn test_rename_to_invalid_identifier_lifetime() {
mark::check!(rename_not_an_ident_ref);
cov_mark::check!(rename_not_an_ident_ref);
check(
"'foo",
r#"fn main() { let i$0 = 1; }"#,
@ -637,7 +639,7 @@ mod tests {
#[test]
fn test_rename_to_invalid_identifier_lifetime2() {
mark::check!(rename_not_a_lifetime_ident_ref);
cov_mark::check!(rename_not_a_lifetime_ident_ref);
check(
"foo",
r#"fn main<'a>(_: &'a$0 ()) {}"#,
@ -647,7 +649,7 @@ mod tests {
#[test]
fn test_rename_to_underscore_invalid() {
mark::check!(rename_underscore_multiple);
cov_mark::check!(rename_underscore_multiple);
check(
"_",
r#"fn main(foo$0: ()) {foo;}"#,
@ -666,7 +668,7 @@ mod tests {
#[test]
fn test_rename_for_local() {
mark::check!(rename_ident);
cov_mark::check!(rename_ident);
check(
"k",
r#"
@ -829,7 +831,7 @@ impl Foo {
#[test]
fn test_rename_field_in_field_shorthand() {
mark::check!(test_rename_field_in_field_shorthand);
cov_mark::check!(test_rename_field_in_field_shorthand);
check(
"j",
r#"
@ -855,7 +857,7 @@ impl Foo {
#[test]
fn test_rename_local_in_field_shorthand() {
mark::check!(test_rename_local_in_field_shorthand);
cov_mark::check!(test_rename_local_in_field_shorthand);
check(
"j",
r#"
@ -1261,7 +1263,7 @@ fn foo(f: foo::Foo) {
#[test]
fn test_parameter_to_self() {
mark::check!(rename_to_self);
cov_mark::check!(rename_to_self);
check(
"self",
r#"
@ -1401,7 +1403,7 @@ impl Foo {
#[test]
fn test_owned_self_to_parameter() {
mark::check!(rename_self_to_param);
cov_mark::check!(rename_self_to_param);
check(
"foo",
r#"
@ -1454,7 +1456,7 @@ impl Foo {
#[test]
fn test_rename_field_put_init_shorthand() {
mark::check!(test_rename_field_put_init_shorthand);
cov_mark::check!(test_rename_field_put_init_shorthand);
check(
"bar",
r#"
@ -1476,7 +1478,7 @@ fn foo(bar: i32) -> Foo {
#[test]
fn test_rename_local_put_init_shorthand() {
mark::check!(test_rename_local_put_init_shorthand);
cov_mark::check!(test_rename_local_put_init_shorthand);
check(
"i",
r#"
@ -1498,7 +1500,7 @@ fn foo(i: i32) -> Foo {
#[test]
fn test_struct_field_pat_into_shorthand() {
mark::check!(test_rename_field_put_init_shorthand_pat);
cov_mark::check!(test_rename_field_put_init_shorthand_pat);
check(
"baz",
r#"
@ -1610,7 +1612,7 @@ fn foo(foo: Foo) {
#[test]
fn test_rename_lifetimes() {
mark::check!(rename_lifetime);
cov_mark::check!(rename_lifetime);
check(
"'yeeee",
r#"
@ -1698,7 +1700,7 @@ fn foo<'a>() -> &'a () {
#[test]
fn test_self_to_self() {
mark::check!(rename_self_to_self);
cov_mark::check!(rename_self_to_self);
check(
"self",
r#"

View file

@ -9,7 +9,6 @@ use syntax::{
ast::{self, AstNode, AttrsOwner},
match_ast, SyntaxNode,
};
use test_utils::mark;
use crate::{
display::{ToNav, TryToNav},
@ -130,7 +129,9 @@ fn runnables_mod(sema: &Semantics<RootDatabase>, acc: &mut Vec<Runnable>, module
if let hir::ModuleDef::Module(submodule) = def {
match submodule.definition_source(sema.db).value {
hir::ModuleSource::Module(_) => runnables_mod(sema, acc, submodule),
hir::ModuleSource::SourceFile(_) => mark::hit!(dont_recurse_in_outline_submodules),
hir::ModuleSource::SourceFile(_) => {
cov_mark::hit!(dont_recurse_in_outline_submodules)
}
hir::ModuleSource::BlockExpr(_) => {} // inner items aren't runnable
}
}
@ -328,7 +329,6 @@ fn has_test_function_or_multiple_test_submodules(
#[cfg(test)]
mod tests {
use expect_test::{expect, Expect};
use test_utils::mark;
use crate::fixture;
@ -1056,7 +1056,7 @@ mod tests {
#[test]
fn dont_recurse_in_outline_submodules() {
mark::check!(dont_recurse_in_outline_submodules);
cov_mark::check!(dont_recurse_in_outline_submodules);
check(
r#"
//- /lib.rs

View file

@ -9,7 +9,7 @@ use syntax::{
SyntaxKind::*,
SyntaxToken, TextRange, TextSize, TokenAtOffset,
};
use test_utils::mark;
use text_edit::TextEdit;
// Feature: On Enter
@ -55,7 +55,7 @@ pub(crate) fn on_enter(db: &RootDatabase, position: FilePosition) -> Option<Text
// Continuing single-line non-doc comments (like this one :) ) is annoying
if prefix == "//" && comment_range.end() == position.offset {
if comment.text().ends_with(' ') {
mark::hit!(continues_end_of_line_comment_with_space);
cov_mark::hit!(continues_end_of_line_comment_with_space);
remove_trailing_whitespace = true;
} else if !followed_by_comment(&comment) {
return None;
@ -109,7 +109,7 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
#[cfg(test)]
mod tests {
use stdx::trim_indent;
use test_utils::{assert_eq_text, mark};
use test_utils::assert_eq_text;
use crate::fixture;
@ -238,7 +238,7 @@ fn main() {
#[test]
fn continues_end_of_line_comment_with_space() {
mark::check!(continues_end_of_line_comment_with_space);
cov_mark::check!(continues_end_of_line_comment_with_space);
do_check(
r#"
fn main() {