diff --git a/Cargo.lock b/Cargo.lock index 340ea3294..bca31b1f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3689,6 +3689,7 @@ name = "lighthouse_version" version = "0.1.0" dependencies = [ "git-version", + "regex", "target_info", ] diff --git a/common/lighthouse_version/Cargo.toml b/common/lighthouse_version/Cargo.toml index a9778787a..7da51ea11 100644 --- a/common/lighthouse_version/Cargo.toml +++ b/common/lighthouse_version/Cargo.toml @@ -9,3 +9,6 @@ edition = "2018" [dependencies] git-version = "0.3.4" target_info = "0.1.0" + +[dev-dependencies] +regex = "1" diff --git a/common/lighthouse_version/src/lib.rs b/common/lighthouse_version/src/lib.rs index 7f9d58d05..54b28bec7 100644 --- a/common/lighthouse_version/src/lib.rs +++ b/common/lighthouse_version/src/lib.rs @@ -9,7 +9,7 @@ use target_info::Target; /// /// `Lighthouse/v0.2.0-1419501f2+` pub const VERSION: &str = git_version!( - args = ["--always", "--dirty=+", "--abbrev=7"], + args = ["--always", "--dirty=+", "--abbrev=7", "--exclude=*"], prefix = "Lighthouse/v1.1.3-", fallback = "unknown" ); @@ -22,3 +22,16 @@ pub const VERSION: &str = git_version!( pub fn version_with_platform() -> String { format!("{}/{}-{}", VERSION, Target::arch(), Target::os()) } + +#[cfg(test)] +mod test { + use super::*; + use regex::Regex; + + #[test] + fn version_formatting() { + let re = Regex::new(r"^Lighthouse/v[0-9]+\.[0-9]+\.[0-9]+(-rc.[0-9])?-[[:xdigit:]]{7}\+?$") + .unwrap(); + assert!(re.is_match(VERSION), VERSION); + } +}