Add run-tests command

This commit is contained in:
hkalbasi 2023-06-22 19:33:37 +03:30
parent f0e00ed599
commit 674cd5ab57
8 changed files with 166 additions and 36 deletions

View file

@ -2,7 +2,7 @@ use std::fmt;
use ast::HasName;
use cfg::CfgExpr;
use hir::{AsAssocItem, HasAttrs, HasSource, Semantics};
use hir::{db::HirDatabase, AsAssocItem, HasAttrs, HasSource, Semantics};
use ide_assists::utils::test_related_attribute;
use ide_db::{
base_db::{FilePosition, FileRange},
@ -14,7 +14,7 @@ use ide_db::{
use itertools::Itertools;
use stdx::{always, format_to};
use syntax::{
ast::{self, AstNode, HasAttrs as _},
ast::{self, AstNode},
SmolStr, SyntaxNode,
};
@ -307,7 +307,6 @@ pub(crate) fn runnable_fn(
sema: &Semantics<'_, RootDatabase>,
def: hir::Function,
) -> Option<Runnable> {
let func = def.source(sema.db)?;
let name = def.name(sema.db).to_smol_str();
let root = def.module(sema.db).krate().root_module(sema.db);
@ -323,10 +322,10 @@ pub(crate) fn runnable_fn(
canonical_path.map(TestId::Path).unwrap_or(TestId::Name(name))
};
if test_related_attribute(&func.value).is_some() {
let attr = TestAttr::from_fn(&func.value);
if def.is_test(sema.db) {
let attr = TestAttr::from_fn(sema.db, def);
RunnableKind::Test { test_id: test_id(), attr }
} else if func.value.has_atom_attr("bench") {
} else if def.is_bench(sema.db) {
RunnableKind::Bench { test_id: test_id() }
} else {
return None;
@ -335,7 +334,7 @@ pub(crate) fn runnable_fn(
let nav = NavigationTarget::from_named(
sema.db,
func.as_ref().map(|it| it as &dyn ast::HasName),
def.source(sema.db)?.as_ref().map(|it| it as &dyn ast::HasName),
SymbolKind::Function,
);
let cfg = def.attrs(sema.db).cfg();
@ -487,12 +486,8 @@ pub struct TestAttr {
}
impl TestAttr {
fn from_fn(fn_def: &ast::Fn) -> TestAttr {
let ignore = fn_def
.attrs()
.filter_map(|attr| attr.simple_name())
.any(|attribute_text| attribute_text == "ignore");
TestAttr { ignore }
fn from_fn(db: &dyn HirDatabase, fn_def: hir::Function) -> TestAttr {
TestAttr { ignore: fn_def.is_ignore(db) }
}
}