#![allow(
dead_code,
reason = "shared integration-test fixtures; not every test binary uses every item"
)]
use assert_fs::TempDir;
use assert_fs::prelude::*;
use cargo_feature_combinations::CfgEvaluator;
use cargo_feature_combinations::target::{TargetEnvironment, TargetTriple};
use color_eyre::eyre;
pub struct HostEnv(pub &'static str);
impl TargetEnvironment for HostEnv {
fn cargo_build_target(&self) -> Option<String> {
None
}
fn host_target(&self) -> eyre::Result<TargetTriple> {
Ok(TargetTriple(self.0.to_string()))
}
}
#[derive(Default)]
pub struct PairEval {
rules: Vec<(String, String)>,
}
impl PairEval {
pub fn matching(triple: &str, cfg: &str) -> Self {
Self {
rules: vec![(triple.to_string(), cfg.to_string())],
}
}
}
impl CfgEvaluator for PairEval {
fn matches(&mut self, cfg_expr: &str, target: &TargetTriple) -> eyre::Result<bool> {
Ok(self
.rules
.iter()
.any(|(t, c)| t == target.as_str() && c == cfg_expr))
}
}
pub fn single_crate(cargo_toml: &str) -> eyre::Result<TempDir> {
let temp = TempDir::new()?;
temp.child("Cargo.toml").write_str(cargo_toml)?;
temp.child("src/lib.rs").write_str("pub fn x() {}\n")?;
Ok(temp)
}
pub fn metadata(temp: &TempDir) -> eyre::Result<cargo_metadata::Metadata> {
Ok(cargo_metadata::MetadataCommand::new()
.current_dir(temp.path())
.no_deps()
.exec()?)
}