mark tokio::test as test - #16768
mark tokio::test as test#16768PSeitz wants to merge 1 commit into
Conversation
this is to support the `excludeTests` option to also handle `#[tokio::test]`
| }) || self.iter().any(|it| { | ||
| it.path() | ||
| .segments() | ||
| .iter() | ||
| .zip(["tokio", "test"].iter()) | ||
| .all(|it| it.0.as_str() == Some(it.1)) |
There was a problem hiding this comment.
That's the wrong way to fix this, we need to go up the expansion hierarchy to find the necessary test attribute when categorizing the references
There was a problem hiding this comment.
I thought that's too slow as mentioned here: #16441 (comment)
Although I would prefer to have a full filtered result which takes a little bit longer
There was a problem hiding this comment.
Right, that was about general traversal which we do, we are missing traversing up the macro expansions still though. Seems that was overlooked in the PR. That won't make much of a difference I guess given most finds shouldn't be in macro calls anyways.
There was a problem hiding this comment.
I thought it's related to tokio::test, but it's not:
#16768 (comment)
| test_func(); | ||
| } | ||
|
|
||
| #[tokio::test] |
There was a problem hiding this comment.
#[tokio::test] is already mark as test, cause it will be expand to #[::core::prelude::v1::test]
There was a problem hiding this comment.
I thought it's not working because I saw a lot of references in tokio::test, but the problem with detection seems more general.
e.g. a vec![] is enough to break the current filter
struct Point {
x: f64,
y: f64,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
let vec = vec![Point { x: 1.0, y: 2.0 }];
assert_eq!(vec.len(), 1);
}
}|
@Veykril @Young-Flash
fn is_name_ref_in_test(sema: &Semantics<'_, RootDatabase>, name_ref: &ast::NameRef) -> bool {
name_ref.syntax().ancestors().any(|node| match ast::Fn::cast(node) {
Some(it) => sema.to_def(&it).map_or(false, |func| func.is_test(sema.db)),
None => false,
})
}struct Point {
x: f64,
y: f64,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
let vec = vec![Point { x: 1.0, y: 2.0 }];
assert_eq!(vec.len(), 1);
}
} |
|
The problem is that the Using rust-analyzer/crates/hir-expand/src/files.rs Line 151 in f17a8c7 |
this is to support the
excludeTestsoption to also handle#[tokio::test]