Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 7ec3d36

Browse files
committed
Update regex use to match test for external librairies
Make #[test] regex a little bit more permissive to allow external libs that have special test macro to be recognize as valid test case.
1 parent 838a834 commit 7ec3d36

File tree

3 files changed

+46
-18
lines changed

3 files changed

+46
-18
lines changed

rls/src/actions/run.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn collect_run_actions(ctx: &InitActionContext, file: &Path) -> Vec<RunActio
2323
}
2424

2525
lazy_static! {
26-
/// __(a):__ `\#\[test\]` matches `#[test]`
26+
/// __(a):__ `\#\[([\w]+::)*test\]` matches `#[test]`, `#[async_executor::test]` or `#[async_lib::module::test]`.
2727
///
2828
/// __(b):__ `^[^\/]*?fn\s+(?P<name>\w+)` matches any line which contains `fn name` before any comment is started and captures the word after fn.
2929
/// The laziness of the quantifier is there to make the regex quicker (about 5 times less steps)
@@ -42,7 +42,7 @@ pub fn collect_run_actions(ctx: &InitActionContext, file: &Path) -> Vec<RunActio
4242
/// fn right_function() {}
4343
/// ```
4444
static ref TEST_FN_RE: Regex =
45-
Regex::new(r"(?m)#\[test\](\n|.)*?^[^/]*?fn\s+(?P<name>\w+)").unwrap();
45+
Regex::new(r"(?m)#\[([\w]+::)*test\](\n|.)*?^[^/]*?fn\s+(?P<name>\w+)").unwrap();
4646
}
4747

4848
let line_index = LineIndex::new(&text);

tests/client.rs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -987,24 +987,42 @@ fn client_lens_run() {
987987
},
988988
);
989989

990-
let expected = CodeLens {
991-
command: Some(Command {
992-
command: "rls.run".to_string(),
993-
title: "Run test".to_string(),
994-
arguments: Some(vec![json!({
995-
"args": [ "test", "--", "--nocapture", "test_foo" ],
996-
"binary": "cargo",
997-
"env": { "RUST_BACKTRACE": "short" }
998-
})]),
999-
}),
1000-
data: None,
1001-
range: Range {
1002-
start: Position { line: 4, character: 3 },
1003-
end: Position { line: 4, character: 11 },
990+
let expected = vec![
991+
CodeLens {
992+
command: Some(Command {
993+
command: "rls.run".to_string(),
994+
title: "Run test".to_string(),
995+
arguments: Some(vec![json!({
996+
"args": [ "test", "--", "--nocapture", "test_foo" ],
997+
"binary": "cargo",
998+
"env": { "RUST_BACKTRACE": "short" }
999+
})]),
1000+
}),
1001+
data: None,
1002+
range: Range {
1003+
start: Position { line: 4, character: 3 },
1004+
end: Position { line: 4, character: 11 },
1005+
},
10041006
},
1005-
};
1007+
CodeLens {
1008+
command: Some(Command {
1009+
command: "rls.run".to_string(),
1010+
title: "Run test".to_string(),
1011+
arguments: Some(vec![json!({
1012+
"args": [ "test", "--", "--nocapture", "test_bar"],
1013+
"binary": "cargo",
1014+
"env": { "RUST_BACKTRACE": "short" }
1015+
})]),
1016+
}),
1017+
data: None,
1018+
range: Range {
1019+
start: Position { line: 9, character: 3 },
1020+
end: Position { line: 9, character: 11 },
1021+
},
1022+
},
1023+
];
10061024

1007-
assert_eq!(lens, Some(vec![expected]));
1025+
assert_eq!(lens, Some(expected));
10081026
}
10091027

10101028
#[test]

tests/fixtures/lens_run/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,13 @@ pub fn main() {
55
fn test_foo() {
66

77
}
8+
9+
#[tokio::test]
10+
fn test_bar() {
11+
12+
}
13+
14+
#[dummy_ext]
15+
fn test_baz() {
16+
17+
}

0 commit comments

Comments
 (0)