feat: run ignored tests

This commit is contained in:
Hannes De Valkeneer 2020-04-22 22:52:12 +02:00
parent 3f1f3a835a
commit 380a2870c7
3 changed files with 38 additions and 4 deletions

View file

@ -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<RootDatabase>, fn_def: ast::FnDef) -> Option<Run
};
if has_test_related_attribute(&fn_def) {
RunnableKind::Test { test_id }
let attr = TestAttr::from_fn(&fn_def);
RunnableKind::Test { test_id, attr }
} else if fn_def.has_atom_attr("bench") {
RunnableKind::Bench { test_id }
} else {
@ -87,6 +88,21 @@ fn runnable_fn(sema: &Semantics<RootDatabase>, fn_def: ast::FnDef) -> Option<Run
Some(Runnable { range: fn_def.syntax().text_range(), kind })
}
#[derive(Debug)]
pub struct TestAttr {
pub ignore: bool,
}
impl TestAttr {
fn from_fn(fn_def: &ast::FnDef) -> 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,
},
},
},
]

View file

@ -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());

View file

@ -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(),