Skip to content

Commit a0a650a

Browse files
committed
Add some smoke tests to toolchain_info
1 parent 92ef331 commit a0a650a

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

crates/project-model/src/toolchain_info/rustc_cfg.rs

+26
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,29 @@ fn rustc_print_cfg(
9696

9797
utf8_stdout(&mut cmd).with_context(|| format!("unable to fetch cfgs via `{cmd:?}`"))
9898
}
99+
100+
#[cfg(test)]
101+
mod tests {
102+
use paths::{AbsPathBuf, Utf8PathBuf};
103+
104+
use crate::{ManifestPath, Sysroot};
105+
106+
use super::*;
107+
108+
#[test]
109+
fn cargo() {
110+
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
111+
let sysroot = Sysroot::empty();
112+
let manifest_path =
113+
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
114+
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
115+
assert_ne!(get(cfg, None, &FxHashMap::default()), vec![]);
116+
}
117+
118+
#[test]
119+
fn rustc() {
120+
let sysroot = Sysroot::empty();
121+
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
122+
assert_ne!(get(cfg, None, &FxHashMap::default()), vec![]);
123+
}
124+
}

crates/project-model/src/toolchain_info/target_data_layout.rs

+26
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,29 @@ pub fn get(
5555
.with_context(|| format!("unable to fetch target-data-layout via `{cmd:?}`"))
5656
.and_then(process)
5757
}
58+
59+
#[cfg(test)]
60+
mod tests {
61+
use paths::{AbsPathBuf, Utf8PathBuf};
62+
63+
use crate::{ManifestPath, Sysroot};
64+
65+
use super::*;
66+
67+
#[test]
68+
fn cargo() {
69+
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
70+
let sysroot = Sysroot::empty();
71+
let manifest_path =
72+
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
73+
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
74+
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
75+
}
76+
77+
#[test]
78+
fn rustc() {
79+
let sysroot = Sysroot::empty();
80+
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
81+
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
82+
}
83+
}

crates/project-model/src/toolchain_info/target_tuple.rs

+26
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,29 @@ fn parse_output_cargo_config_build_target(stdout: String) -> anyhow::Result<Vec<
7777

7878
serde_json::from_str(trimmed).context("Failed to parse `build.target` as an array of target")
7979
}
80+
81+
#[cfg(test)]
82+
mod tests {
83+
use paths::{AbsPathBuf, Utf8PathBuf};
84+
85+
use crate::{ManifestPath, Sysroot};
86+
87+
use super::*;
88+
89+
#[test]
90+
fn cargo() {
91+
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
92+
let sysroot = Sysroot::empty();
93+
let manifest_path =
94+
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
95+
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
96+
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
97+
}
98+
99+
#[test]
100+
fn rustc() {
101+
let sysroot = Sysroot::empty();
102+
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
103+
assert!(get(cfg, None, &FxHashMap::default()).is_ok());
104+
}
105+
}

crates/project-model/src/toolchain_info/version.rs

+26
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,29 @@ pub(crate) fn get(
3030
}
3131
anyhow::Ok(version)
3232
}
33+
34+
#[cfg(test)]
35+
mod tests {
36+
use paths::{AbsPathBuf, Utf8PathBuf};
37+
38+
use crate::{ManifestPath, Sysroot};
39+
40+
use super::*;
41+
42+
#[test]
43+
fn cargo() {
44+
let manifest_path = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
45+
let sysroot = Sysroot::empty();
46+
let manifest_path =
47+
ManifestPath::try_from(AbsPathBuf::assert(Utf8PathBuf::from(manifest_path))).unwrap();
48+
let cfg = QueryConfig::Cargo(&sysroot, &manifest_path);
49+
assert!(get(cfg, &FxHashMap::default()).is_ok());
50+
}
51+
52+
#[test]
53+
fn rustc() {
54+
let sysroot = Sysroot::empty();
55+
let cfg = QueryConfig::Rustc(&sysroot, env!("CARGO_MANIFEST_DIR").as_ref());
56+
assert!(get(cfg, &FxHashMap::default()).is_ok());
57+
}
58+
}

0 commit comments

Comments
 (0)