use std::path::{Path, PathBuf};
use std::process::Command;
fn repo_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR"))
.ancestors()
.nth(2)
.expect("repo root is two levels above crates/umbral-cli")
.to_path_buf()
}
#[test]
#[ignore = "type-checks an entire generated app (minutes, GBs). CI runs it; locally: --ignored"]
fn the_scaffolded_project_compiles_with_no_errors_and_no_warnings() {
let repo = repo_root();
assert!(
repo.join("crates/umbral-core/Cargo.toml").exists(),
"expected a source checkout at {}",
repo.display()
);
let tmp = tempfile::tempdir().expect("tempdir");
let report = umbral_cli::scaffold::scaffold_project("checkme", tmp.path(), Some(&repo))
.expect("scaffold_project");
let target_dir = repo.join("target/scaffold-check");
let out = Command::new(env!("CARGO"))
.current_dir(&report.root)
.args(["check", "--all-targets", "--message-format=short"])
.env("CARGO_TARGET_DIR", &target_dir)
.env("RUSTFLAGS", "-D warnings")
.output()
.expect("cargo check should be runnable");
let stderr = String::from_utf8_lossy(&out.stderr);
if !out.status.success() {
panic!(
"`umbral startproject` emitted a project that does not compile.\n\
This is the first thing a new user runs. Fix the SCAFFOLD, not the test.\n\n\
cargo check said:\n{stderr}"
);
}
let is_build_script_notice = |l: &str| {
l.starts_with("warning: ")
&& l[9..]
.split_once(": ")
.is_some_and(|(pkg, _)| pkg.contains('@'))
};
let warnings: Vec<&str> = stderr
.lines()
.filter(|l| l.starts_with("warning:") && !is_build_script_notice(l))
.collect();
assert!(
warnings.is_empty(),
"the scaffolded project compiles but is not clean:\n{}",
warnings.join("\n")
);
}