From 05daa86634b41aa3f311a1ac0b02bf7fed7ed569 Mon Sep 17 00:00:00 2001 From: Jan Jansen Date: Thu, 27 Dec 2018 21:45:16 +0100 Subject: Make modules with tests runnable Fixes #154 --- crates/ra_analysis/tests/runnables.rs | 118 ++++++++++++++++++++++++++++++++++ crates/ra_analysis/tests/tests.rs | 50 ++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 crates/ra_analysis/tests/runnables.rs (limited to 'crates/ra_analysis/tests') diff --git a/crates/ra_analysis/tests/runnables.rs b/crates/ra_analysis/tests/runnables.rs new file mode 100644 index 000000000..9e5342c46 --- /dev/null +++ b/crates/ra_analysis/tests/runnables.rs @@ -0,0 +1,118 @@ +extern crate ra_analysis; +extern crate ra_editor; +extern crate ra_syntax; +extern crate relative_path; +extern crate rustc_hash; +extern crate test_utils; + +use test_utils::assert_eq_dbg; + +use ra_analysis::{ + mock_analysis::{analysis_and_position}, +}; + +#[test] +fn test_runnables() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + fn main() {} + + #[test] + fn test_foo() {} + + #[test] + #[ignore] + fn test_foo() {} + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_eq_dbg( + r#"[Runnable { range: [1; 21), kind: Bin }, + Runnable { range: [22; 46), kind: Test { name: "test_foo" } }, + Runnable { range: [47; 81), kind: Test { name: "test_foo" } }]"#, + &runnables, + ) +} + +#[test] +fn test_runnables_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod test_mod { + #[test] + fn test_foo1() {} + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_eq_dbg( + r#"[Runnable { range: [1; 59), kind: TestMod { path: "test_mod" } }, + Runnable { range: [28; 57), kind: Test { name: "test_foo1" } }]"#, + &runnables, + ) +} + +#[test] +fn test_runnables_one_depth_layer_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod foo { + mod test_mod { + #[test] + fn test_foo1() {} + } + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_eq_dbg( + r#"[Runnable { range: [23; 85), kind: TestMod { path: "foo::test_mod" } }, + Runnable { range: [46; 79), kind: Test { name: "test_foo1" } }]"#, + &runnables, + ) +} + +#[test] +fn test_runnables_multiple_depth_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod foo { + mod bar { + mod test_mod { + #[test] + fn test_foo1() {} + } + } + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_eq_dbg( + r#"[Runnable { range: [41; 115), kind: TestMod { path: "foo::bar::test_mod" } }, + Runnable { range: [68; 105), kind: Test { name: "test_foo1" } }]"#, + &runnables, + ) +} + +#[test] +fn test_runnables_no_test_function_in_module() { + let (analysis, pos) = analysis_and_position( + r#" + //- /lib.rs + <|> //empty + mod test_mod { + fn foo1() {} + } + "#, + ); + let runnables = analysis.runnables(pos.file_id).unwrap(); + assert_eq_dbg(r#"[]"#, &runnables) +} diff --git a/crates/ra_analysis/tests/tests.rs b/crates/ra_analysis/tests/tests.rs index a314fbc40..b61ead752 100644 --- a/crates/ra_analysis/tests/tests.rs +++ b/crates/ra_analysis/tests/tests.rs @@ -131,6 +131,56 @@ fn test_resolve_parent_module_for_inline() { ); } +#[test] +fn test_path_one_layer() { + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + mod foo; + //- /foo/mod.rs + mod bla; + //- /foo/bla.rs + <|> //empty + ", + ); + let symbols = analysis.module_path(pos).unwrap().unwrap(); + assert_eq!("foo::bla", &symbols); +} + +#[test] +fn test_path_two_layer() { + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + mod foo; + //- /foo/mod.rs + mod bla; + //- /foo/bla/mod.rs + mod more; + //- /foo/bla/more.rs + <|> //empty + ", + ); + let symbols = analysis.module_path(pos).unwrap().unwrap(); + assert_eq!("foo::bla::more", &symbols); +} + +#[test] +fn test_path_in_file_mod() { + let (analysis, pos) = analysis_and_position( + " + //- /lib.rs + mod foo; + //- /foo.rs + mod bar { + <|> //empty + } + ", + ); + let symbols = analysis.module_path(pos).unwrap().unwrap(); + assert_eq!("foo::bar", &symbols); +} + #[test] fn test_resolve_crate_root() { let mock = MockAnalysis::with_files( -- cgit v1.2.3