3793: Add integrated test for concat include env r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-03-31 17:19:37 +00:00 committed by GitHub
commit 37a01de42c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 5 deletions

View file

@ -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::<GotoDefinition>(TextDocumentPositionParams::new(
server.doc_id("src/main.rs"),
Position::new(2, 15),
));
assert!(format!("{}", res).contains("hello.rs"));
}

View file

@ -27,11 +27,12 @@ pub struct Project<'a> {
with_sysroot: bool,
tmp_dir: Option<TempDir>,
roots: Vec<PathBuf>,
config: Option<Box<dyn Fn(&mut ServerConfig)>>,
}
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<PathBuf>,
files: Vec<(PathBuf, String)>,
) -> Server {
@ -118,7 +131,7 @@ impl Server {
window: None,
experimental: None,
},
ServerConfig { with_sysroot, ..ServerConfig::default() },
config,
connection,
)
.unwrap()