|
1 | 1 | use std::fmt; |
2 | 2 |
|
| 3 | +use assists::utils::test_related_attribute; |
3 | 4 | use cfg::CfgExpr; |
4 | 5 | use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; |
5 | 6 | use ide_db::RootDatabase; |
@@ -156,7 +157,7 @@ fn runnable_fn( |
156 | 157 | None => TestId::Name(name_string), |
157 | 158 | }; |
158 | 159 |
|
159 | | - if has_test_related_attribute(&fn_def) { |
| 160 | + if test_related_attribute(&fn_def).is_some() { |
160 | 161 | let attr = TestAttr::from_fn(&fn_def); |
161 | 162 | RunnableKind::Test { test_id, attr } |
162 | 163 | } else if fn_def.has_atom_attr("bench") { |
@@ -235,20 +236,6 @@ impl TestAttr { |
235 | 236 | } |
236 | 237 | } |
237 | 238 |
|
238 | | -/// This is a method with a heuristics to support test methods annotated with custom test annotations, such as |
239 | | -/// `#[test_case(...)]`, `#[tokio::test]` and similar. |
240 | | -/// Also a regular `#[test]` annotation is supported. |
241 | | -/// |
242 | | -/// It may produce false positives, for example, `#[wasm_bindgen_test]` requires a different command to run the test, |
243 | | -/// but it's better than not to have the runnables for the tests at all. |
244 | | -pub(crate) fn has_test_related_attribute(fn_def: &ast::Fn) -> bool { |
245 | | - fn_def |
246 | | - .attrs() |
247 | | - .filter_map(|attr| attr.path()) |
248 | | - .map(|path| path.syntax().to_string().to_lowercase()) |
249 | | - .any(|attribute_text| attribute_text.contains("test")) |
250 | | -} |
251 | | - |
252 | 239 | const RUSTDOC_FENCE: &str = "```"; |
253 | 240 | const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] = |
254 | 241 | &["", "rust", "should_panic", "edition2015", "edition2018"]; |
@@ -307,7 +294,7 @@ fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { |
307 | 294 | for item in item_list.items() { |
308 | 295 | match item { |
309 | 296 | ast::Item::Fn(f) => { |
310 | | - if has_test_related_attribute(&f) { |
| 297 | + if test_related_attribute(&f).is_some() { |
311 | 298 | return true; |
312 | 299 | } |
313 | 300 | } |
|
0 commit comments