pub const VERSION: &str = env!("QEX_BUILD_VERSION");
pub fn is_development(version: &str) -> bool {
let version = version.trim();
version == DEVELOPMENT || version.starts_with(concat!("0.0.0-dev", "+"))
}
pub const DEVELOPMENT: &str = "0.0.0-dev";
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_release_is_not_a_development_build() {
assert!(!is_development("0.7.3"));
assert!(!is_development("1.0.0"));
assert!(!is_development("0.7.3+g98513e2"));
}
#[test]
fn the_forms_that_build_rs_writes_are_development_builds() {
assert!(is_development("0.0.0-dev"));
assert!(is_development("0.0.0-dev+g98513e2"));
assert!(is_development("0.0.0-dev+g98513e2.dirty"));
assert!(is_development("0.0.0-dev+unknown"));
}
#[test]
fn text_that_is_not_a_version_is_not_a_development_build() {
assert!(!is_development(""));
assert!(!is_development("not-a-version"));
assert!(!is_development("-dev"));
assert!(!is_development("0.0-dev"), "a version has three numbers");
assert!(
!is_development("0.0.0.0-dev"),
"a version has three numbers"
);
assert!(!is_development("0.0.x-dev"));
assert!(!is_development("0.7.3-rc1"), "a candidate is not a build");
assert!(!is_development("0.7.3-alpha-5"), "qex writes no alpha");
}
#[test]
fn a_word_that_starts_with_dev_is_not_a_development_build() {
assert!(!is_development("0.0.0-devil"));
assert!(!is_development("0.0.0-development"));
assert!(!is_development("0.0.0-devel"));
assert!(!is_development("0.0.0-dev.1"), "qex writes no such form");
assert!(!is_development("0.0.0-dev-1"), "qex writes no such form");
assert!(!is_development("0.1.0-dev"));
assert!(!is_development("1.0.0-dev"));
}
#[test]
fn cargo_toml_holds_this_development_version_or_a_release() {
assert!(
is_development(DEVELOPMENT),
"the constant must name a development build"
);
let cargo: toml::Value =
toml::from_str(include_str!("../Cargo.toml")).expect("Cargo.toml must be TOML");
let found = cargo
.get("package")
.and_then(|p| p.get("version"))
.and_then(|v| v.as_str())
.expect("Cargo.toml must hold `[package] version`");
let release = found.split('.').count() == 3
&& found
.split('.')
.all(|p| !p.is_empty() && p.bytes().all(|b| b.is_ascii_digit()));
assert!(
found == DEVELOPMENT || release,
"Cargo.toml holds `{found}`. It must hold `{DEVELOPMENT}`, which is what \
`main` holds, or three numbers, which is what the commit that a tag names \
holds. Any other text gives a build that qex refuses in place of warning \
about it."
);
}
#[test]
fn this_build_names_itself() {
assert!(!VERSION.is_empty(), "a build must report a version");
}
}