Skip to content

Commit b1de91e

Browse files
committed
internal: add simple smoke test for project model
Our project model code is rather complicated -- the logic for lowering from `cargo metadata` to `CrateGraph` is fiddly and special-case. So far, we survived without testing this at all, but this increasingly seems like a poor option. So this PR introduces a simple tests just to detect the most obvious failures. The idea here is that, although we rely on external processes (cargo & rustc), we are actually using their stable interfaces, so we might just mock out the outputs. Long term, I would like to try to virtualize IO here, so as to do such mocking in a more principled way, but lets start simple. Should we forgo the mocking and just call `cargo metadata` directly perhaps? Touch question -- I personally feel that fast, in-process tests are more important in this case than any extra assurance we get from running the real thing. Super-long term, we would probably want to extend our heavy tests to cover more use-cases, but we should figure a way to do that without slowing the tests down for everyone. Perhaps we need two-tiered bors system, where we pull from `master` into `release` branch only when an additional set of tests passes?
1 parent 2211d2c commit b1de91e

File tree

6 files changed

+777
-1
lines changed

6 files changed

+777
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cfg/src/lib.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,26 @@ pub use dnf::DnfExpr;
2323
/// of key and value in `key_values`.
2424
///
2525
/// See: <https://doc.rust-lang.org/reference/conditional-compilation.html#set-configuration-options>
26-
#[derive(Debug, Clone, PartialEq, Eq, Default)]
26+
#[derive(Clone, PartialEq, Eq, Default)]
2727
pub struct CfgOptions {
2828
enabled: FxHashSet<CfgAtom>,
2929
}
3030

31+
impl fmt::Debug for CfgOptions {
32+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33+
let mut items = self
34+
.enabled
35+
.iter()
36+
.map(|atom| match atom {
37+
CfgAtom::Flag(it) => it.to_string(),
38+
CfgAtom::KeyValue { key, value } => format!("{}={}", key, value),
39+
})
40+
.collect::<Vec<_>>();
41+
items.sort();
42+
f.debug_tuple("CfgOptions").field(&items).finish()
43+
}
44+
}
45+
3146
impl CfgOptions {
3247
pub fn check(&self, cfg: &CfgExpr) -> Option<bool> {
3348
cfg.fold(&|atom| self.enabled.contains(atom))

crates/project_model/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ semver = "1"
1616
serde = { version = "1.0.106", features = ["derive"] }
1717
serde_json = "1.0.48"
1818
anyhow = "1.0.26"
19+
expect-test = "1"
1920
la-arena = { version = "0.2.0", path = "../../lib/arena" }
2021

2122
cfg = { path = "../cfg", version = "0.0.0" }

crates/project_model/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ mod workspace;
2424
mod rustc_cfg;
2525
mod build_scripts;
2626

27+
#[cfg(test)]
28+
mod tests;
29+
2730
use std::{
2831
convert::{TryFrom, TryInto},
2932
fs::{self, read_dir, ReadDir},

0 commit comments

Comments
 (0)