Skip to content

Commit

Permalink
Fix runnable detection for #[tokio::test]
Browse files Browse the repository at this point in the history
  • Loading branch information
HKalbasi committed Jun 28, 2023
1 parent 7c8ae35 commit 97c48f9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
9 changes: 8 additions & 1 deletion crates/hir-def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@ impl Attrs {
}

pub fn is_test(&self) -> bool {
self.by_key("test").exists()
self.iter().any(|x| {
x.path()
.segments()
.iter()
.rev()
.zip(["core", "prelude", "v1", "test"].iter().rev())
.all(|x| x.0.as_str() == Some(x.1))
})
}

pub fn is_ignore(&self) -> bool {
Expand Down
36 changes: 30 additions & 6 deletions crates/ide/src/runnables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ fn main() {}
#[test]
fn test_foo() {}
#[::core::prelude::v1::test]
fn test_full_path() {}
#[test]
#[ignore]
fn test_foo() {}
Expand All @@ -600,7 +603,7 @@ mod not_a_root {
fn main() {}
}
"#,
&[TestMod, Bin, Test, Test, Bench],
&[TestMod, Bin, Test, Test, Test, Bench],
expect![[r#"
[
Runnable {
Expand All @@ -609,7 +612,7 @@ mod not_a_root {
file_id: FileId(
0,
),
full_range: 0..137,
full_range: 0..190,
name: "",
kind: Module,
},
Expand Down Expand Up @@ -659,8 +662,29 @@ mod not_a_root {
file_id: FileId(
0,
),
full_range: 41..75,
focus_range: 62..70,
full_range: 41..92,
focus_range: 73..87,
name: "test_full_path",
kind: Function,
},
kind: Test {
test_id: Path(
"test_full_path",
),
attr: TestAttr {
ignore: false,
},
},
cfg: None,
},
Runnable {
use_name_in_title: false,
nav: NavigationTarget {
file_id: FileId(
0,
),
full_range: 94..128,
focus_range: 115..123,
name: "test_foo",
kind: Function,
},
Expand All @@ -680,8 +704,8 @@ mod not_a_root {
file_id: FileId(
0,
),
full_range: 77..99,
focus_range: 89..94,
full_range: 130..152,
focus_range: 142..147,
name: "bench",
kind: Function,
},
Expand Down

0 comments on commit 97c48f9

Please sign in to comment.