mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-25 19:35:06 +00:00
Add some smoke tests to toolchain_info
This commit is contained in:
parent
b8a0488740
commit
59c8e27acc
5 changed files with 129 additions and 23 deletions
|
@ -96,3 +96,29 @@ fn rustc_print_cfg(
|
|||
|
||||
utf8_stdout(&mut cmd).with_context(|| format!("unable to fetch cfgs via `{cmd:?}`"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use paths::{AbsPathBuf, Utf8PathBuf};
|
||||
|
||||
use crate::{ManifestPath, Sysroot};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cargo() {
|
||||
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
|
||||
let sysroot = Sysroot::empty();
|
||||
let manifest_path =
|
||||
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
|
||||
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
|
||||
assert_ne!(get(cfg, None, &FxHashMap::default()), vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rustc() {
|
||||
let sysroot = Sysroot::empty();
|
||||
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
|
||||
assert_ne!(get(cfg, None, &FxHashMap::default()), vec![]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,3 +55,29 @@ pub fn get(
|
|||
.with_context(|| format!("unable to fetch target-data-layout via `{cmd:?}`"))
|
||||
.and_then(process)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use paths::{AbsPathBuf, Utf8PathBuf};
|
||||
|
||||
use crate::{ManifestPath, Sysroot};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cargo() {
|
||||
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
|
||||
let sysroot = Sysroot::empty();
|
||||
let manifest_path =
|
||||
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
|
||||
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
|
||||
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rustc() {
|
||||
let sysroot = Sysroot::empty();
|
||||
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
|
||||
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,3 +77,29 @@ fn parse_output_cargo_config_build_target(stdout: String) -> anyhow::Result<Vec<
|
|||
|
||||
serde_json::from_str(trimmed).context("Failed to parse `build.target` as an array of target")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use paths::{AbsPathBuf, Utf8PathBuf};
|
||||
|
||||
use crate::{ManifestPath, Sysroot};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cargo() {
|
||||
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
|
||||
let sysroot = Sysroot::empty();
|
||||
let manifest_path =
|
||||
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
|
||||
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
|
||||
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rustc() {
|
||||
let sysroot = Sysroot::empty();
|
||||
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
|
||||
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,3 +30,29 @@ pub(crate) fn get(
|
|||
}
|
||||
anyhow::Ok(version)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use paths::{AbsPathBuf, Utf8PathBuf};
|
||||
|
||||
use crate::{ManifestPath, Sysroot};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn cargo() {
|
||||
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
|
||||
let sysroot = Sysroot::empty();
|
||||
let manifest_path =
|
||||
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
|
||||
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
|
||||
assert!(get(cfg, &FxHashMap::default()).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rustc() {
|
||||
let sysroot = Sysroot::empty();
|
||||
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
|
||||
assert!(get(cfg, &FxHashMap::default()).is_ok());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,27 +245,10 @@ impl ProjectWorkspace {
|
|||
if let Err(e) = &data_layout {
|
||||
tracing::error!(%e, "failed fetching data layout for {cargo_toml:?} workspace");
|
||||
}
|
||||
sysroot.load_workspace(&SysrootSourceWorkspaceConfig::CargoMetadata(
|
||||
sysroot_metadata_config(&config.extra_env, &targets),
|
||||
));
|
||||
|
||||
let (meta, error) = CargoWorkspace::fetch_metadata(
|
||||
cargo_toml,
|
||||
cargo_toml.parent(),
|
||||
&CargoMetadataConfig {
|
||||
features: config.features.clone(),
|
||||
targets: targets.clone(),
|
||||
extra_args: config.extra_args.clone(),
|
||||
extra_env: config.extra_env.clone(),
|
||||
},
|
||||
&sysroot,
|
||||
false,
|
||||
progress,
|
||||
)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to read Cargo metadata from Cargo.toml file {cargo_toml}, {toolchain:?}",
|
||||
)
|
||||
})?;
|
||||
let cargo_config_extra_env = cargo_config_env(cargo_toml, &config.extra_env, &sysroot);
|
||||
let cargo = CargoWorkspace::new(meta, cargo_toml.clone(), cargo_config_extra_env);
|
||||
let rustc = rustc_dir.and_then(|rustc_dir| {
|
||||
info!(workspace = %cargo_toml, rustc_dir = %rustc_dir, "Using rustc source");
|
||||
match CargoWorkspace::fetch_metadata(
|
||||
|
@ -302,9 +285,28 @@ impl ProjectWorkspace {
|
|||
}
|
||||
}
|
||||
});
|
||||
sysroot.load_workspace(&SysrootSourceWorkspaceConfig::CargoMetadata(
|
||||
sysroot_metadata_config(&config.extra_env, &targets),
|
||||
));
|
||||
|
||||
let (meta, error) = CargoWorkspace::fetch_metadata(
|
||||
cargo_toml,
|
||||
cargo_toml.parent(),
|
||||
&CargoMetadataConfig {
|
||||
features: config.features.clone(),
|
||||
targets,
|
||||
extra_args: config.extra_args.clone(),
|
||||
extra_env: config.extra_env.clone(),
|
||||
},
|
||||
&sysroot,
|
||||
false,
|
||||
progress,
|
||||
)
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Failed to read Cargo metadata from Cargo.toml file {cargo_toml}, {toolchain:?}",
|
||||
)
|
||||
})?;
|
||||
let cargo_config_extra_env = cargo_config_env(cargo_toml, &config.extra_env, &sysroot);
|
||||
let cargo = CargoWorkspace::new(meta, cargo_toml.clone(), cargo_config_extra_env);
|
||||
|
||||
Ok(ProjectWorkspace {
|
||||
kind: ProjectWorkspaceKind::Cargo {
|
||||
cargo,
|
||||
|
|
Loading…
Reference in a new issue