use std::fs;
fn repo_file(relative_path: &str) -> Option<String> {
let path = format!("{}/../../{relative_path}", env!("CARGO_MANIFEST_DIR"));
fs::read_to_string(path).ok()
}
fn gradle_version() -> Option<String> {
let text = repo_file("gradle.properties")?;
text.lines().find_map(|l| {
l.trim()
.strip_prefix("version=")
.map(|v| v.trim().to_string())
})
}
#[test]
fn cargo_version_matches_gradle_properties() {
let Some(gradle) = gradle_version() else {
eprintln!("gradle.properties not reachable (published crate); nothing to cross-check");
return;
};
let cargo = env!("CARGO_PKG_VERSION");
assert_eq!(
cargo, gradle,
"\n\nCargo.toml version ({cargo}) does not match gradle.properties version ({gradle}).\n\
gradle.properties is the single source of truth; the committed Cargo.toml must be kept in\n\
lockstep, or the wrapper<->libmesmo version-skew check fails every Rust test with an\n\
unrelated-looking runtime error. Fix from the repository root:\n\n\
\x20 ./gradlew syncVersions\n\n\
and commit the resulting wrapper version updates.\n"
);
}
#[test]
fn build_rs_downloads_the_asset_that_release_yml_uploads() {
let Some(workflow) = repo_file(".github/workflows/release.yml") else {
eprintln!("release.yml not reachable (published crate); nothing to cross-check");
return;
};
let build_rs = fs::read_to_string(concat!(env!("CARGO_MANIFEST_DIR"), "/build.rs"))
.expect("build.rs sits beside Cargo.toml");
let asked_for = build_rs
.lines()
.find_map(|l| {
let rest = l.trim().strip_prefix(r#"let tarball = format!(""#)?;
rest.split_once("-{version}").map(|(prefix, _)| prefix)
})
.expect(
r#"build.rs names the tarball as `let tarball = format!("<prefix>-{version}-..")`"#,
);
let uploaded: Vec<&str> = workflow
.lines()
.filter_map(|l| l.trim().strip_prefix("tar czf "))
.filter_map(|rest| {
rest.split_once("-${{ github.ref_name }}")
.map(|(prefix, _)| prefix)
})
.collect();
assert!(
!uploaded.is_empty(),
"no `tar czf <prefix>-${{{{ github.ref_name }}}}-..` lines found in release.yml — if the \n\
release workflow changed how it names assets, update this test and build.rs together."
);
for uploaded_prefix in &uploaded {
assert_eq!(
&asked_for, uploaded_prefix,
"\n\nbuild.rs downloads `{asked_for}-<version>-<platform>.tar.gz`, but release.yml \n\
uploads `{uploaded_prefix}-<version>-<platform>.tar.gz`. Every published crate resolves \n\
its libmesmo through that URL, so a mismatch is a 404 on the consumer's first build.\n"
);
}
}