diff options
author | Benjamin Coenen <[email protected]> | 2020-05-05 16:43:28 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-05-05 16:44:27 +0100 |
commit | fe52f8f0281c0f56955871863a6e0c14732540f9 (patch) | |
tree | 14bed0631da587bfc25a8560037386ce2fdc6887 /crates/rust-analyzer/src/cargo_target_spec.rs | |
parent | 15de338703fd9c789c4cf8041a59d8730f12bc78 (diff) |
add doctest support #4317
Signed-off-by: Benjamin Coenen <[email protected]>
Diffstat (limited to 'crates/rust-analyzer/src/cargo_target_spec.rs')
-rw-r--r-- | crates/rust-analyzer/src/cargo_target_spec.rs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/crates/rust-analyzer/src/cargo_target_spec.rs b/crates/rust-analyzer/src/cargo_target_spec.rs index 10c25666a..5e5a17943 100644 --- a/crates/rust-analyzer/src/cargo_target_spec.rs +++ b/crates/rust-analyzer/src/cargo_target_spec.rs | |||
@@ -27,7 +27,7 @@ impl CargoTargetSpec { | |||
27 | RunnableKind::Test { test_id, attr } => { | 27 | RunnableKind::Test { test_id, attr } => { |
28 | args.push("test".to_string()); | 28 | args.push("test".to_string()); |
29 | if let Some(spec) = spec { | 29 | if let Some(spec) = spec { |
30 | spec.push_to(&mut args); | 30 | spec.push_to(&mut args, kind); |
31 | } | 31 | } |
32 | extra_args.push(test_id.to_string()); | 32 | extra_args.push(test_id.to_string()); |
33 | if let TestId::Path(_) = test_id { | 33 | if let TestId::Path(_) = test_id { |
@@ -35,13 +35,13 @@ impl CargoTargetSpec { | |||
35 | } | 35 | } |
36 | extra_args.push("--nocapture".to_string()); | 36 | extra_args.push("--nocapture".to_string()); |
37 | if attr.ignore { | 37 | if attr.ignore { |
38 | extra_args.push("--ignored".to_string()) | 38 | extra_args.push("--ignored".to_string()); |
39 | } | 39 | } |
40 | } | 40 | } |
41 | RunnableKind::TestMod { path } => { | 41 | RunnableKind::TestMod { path } => { |
42 | args.push("test".to_string()); | 42 | args.push("test".to_string()); |
43 | if let Some(spec) = spec { | 43 | if let Some(spec) = spec { |
44 | spec.push_to(&mut args); | 44 | spec.push_to(&mut args, kind); |
45 | } | 45 | } |
46 | extra_args.push(path.to_string()); | 46 | extra_args.push(path.to_string()); |
47 | extra_args.push("--nocapture".to_string()); | 47 | extra_args.push("--nocapture".to_string()); |
@@ -49,7 +49,7 @@ impl CargoTargetSpec { | |||
49 | RunnableKind::Bench { test_id } => { | 49 | RunnableKind::Bench { test_id } => { |
50 | args.push("bench".to_string()); | 50 | args.push("bench".to_string()); |
51 | if let Some(spec) = spec { | 51 | if let Some(spec) = spec { |
52 | spec.push_to(&mut args); | 52 | spec.push_to(&mut args, kind); |
53 | } | 53 | } |
54 | extra_args.push(test_id.to_string()); | 54 | extra_args.push(test_id.to_string()); |
55 | if let TestId::Path(_) = test_id { | 55 | if let TestId::Path(_) = test_id { |
@@ -57,10 +57,19 @@ impl CargoTargetSpec { | |||
57 | } | 57 | } |
58 | extra_args.push("--nocapture".to_string()); | 58 | extra_args.push("--nocapture".to_string()); |
59 | } | 59 | } |
60 | RunnableKind::DocTest { test_id } => { | ||
61 | args.push("test".to_string()); | ||
62 | args.push("--doc".to_string()); | ||
63 | if let Some(spec) = spec { | ||
64 | spec.push_to(&mut args, kind); | ||
65 | } | ||
66 | extra_args.push(test_id.to_string()); | ||
67 | extra_args.push("--nocapture".to_string()); | ||
68 | } | ||
60 | RunnableKind::Bin => { | 69 | RunnableKind::Bin => { |
61 | args.push("run".to_string()); | 70 | args.push("run".to_string()); |
62 | if let Some(spec) = spec { | 71 | if let Some(spec) = spec { |
63 | spec.push_to(&mut args); | 72 | spec.push_to(&mut args, kind); |
64 | } | 73 | } |
65 | } | 74 | } |
66 | } | 75 | } |
@@ -91,9 +100,14 @@ impl CargoTargetSpec { | |||
91 | Ok(res) | 100 | Ok(res) |
92 | } | 101 | } |
93 | 102 | ||
94 | pub(crate) fn push_to(self, buf: &mut Vec<String>) { | 103 | pub(crate) fn push_to(self, buf: &mut Vec<String>, kind: &RunnableKind) { |
95 | buf.push("--package".to_string()); | 104 | buf.push("--package".to_string()); |
96 | buf.push(self.package); | 105 | buf.push(self.package); |
106 | |||
107 | // Can't mix --doc with other target flags | ||
108 | if let RunnableKind::DocTest { .. } = kind { | ||
109 | return; | ||
110 | } | ||
97 | match self.target_kind { | 111 | match self.target_kind { |
98 | TargetKind::Bin => { | 112 | TargetKind::Bin => { |
99 | buf.push("--bin".to_string()); | 113 | buf.push("--bin".to_string()); |