From 380a2870c73be5c03512b5711988d760cd21cca6 Mon Sep 17 00:00:00 2001 From: Hannes De Valkeneer Date: Wed, 22 Apr 2020 22:52:12 +0200 Subject: feat: run ignored tests --- crates/ra_ide/src/runnables.rs | 35 ++++++++++++++++++++++++-- crates/rust-analyzer/src/cargo_target_spec.rs | 5 +++- crates/rust-analyzer/src/main_loop/handlers.rs | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 9433f3a24..05a66e03c 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -34,7 +34,7 @@ impl Display for TestId { #[derive(Debug)] pub enum RunnableKind { - Test { test_id: TestId }, + Test { test_id: TestId, attr: TestAttr }, TestMod { path: String }, Bench { test_id: TestId }, Bin, @@ -77,7 +77,8 @@ fn runnable_fn(sema: &Semantics, fn_def: ast::FnDef) -> Option, fn_def: ast::FnDef) -> Option TestAttr { + let ignore = fn_def + .attrs() + .filter_map(|attr| attr.simple_name()) + .any(|attribute_text| attribute_text == "ignore"); + TestAttr { ignore } + } +} + /// This is a method with a heuristics to support test methods annotated with custom test annotations, such as /// `#[test_case(...)]`, `#[tokio::test]` and similar. /// Also a regular `#[test]` annotation is supported. @@ -157,6 +173,9 @@ mod tests { test_id: Path( "test_foo", ), + attr: TestAttr { + ignore: false, + }, }, }, Runnable { @@ -165,6 +184,9 @@ mod tests { test_id: Path( "test_foo", ), + attr: TestAttr { + ignore: true, + }, }, }, ] @@ -200,6 +222,9 @@ mod tests { test_id: Path( "test_mod::test_foo1", ), + attr: TestAttr { + ignore: false, + }, }, }, ] @@ -237,6 +262,9 @@ mod tests { test_id: Path( "foo::test_mod::test_foo1", ), + attr: TestAttr { + ignore: false, + }, }, }, ] @@ -276,6 +304,9 @@ mod tests { test_id: Path( "foo::bar::test_mod::test_foo1", ), + attr: TestAttr { + ignore: false, + }, }, }, ] diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index 942c30328..c2ece49f4 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs @@ -23,7 +23,7 @@ impl CargoTargetSpec { let mut args = Vec::new(); let mut extra_args = Vec::new(); match kind { - RunnableKind::Test { test_id } => { + RunnableKind::Test { test_id, attr } => { args.push("test".to_string()); if let Some(spec) = spec { spec.push_to(&mut args); @@ -33,6 +33,9 @@ impl CargoTargetSpec { extra_args.push("--exact".to_string()); } extra_args.push("--nocapture".to_string()); + if attr.ignore { + extra_args.push("--ignored".to_string()) + } } RunnableKind::TestMod { path } => { args.push("test".to_string()); diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs index b207f0764..41d9fe344 100644 --- a/crates/rust-analyzer/src/main_loop/handlers.rs +++ b/crates/rust-analyzer/src/main_loop/handlers.rs @@ -968,7 +968,7 @@ fn to_lsp_runnable( let (args, extra_args) = CargoTargetSpec::runnable_args(spec, &runnable.kind)?; let line_index = world.analysis().file_line_index(file_id)?; let label = match &runnable.kind { - RunnableKind::Test { test_id } => format!("test {}", test_id), + RunnableKind::Test { test_id, .. } => format!("test {}", test_id), RunnableKind::TestMod { path } => format!("test-mod {}", path), RunnableKind::Bench { test_id } => format!("bench {}", test_id), RunnableKind::Bin => "run binary".to_string(), -- cgit v1.2.3