diff options
Diffstat (limited to 'crates/ra_ide/src/runnables.rs')
-rw-r--r-- | crates/ra_ide/src/runnables.rs | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index f32ce0d22..9f7b5edfd 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs | |||
@@ -42,6 +42,42 @@ pub enum RunnableKind { | |||
42 | Bin, | 42 | Bin, |
43 | } | 43 | } |
44 | 44 | ||
45 | #[derive(Debug, Eq, PartialEq)] | ||
46 | pub struct RunnableAction { | ||
47 | pub run_title: &'static str, | ||
48 | pub debugee: bool, | ||
49 | } | ||
50 | |||
51 | const TEST: RunnableAction = RunnableAction { run_title: "▶\u{fe0e} Run Test", debugee: true }; | ||
52 | const DOCTEST: RunnableAction = | ||
53 | RunnableAction { run_title: "▶\u{fe0e} Run Doctest", debugee: false }; | ||
54 | const BENCH: RunnableAction = RunnableAction { run_title: "▶\u{fe0e} Run Bench", debugee: true }; | ||
55 | const BIN: RunnableAction = RunnableAction { run_title: "▶\u{fe0e} Run", debugee: true }; | ||
56 | |||
57 | impl Runnable { | ||
58 | // test package::module::testname | ||
59 | pub fn label(&self, target: Option<String>) -> String { | ||
60 | match &self.kind { | ||
61 | RunnableKind::Test { test_id, .. } => format!("test {}", test_id), | ||
62 | RunnableKind::TestMod { path } => format!("test-mod {}", path), | ||
63 | RunnableKind::Bench { test_id } => format!("bench {}", test_id), | ||
64 | RunnableKind::DocTest { test_id, .. } => format!("doctest {}", test_id), | ||
65 | RunnableKind::Bin => { | ||
66 | target.map_or_else(|| "run binary".to_string(), |t| format!("run {}", t)) | ||
67 | } | ||
68 | } | ||
69 | } | ||
70 | |||
71 | pub fn action(&self) -> &'static RunnableAction { | ||
72 | match &self.kind { | ||
73 | RunnableKind::Test { .. } | RunnableKind::TestMod { .. } => &TEST, | ||
74 | RunnableKind::DocTest { .. } => &DOCTEST, | ||
75 | RunnableKind::Bench { .. } => &BENCH, | ||
76 | RunnableKind::Bin => &BIN, | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
45 | // Feature: Run | 81 | // Feature: Run |
46 | // | 82 | // |
47 | // Shows a popup suggesting to run a test/benchmark/binary **at the current cursor | 83 | // Shows a popup suggesting to run a test/benchmark/binary **at the current cursor |
@@ -207,6 +243,15 @@ mod tests { | |||
207 | 243 | ||
208 | use crate::mock_analysis::analysis_and_position; | 244 | use crate::mock_analysis::analysis_and_position; |
209 | 245 | ||
246 | use super::{Runnable, RunnableAction, BENCH, BIN, DOCTEST, TEST}; | ||
247 | |||
248 | fn assert_actions(runnables: &[Runnable], actions: &[&RunnableAction]) { | ||
249 | assert_eq!( | ||
250 | actions, | ||
251 | runnables.into_iter().map(|it| it.action()).collect::<Vec<_>>().as_slice() | ||
252 | ); | ||
253 | } | ||
254 | |||
210 | #[test] | 255 | #[test] |
211 | fn test_runnables() { | 256 | fn test_runnables() { |
212 | let (analysis, pos) = analysis_and_position( | 257 | let (analysis, pos) = analysis_and_position( |
@@ -221,6 +266,9 @@ mod tests { | |||
221 | #[test] | 266 | #[test] |
222 | #[ignore] | 267 | #[ignore] |
223 | fn test_foo() {} | 268 | fn test_foo() {} |
269 | |||
270 | #[bench] | ||
271 | fn bench() {} | ||
224 | "#, | 272 | "#, |
225 | ); | 273 | ); |
226 | let runnables = analysis.runnables(pos.file_id).unwrap(); | 274 | let runnables = analysis.runnables(pos.file_id).unwrap(); |
@@ -295,9 +343,32 @@ mod tests { | |||
295 | }, | 343 | }, |
296 | cfg_exprs: [], | 344 | cfg_exprs: [], |
297 | }, | 345 | }, |
346 | Runnable { | ||
347 | nav: NavigationTarget { | ||
348 | file_id: FileId( | ||
349 | 1, | ||
350 | ), | ||
351 | full_range: 82..104, | ||
352 | name: "bench", | ||
353 | kind: FN_DEF, | ||
354 | focus_range: Some( | ||
355 | 94..99, | ||
356 | ), | ||
357 | container_name: None, | ||
358 | description: None, | ||
359 | docs: None, | ||
360 | }, | ||
361 | kind: Bench { | ||
362 | test_id: Path( | ||
363 | "bench", | ||
364 | ), | ||
365 | }, | ||
366 | cfg_exprs: [], | ||
367 | }, | ||
298 | ] | 368 | ] |
299 | "### | 369 | "### |
300 | ); | 370 | ); |
371 | assert_actions(&runnables, &[&BIN, &TEST, &TEST, &BENCH]); | ||
301 | } | 372 | } |
302 | 373 | ||
303 | #[test] | 374 | #[test] |
@@ -361,6 +432,7 @@ mod tests { | |||
361 | ] | 432 | ] |
362 | "### | 433 | "### |
363 | ); | 434 | ); |
435 | assert_actions(&runnables, &[&BIN, &DOCTEST]); | ||
364 | } | 436 | } |
365 | 437 | ||
366 | #[test] | 438 | #[test] |
@@ -427,6 +499,7 @@ mod tests { | |||
427 | ] | 499 | ] |
428 | "### | 500 | "### |
429 | ); | 501 | ); |
502 | assert_actions(&runnables, &[&BIN, &DOCTEST]); | ||
430 | } | 503 | } |
431 | 504 | ||
432 | #[test] | 505 | #[test] |
@@ -493,6 +566,7 @@ mod tests { | |||
493 | ] | 566 | ] |
494 | "### | 567 | "### |
495 | ); | 568 | ); |
569 | assert_actions(&runnables, &[&TEST, &TEST]); | ||
496 | } | 570 | } |
497 | 571 | ||
498 | #[test] | 572 | #[test] |
@@ -561,6 +635,7 @@ mod tests { | |||
561 | ] | 635 | ] |
562 | "### | 636 | "### |
563 | ); | 637 | ); |
638 | assert_actions(&runnables, &[&TEST, &TEST]); | ||
564 | } | 639 | } |
565 | 640 | ||
566 | #[test] | 641 | #[test] |
@@ -631,6 +706,7 @@ mod tests { | |||
631 | ] | 706 | ] |
632 | "### | 707 | "### |
633 | ); | 708 | ); |
709 | assert_actions(&runnables, &[&TEST, &TEST]); | ||
634 | } | 710 | } |
635 | 711 | ||
636 | #[test] | 712 | #[test] |
@@ -681,6 +757,7 @@ mod tests { | |||
681 | ] | 757 | ] |
682 | "### | 758 | "### |
683 | ); | 759 | ); |
760 | assert_actions(&runnables, &[&TEST]); | ||
684 | } | 761 | } |
685 | 762 | ||
686 | #[test] | 763 | #[test] |
@@ -739,6 +816,7 @@ mod tests { | |||
739 | ] | 816 | ] |
740 | "### | 817 | "### |
741 | ); | 818 | ); |
819 | assert_actions(&runnables, &[&TEST]); | ||
742 | } | 820 | } |
743 | 821 | ||
744 | #[test] | 822 | #[test] |