aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-31 18:19:37 +0100
committerGitHub <[email protected]>2020-03-31 18:19:37 +0100
commit37a01de42c1bd435710741a2e15ceee1efaccf39 (patch)
treef3c9bb9abb7ae2c6af7ca6886358a69a08725a06
parent47c9ee235552fe9eae974ea2560d16c6e5dc7ff4 (diff)
parenta4f9d966f015010e435d6a73360809a884c7415b (diff)
Merge #3793
3793: Add integrated test for concat include env r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/main.rs46
-rw-r--r--crates/rust-analyzer/tests/heavy_tests/support.rs21
2 files changed, 62 insertions, 5 deletions
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs
index 145429571..5af5eaad2 100644
--- a/crates/rust-analyzer/tests/heavy_tests/main.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/main.rs
@@ -9,7 +9,7 @@ use lsp_types::{
9}; 9};
10use rust_analyzer::req::{ 10use rust_analyzer::req::{
11 CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument, 11 CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument,
12 Formatting, OnEnter, Runnables, RunnablesParams, 12 Formatting, GotoDefinition, OnEnter, Runnables, RunnablesParams,
13}; 13};
14use serde_json::json; 14use serde_json::json;
15use tempfile::TempDir; 15use tempfile::TempDir;
@@ -581,3 +581,47 @@ version = \"0.0.0\"
581 }), 581 }),
582 ); 582 );
583} 583}
584
585#[test]
586fn resolve_include_concat_env() {
587 if skip_slow_tests() {
588 return;
589 }
590
591 let server = Project::with_fixture(
592 r###"
593//- Cargo.toml
594[package]
595name = "foo"
596version = "0.0.0"
597
598//- build.rs
599use std::{env, fs, path::Path};
600
601fn main() {
602 let out_dir = env::var_os("OUT_DIR").unwrap();
603 let dest_path = Path::new(&out_dir).join("hello.rs");
604 fs::write(
605 &dest_path,
606 r#"pub fn message() -> &'static str { "Hello, World!" }"#,
607 )
608 .unwrap();
609 println!("cargo:rerun-if-changed=build.rs");
610}
611//- src/main.rs
612include!(concat!(env!("OUT_DIR"), "/hello.rs"));
613
614fn main() { message(); }
615"###,
616 )
617 .with_config(|config| {
618 config.cargo_features.load_out_dirs_from_check = true;
619 })
620 .server();
621 server.wait_until_workspace_is_loaded();
622 let res = server.send_request::<GotoDefinition>(TextDocumentPositionParams::new(
623 server.doc_id("src/main.rs"),
624 Position::new(2, 15),
625 ));
626 assert!(format!("{}", res).contains("hello.rs"));
627}
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs
index fc3c65ad9..d8bed6d7f 100644
--- a/crates/rust-analyzer/tests/heavy_tests/support.rs
+++ b/crates/rust-analyzer/tests/heavy_tests/support.rs
@@ -27,11 +27,12 @@ pub struct Project<'a> {
27 with_sysroot: bool, 27 with_sysroot: bool,
28 tmp_dir: Option<TempDir>, 28 tmp_dir: Option<TempDir>,
29 roots: Vec<PathBuf>, 29 roots: Vec<PathBuf>,
30 config: Option<Box<dyn Fn(&mut ServerConfig)>>,
30} 31}
31 32
32impl<'a> Project<'a> { 33impl<'a> Project<'a> {
33 pub fn with_fixture(fixture: &str) -> Project { 34 pub fn with_fixture(fixture: &str) -> Project {
34 Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false } 35 Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false, config: None }
35 } 36 }
36 37
37 pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> { 38 pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> {
@@ -49,6 +50,11 @@ impl<'a> Project<'a> {
49 self 50 self
50 } 51 }
51 52
53 pub fn with_config(mut self, config: impl Fn(&mut ServerConfig) + 'static) -> Project<'a> {
54 self.config = Some(Box::new(config));
55 self
56 }
57
52 pub fn server(self) -> Server { 58 pub fn server(self) -> Server {
53 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); 59 let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap());
54 static INIT: Once = Once::new(); 60 static INIT: Once = Once::new();
@@ -72,7 +78,14 @@ impl<'a> Project<'a> {
72 78
73 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); 79 let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect();
74 80
75 Server::new(tmp_dir, self.with_sysroot, roots, paths) 81 let mut config =
82 ServerConfig { with_sysroot: self.with_sysroot, ..ServerConfig::default() };
83
84 if let Some(f) = &self.config {
85 f(&mut config)
86 }
87
88 Server::new(tmp_dir, config, roots, paths)
76 } 89 }
77} 90}
78 91
@@ -92,7 +105,7 @@ pub struct Server {
92impl Server { 105impl Server {
93 fn new( 106 fn new(
94 dir: TempDir, 107 dir: TempDir,
95 with_sysroot: bool, 108 config: ServerConfig,
96 roots: Vec<PathBuf>, 109 roots: Vec<PathBuf>,
97 files: Vec<(PathBuf, String)>, 110 files: Vec<(PathBuf, String)>,
98 ) -> Server { 111 ) -> Server {
@@ -118,7 +131,7 @@ impl Server {
118 window: None, 131 window: None,
119 experimental: None, 132 experimental: None,
120 }, 133 },
121 ServerConfig { with_sysroot, ..ServerConfig::default() }, 134 config,
122 connection, 135 connection,
123 ) 136 )
124 .unwrap() 137 .unwrap()