aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/runnables.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/runnables.rs')
-rw-r--r--crates/ra_ide/src/runnables.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs
index 7533692f6..b6b0c70f9 100644
--- a/crates/ra_ide/src/runnables.rs
+++ b/crates/ra_ide/src/runnables.rs
@@ -3,12 +3,13 @@
3use hir::InFile; 3use hir::InFile;
4use itertools::Itertools; 4use itertools::Itertools;
5use ra_db::SourceDatabase; 5use ra_db::SourceDatabase;
6use ra_ide_db::RootDatabase;
6use ra_syntax::{ 7use ra_syntax::{
7 ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner}, 8 ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner},
8 match_ast, SyntaxNode, TextRange, 9 match_ast, SyntaxNode, TextRange,
9}; 10};
10 11
11use crate::{db::RootDatabase, FileId}; 12use crate::FileId;
12 13
13#[derive(Debug)] 14#[derive(Debug)]
14pub struct Runnable { 15pub struct Runnable {
@@ -43,7 +44,7 @@ fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> {
43 let name = fn_def.name()?.text().clone(); 44 let name = fn_def.name()?.text().clone();
44 let kind = if name == "main" { 45 let kind = if name == "main" {
45 RunnableKind::Bin 46 RunnableKind::Bin
46 } else if fn_def.has_atom_attr("test") { 47 } else if has_test_related_attribute(&fn_def) {
47 RunnableKind::Test { name: name.to_string() } 48 RunnableKind::Test { name: name.to_string() }
48 } else if fn_def.has_atom_attr("bench") { 49 } else if fn_def.has_atom_attr("bench") {
49 RunnableKind::Bench { name: name.to_string() } 50 RunnableKind::Bench { name: name.to_string() }
@@ -53,6 +54,20 @@ fn runnable_fn(fn_def: ast::FnDef) -> Option<Runnable> {
53 Some(Runnable { range: fn_def.syntax().text_range(), kind }) 54 Some(Runnable { range: fn_def.syntax().text_range(), kind })
54} 55}
55 56
57/// This is a method with a heuristics to support test methods annotated with custom test annotations, such as
58/// `#[test_case(...)]`, `#[tokio::test]` and similar.
59/// Also a regular `#[test]` annotation is supported.
60///
61/// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test,
62/// but it's better than not to have the runnables for the tests at all.
63fn has_test_related_attribute(fn_def: &ast::FnDef) -> bool {
64 fn_def
65 .attrs()
66 .filter_map(|attr| attr.path())
67 .map(|path| path.syntax().to_string().to_lowercase())
68 .any(|attribute_text| attribute_text.contains("test"))
69}
70
56fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option<Runnable> { 71fn runnable_mod(db: &RootDatabase, file_id: FileId, module: ast::Module) -> Option<Runnable> {
57 let has_test_function = module 72 let has_test_function = module
58 .item_list()? 73 .item_list()?