4320: add doctest support r=matklad a=bnjjj

close #4317

preview:

<img width="253" alt="Capture d’écran 2020-05-05 à 17 39 58" src="https://user-images.githubusercontent.com/5719034/81086040-45110b80-8ef8-11ea-9c05-79c6fe400fc3.png">


Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
bors[bot] 2020-05-05 16:22:31 +00:00 committed by GitHub
commit f0411ff9e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 6 deletions

View file

@ -27,7 +27,7 @@ impl CargoTargetSpec {
RunnableKind::Test { test_id, attr } => {
args.push("test".to_string());
if let Some(spec) = spec {
spec.push_to(&mut args);
spec.push_to(&mut args, kind);
}
extra_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
@ -35,13 +35,13 @@ impl CargoTargetSpec {
}
extra_args.push("--nocapture".to_string());
if attr.ignore {
extra_args.push("--ignored".to_string())
extra_args.push("--ignored".to_string());
}
}
RunnableKind::TestMod { path } => {
args.push("test".to_string());
if let Some(spec) = spec {
spec.push_to(&mut args);
spec.push_to(&mut args, kind);
}
extra_args.push(path.to_string());
extra_args.push("--nocapture".to_string());
@ -49,7 +49,7 @@ impl CargoTargetSpec {
RunnableKind::Bench { test_id } => {
args.push("bench".to_string());
if let Some(spec) = spec {
spec.push_to(&mut args);
spec.push_to(&mut args, kind);
}
extra_args.push(test_id.to_string());
if let TestId::Path(_) = test_id {
@ -57,10 +57,19 @@ impl CargoTargetSpec {
}
extra_args.push("--nocapture".to_string());
}
RunnableKind::DocTest { test_id } => {
args.push("test".to_string());
args.push("--doc".to_string());
if let Some(spec) = spec {
spec.push_to(&mut args, kind);
}
extra_args.push(test_id.to_string());
extra_args.push("--nocapture".to_string());
}
RunnableKind::Bin => {
args.push("run".to_string());
if let Some(spec) = spec {
spec.push_to(&mut args);
spec.push_to(&mut args, kind);
}
}
}
@ -91,9 +100,14 @@ impl CargoTargetSpec {
Ok(res)
}
pub(crate) fn push_to(self, buf: &mut Vec<String>) {
pub(crate) fn push_to(self, buf: &mut Vec<String>, kind: &RunnableKind) {
buf.push("--package".to_string());
buf.push(self.package);
// Can't mix --doc with other target flags
if let RunnableKind::DocTest { .. } = kind {
return;
}
match self.target_kind {
TargetKind::Bin => {
buf.push("--bin".to_string());

View file

@ -835,6 +835,7 @@ pub fn handle_code_lens(
for runnable in world.analysis().runnables(file_id)? {
let title = match &runnable.kind {
RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => "▶️\u{fe0e}Run Test",
RunnableKind::DocTest { .. } => "▶️\u{fe0e}Run Doctest",
RunnableKind::Bench { .. } => "Run Bench",
RunnableKind::Bin => "Run",
}
@ -1018,6 +1019,7 @@ fn to_lsp_runnable(
RunnableKind::Test { test_id, .. } => format!("test {}", test_id),
RunnableKind::TestMod { path } => format!("test-mod {}", path),
RunnableKind::Bench { test_id } => format!("bench {}", test_id),
RunnableKind::DocTest { test_id, .. } => format!("doctest {}", test_id),
RunnableKind::Bin => "run binary".to_string(),
};
Ok(req::Runnable {