aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-25 18:29:50 +0100
committerGitHub <[email protected]>2020-08-25 18:29:50 +0100
commit91bedefe491af3bf4eeb13bc7716cc419cafe067 (patch)
treef36235847010714710ae16a36509e3efd36b1d43 /crates
parent6141e2706ae73450eea317b6326307b9c54f41b6 (diff)
parentc6dffe479b1cd9ad1a81bd2f3f3f18bf8c112bda (diff)
Merge #5883
5883: Cleanup heavy tests r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/tests/rust-analyzer/main.rs74
-rw-r--r--crates/rust-analyzer/tests/rust-analyzer/support.rs5
2 files changed, 42 insertions, 37 deletions
diff --git a/crates/rust-analyzer/tests/rust-analyzer/main.rs b/crates/rust-analyzer/tests/rust-analyzer/main.rs
index e97784c47..0880d0425 100644
--- a/crates/rust-analyzer/tests/rust-analyzer/main.rs
+++ b/crates/rust-analyzer/tests/rust-analyzer/main.rs
@@ -39,7 +39,6 @@ fn completes_items_from_standard_library() {
39 return; 39 return;
40 } 40 }
41 41
42 let project_start = Instant::now();
43 let server = Project::with_fixture( 42 let server = Project::with_fixture(
44 r#" 43 r#"
45//- /Cargo.toml 44//- /Cargo.toml
@@ -52,10 +51,9 @@ use std::collections::Spam;
52"#, 51"#,
53 ) 52 )
54 .with_sysroot(true) 53 .with_sysroot(true)
55 .server(); 54 .server()
56 server.wait_until_workspace_is_loaded(); 55 .wait_until_workspace_is_loaded();
57 eprintln!("loading took {:?}", project_start.elapsed()); 56
58 let completion_start = Instant::now();
59 let res = server.send_request::<Completion>(CompletionParams { 57 let res = server.send_request::<Completion>(CompletionParams {
60 text_document_position: TextDocumentPositionParams::new( 58 text_document_position: TextDocumentPositionParams::new(
61 server.doc_id("src/lib.rs"), 59 server.doc_id("src/lib.rs"),
@@ -66,7 +64,6 @@ use std::collections::Spam;
66 work_done_progress_params: WorkDoneProgressParams::default(), 64 work_done_progress_params: WorkDoneProgressParams::default(),
67 }); 65 });
68 assert!(res.to_string().contains("HashMap")); 66 assert!(res.to_string().contains("HashMap"));
69 eprintln!("completion took {:?}", completion_start.elapsed());
70} 67}
71 68
72#[test] 69#[test]
@@ -75,7 +72,8 @@ fn test_runnables_project() {
75 return; 72 return;
76 } 73 }
77 74
78 let code = r#" 75 let server = Project::with_fixture(
76 r#"
79//- /foo/Cargo.toml 77//- /foo/Cargo.toml
80[package] 78[package]
81name = "foo" 79name = "foo"
@@ -95,11 +93,13 @@ version = "0.0.0"
95 93
96//- /bar/src/main.rs 94//- /bar/src/main.rs
97fn main() {} 95fn main() {}
98"#; 96"#,
99 97 )
100 let server = Project::with_fixture(code).root("foo").root("bar").server(); 98 .root("foo")
99 .root("bar")
100 .server()
101 .wait_until_workspace_is_loaded();
101 102
102 server.wait_until_workspace_is_loaded();
103 server.request::<Runnables>( 103 server.request::<Runnables>(
104 RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None }, 104 RunnablesParams { text_document: server.doc_id("foo/tests/spam.rs"), position: None },
105 json!([ 105 json!([
@@ -166,8 +166,8 @@ fn main() {
166 166
167pub use std::collections::HashMap; 167pub use std::collections::HashMap;
168"#, 168"#,
169 ); 169 )
170 server.wait_until_workspace_is_loaded(); 170 .wait_until_workspace_is_loaded();
171 171
172 server.request::<Formatting>( 172 server.request::<Formatting>(
173 DocumentFormattingParams { 173 DocumentFormattingParams {
@@ -224,8 +224,8 @@ fn main() {
224 224
225pub use std::collections::HashMap; 225pub use std::collections::HashMap;
226"#, 226"#,
227 ); 227 )
228 server.wait_until_workspace_is_loaded(); 228 .wait_until_workspace_is_loaded();
229 229
230 server.request::<Formatting>( 230 server.request::<Formatting>(
231 DocumentFormattingParams { 231 DocumentFormattingParams {
@@ -277,14 +277,14 @@ mod bar;
277 277
278fn main() {} 278fn main() {}
279"#, 279"#,
280 ); 280 )
281 server.wait_until_workspace_is_loaded(); 281 .wait_until_workspace_is_loaded();
282 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None }; 282
283 server.request::<CodeActionRequest>( 283 server.request::<CodeActionRequest>(
284 CodeActionParams { 284 CodeActionParams {
285 text_document: server.doc_id("src/lib.rs"), 285 text_document: server.doc_id("src/lib.rs"),
286 range: Range::new(Position::new(0, 4), Position::new(0, 7)), 286 range: Range::new(Position::new(0, 4), Position::new(0, 7)),
287 context: empty_context(), 287 context: CodeActionContext::default(),
288 partial_result_params: PartialResultParams::default(), 288 partial_result_params: PartialResultParams::default(),
289 work_done_progress_params: WorkDoneProgressParams::default(), 289 work_done_progress_params: WorkDoneProgressParams::default(),
290 }, 290 },
@@ -307,7 +307,7 @@ fn main() {}
307 CodeActionParams { 307 CodeActionParams {
308 text_document: server.doc_id("src/lib.rs"), 308 text_document: server.doc_id("src/lib.rs"),
309 range: Range::new(Position::new(2, 4), Position::new(2, 7)), 309 range: Range::new(Position::new(2, 4), Position::new(2, 7)),
310 context: empty_context(), 310 context: CodeActionContext::default(),
311 partial_result_params: PartialResultParams::default(), 311 partial_result_params: PartialResultParams::default(),
312 work_done_progress_params: WorkDoneProgressParams::default(), 312 work_done_progress_params: WorkDoneProgressParams::default(),
313 }, 313 },
@@ -348,15 +348,14 @@ fn main() {{}}
348 PROJECT = project.to_string(), 348 PROJECT = project.to_string(),
349 ); 349 );
350 350
351 let server = Project::with_fixture(&code).tmp_dir(tmp_dir).server(); 351 let server =
352 Project::with_fixture(&code).tmp_dir(tmp_dir).server().wait_until_workspace_is_loaded();
352 353
353 server.wait_until_workspace_is_loaded();
354 let empty_context = || CodeActionContext { diagnostics: Vec::new(), only: None };
355 server.request::<CodeActionRequest>( 354 server.request::<CodeActionRequest>(
356 CodeActionParams { 355 CodeActionParams {
357 text_document: server.doc_id("src/lib.rs"), 356 text_document: server.doc_id("src/lib.rs"),
358 range: Range::new(Position::new(0, 4), Position::new(0, 7)), 357 range: Range::new(Position::new(0, 4), Position::new(0, 7)),
359 context: empty_context(), 358 context: CodeActionContext::default(),
360 partial_result_params: PartialResultParams::default(), 359 partial_result_params: PartialResultParams::default(),
361 work_done_progress_params: WorkDoneProgressParams::default(), 360 work_done_progress_params: WorkDoneProgressParams::default(),
362 }, 361 },
@@ -379,7 +378,7 @@ fn main() {{}}
379 CodeActionParams { 378 CodeActionParams {
380 text_document: server.doc_id("src/lib.rs"), 379 text_document: server.doc_id("src/lib.rs"),
381 range: Range::new(Position::new(2, 4), Position::new(2, 7)), 380 range: Range::new(Position::new(2, 4), Position::new(2, 7)),
382 context: empty_context(), 381 context: CodeActionContext::default(),
383 partial_result_params: PartialResultParams::default(), 382 partial_result_params: PartialResultParams::default(),
384 work_done_progress_params: WorkDoneProgressParams::default(), 383 work_done_progress_params: WorkDoneProgressParams::default(),
385 }, 384 },
@@ -412,9 +411,9 @@ fn main() {{}}
412 librs, libs 411 librs, libs
413 )) 412 ))
414 .with_sysroot(true) 413 .with_sysroot(true)
415 .server(); 414 .server()
415 .wait_until_workspace_is_loaded();
416 416
417 server.wait_until_workspace_is_loaded();
418 for i in 0..10 { 417 for i in 0..10 {
419 server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams { 418 server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
420 text_document: TextDocumentItem { 419 text_document: TextDocumentItem {
@@ -425,7 +424,7 @@ fn main() {{}}
425 }, 424 },
426 }); 425 });
427 } 426 }
428 let start = std::time::Instant::now(); 427 let start = Instant::now();
429 server.request::<OnEnter>( 428 server.request::<OnEnter>(
430 TextDocumentPositionParams { 429 TextDocumentPositionParams {
431 text_document: server.doc_id("src/m0.rs"), 430 text_document: server.doc_id("src/m0.rs"),
@@ -461,8 +460,8 @@ version = \"0.0.0\"
461/// Some Docs\r\nfn main() {} 460/// Some Docs\r\nfn main() {}
462", 461",
463 ) 462 )
464 .server(); 463 .server()
465 server.wait_until_workspace_is_loaded(); 464 .wait_until_workspace_is_loaded();
466 465
467 server.request::<OnEnter>( 466 server.request::<OnEnter>(
468 TextDocumentPositionParams { 467 TextDocumentPositionParams {
@@ -536,8 +535,9 @@ fn main() {
536 .with_config(|config| { 535 .with_config(|config| {
537 config.cargo.load_out_dirs_from_check = true; 536 config.cargo.load_out_dirs_from_check = true;
538 }) 537 })
539 .server(); 538 .server()
540 server.wait_until_workspace_is_loaded(); 539 .wait_until_workspace_is_loaded();
540
541 let res = server.send_request::<HoverRequest>(HoverParams { 541 let res = server.send_request::<HoverRequest>(HoverParams {
542 text_document_position_params: TextDocumentPositionParams::new( 542 text_document_position_params: TextDocumentPositionParams::new(
543 server.doc_id("src/main.rs"), 543 server.doc_id("src/main.rs"),
@@ -546,6 +546,7 @@ fn main() {
546 work_done_progress_params: Default::default(), 546 work_done_progress_params: Default::default(),
547 }); 547 });
548 assert!(res.to_string().contains("&str")); 548 assert!(res.to_string().contains("&str"));
549
549 let res = server.send_request::<HoverRequest>(HoverParams { 550 let res = server.send_request::<HoverRequest>(HoverParams {
550 text_document_position_params: TextDocumentPositionParams::new( 551 text_document_position_params: TextDocumentPositionParams::new(
551 server.doc_id("src/main.rs"), 552 server.doc_id("src/main.rs"),
@@ -554,6 +555,7 @@ fn main() {
554 work_done_progress_params: Default::default(), 555 work_done_progress_params: Default::default(),
555 }); 556 });
556 assert!(res.to_string().contains("&str")); 557 assert!(res.to_string().contains("&str"));
558
557 server.request::<GotoTypeDefinition>( 559 server.request::<GotoTypeDefinition>(
558 GotoDefinitionParams { 560 GotoDefinitionParams {
559 text_document_position_params: TextDocumentPositionParams::new( 561 text_document_position_params: TextDocumentPositionParams::new(
@@ -579,6 +581,7 @@ fn main() {
579 "targetUri": "file:///[..]src/main.rs" 581 "targetUri": "file:///[..]src/main.rs"
580 }]), 582 }]),
581 ); 583 );
584
582 server.request::<GotoTypeDefinition>( 585 server.request::<GotoTypeDefinition>(
583 GotoDefinitionParams { 586 GotoDefinitionParams {
584 text_document_position_params: TextDocumentPositionParams::new( 587 text_document_position_params: TextDocumentPositionParams::new(
@@ -611,6 +614,7 @@ fn resolve_proc_macro() {
611 if skip_slow_tests() { 614 if skip_slow_tests() {
612 return; 615 return;
613 } 616 }
617
614 let server = Project::with_fixture( 618 let server = Project::with_fixture(
615 r###" 619 r###"
616//- /foo/Cargo.toml 620//- /foo/Cargo.toml
@@ -679,8 +683,9 @@ pub fn foo(_input: TokenStream) -> TokenStream {
679 }) 683 })
680 .root("foo") 684 .root("foo")
681 .root("bar") 685 .root("bar")
682 .server(); 686 .server()
683 server.wait_until_workspace_is_loaded(); 687 .wait_until_workspace_is_loaded();
688
684 let res = server.send_request::<HoverRequest>(HoverParams { 689 let res = server.send_request::<HoverRequest>(HoverParams {
685 text_document_position_params: TextDocumentPositionParams::new( 690 text_document_position_params: TextDocumentPositionParams::new(
686 server.doc_id("foo/src/main.rs"), 691 server.doc_id("foo/src/main.rs"),
@@ -688,7 +693,6 @@ pub fn foo(_input: TokenStream) -> TokenStream {
688 ), 693 ),
689 work_done_progress_params: Default::default(), 694 work_done_progress_params: Default::default(),
690 }); 695 });
691
692 let value = res.get("contents").unwrap().get("value").unwrap().to_string(); 696 let value = res.get("contents").unwrap().get("value").unwrap().to_string();
693 assert_eq!(value, r#""\n```rust\nfoo::Bar\n```\n\n```rust\nfn bar()\n```""#) 697 assert_eq!(value, r#""\n```rust\nfoo::Bar\n```\n\n```rust\nfn bar()\n```""#)
694} 698}
diff --git a/crates/rust-analyzer/tests/rust-analyzer/support.rs b/crates/rust-analyzer/tests/rust-analyzer/support.rs
index 5bafeba79..784cbda79 100644
--- a/crates/rust-analyzer/tests/rust-analyzer/support.rs
+++ b/crates/rust-analyzer/tests/rust-analyzer/support.rs
@@ -202,7 +202,7 @@ impl Server {
202 } 202 }
203 panic!("no response"); 203 panic!("no response");
204 } 204 }
205 pub fn wait_until_workspace_is_loaded(&self) { 205 pub fn wait_until_workspace_is_loaded(self) -> Server {
206 self.wait_for_message_cond(1, &|msg: &Message| match msg { 206 self.wait_for_message_cond(1, &|msg: &Message| match msg {
207 Message::Notification(n) if n.method == "$/progress" => { 207 Message::Notification(n) if n.method == "$/progress" => {
208 match n.clone().extract::<ProgressParams>("$/progress").unwrap() { 208 match n.clone().extract::<ProgressParams>("$/progress").unwrap() {
@@ -214,7 +214,8 @@ impl Server {
214 } 214 }
215 } 215 }
216 _ => false, 216 _ => false,
217 }) 217 });
218 self
218 } 219 }
219 fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&Message) -> bool) { 220 fn wait_for_message_cond(&self, n: usize, cond: &dyn Fn(&Message) -> bool) {
220 let mut total = 0; 221 let mut total = 0;