From a4f9d966f015010e435d6a73360809a884c7415b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Mar 2020 19:16:25 +0200 Subject: Add integrated test for concat include env --- crates/rust-analyzer/tests/heavy_tests/main.rs | 46 ++++++++++++++++++++++- crates/rust-analyzer/tests/heavy_tests/support.rs | 21 +++++++++-- 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::{ }; use rust_analyzer::req::{ CodeActionParams, CodeActionRequest, Completion, CompletionParams, DidOpenTextDocument, - Formatting, OnEnter, Runnables, RunnablesParams, + Formatting, GotoDefinition, OnEnter, Runnables, RunnablesParams, }; use serde_json::json; use tempfile::TempDir; @@ -581,3 +581,47 @@ version = \"0.0.0\" }), ); } + +#[test] +fn resolve_include_concat_env() { + if skip_slow_tests() { + return; + } + + let server = Project::with_fixture( + r###" +//- Cargo.toml +[package] +name = "foo" +version = "0.0.0" + +//- build.rs +use std::{env, fs, path::Path}; + +fn main() { + let out_dir = env::var_os("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("hello.rs"); + fs::write( + &dest_path, + r#"pub fn message() -> &'static str { "Hello, World!" }"#, + ) + .unwrap(); + println!("cargo:rerun-if-changed=build.rs"); +} +//- src/main.rs +include!(concat!(env!("OUT_DIR"), "/hello.rs")); + +fn main() { message(); } +"###, + ) + .with_config(|config| { + config.cargo_features.load_out_dirs_from_check = true; + }) + .server(); + server.wait_until_workspace_is_loaded(); + let res = server.send_request::(TextDocumentPositionParams::new( + server.doc_id("src/main.rs"), + Position::new(2, 15), + )); + assert!(format!("{}", res).contains("hello.rs")); +} 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> { with_sysroot: bool, tmp_dir: Option, roots: Vec, + config: Option>, } impl<'a> Project<'a> { pub fn with_fixture(fixture: &str) -> Project { - Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false } + Project { fixture, tmp_dir: None, roots: vec![], with_sysroot: false, config: None } } pub fn tmp_dir(mut self, tmp_dir: TempDir) -> Project<'a> { @@ -49,6 +50,11 @@ impl<'a> Project<'a> { self } + pub fn with_config(mut self, config: impl Fn(&mut ServerConfig) + 'static) -> Project<'a> { + self.config = Some(Box::new(config)); + self + } + pub fn server(self) -> Server { let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); static INIT: Once = Once::new(); @@ -72,7 +78,14 @@ impl<'a> Project<'a> { let roots = self.roots.into_iter().map(|root| tmp_dir.path().join(root)).collect(); - Server::new(tmp_dir, self.with_sysroot, roots, paths) + let mut config = + ServerConfig { with_sysroot: self.with_sysroot, ..ServerConfig::default() }; + + if let Some(f) = &self.config { + f(&mut config) + } + + Server::new(tmp_dir, config, roots, paths) } } @@ -92,7 +105,7 @@ pub struct Server { impl Server { fn new( dir: TempDir, - with_sysroot: bool, + config: ServerConfig, roots: Vec, files: Vec<(PathBuf, String)>, ) -> Server { @@ -118,7 +131,7 @@ impl Server { window: None, experimental: None, }, - ServerConfig { with_sysroot, ..ServerConfig::default() }, + config, connection, ) .unwrap() -- cgit v1.2.3