Skip to content

Commit

Permalink
Remove dev without commit hash
Browse files Browse the repository at this point in the history
  • Loading branch information
kl committed Nov 26, 2024
1 parent a151fdd commit 70f47f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
26 changes: 8 additions & 18 deletions mullvad-version/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl FromStr for Version {
(?: # (optional) alpha or beta or dev
-alpha(?<alpha>[1-9]\d?\d?)|
-beta(?<beta>[1-9]\d?\d?)|
-dev-(?<dev>[0-9a-f]+)|
(?<no_ver_dev>-dev)
-dev-(?<dev>[0-9a-f]+)
)?$
",
)
Expand All @@ -111,10 +110,7 @@ impl FromStr for Version {

let alpha = captures.name("alpha").map(|m| m.as_str());
let beta = captures.name("beta").map(|m| m.as_str());
let dev = captures
.name("dev")
.map(|m| m.as_str())
.or(captures.name("no_ver_dev").map(|_| ""));
let dev = captures.name("dev").map(|m| m.as_str());

let version_type = match (alpha, beta, dev) {
(None, None, None) => VersionType::Stable,
Expand Down Expand Up @@ -192,18 +188,6 @@ mod tests {
assert_eq!(parsed.is_stable(), false);
}

#[test]
fn test_parse_with_dev_no_version() {
let version = "2099.99-dev";
let parsed = Version::parse(version);
assert_eq!(parsed.year, "99");
assert_eq!(parsed.incremental, "99");
assert_eq!(parsed.alpha(), None);
assert_eq!(parsed.beta(), None);
assert_eq!(parsed.dev(), Some(""));
assert_eq!(parsed.is_stable(), false);
}

#[test]
#[should_panic]
fn test_panics_on_invalid_version() {
Expand All @@ -221,4 +205,10 @@ mod tests {
fn test_panics_on_alpha_and_beta_in_same_version() {
Version::parse("2021.1-beta5-alpha2");
}

#[test]
#[should_panic]
fn test_panics_on_dev_without_commit_hash() {
Version::parse("2021.1-dev");
}
}
10 changes: 6 additions & 4 deletions mullvad-version/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ fn to_android_version_code(version: &str) -> String {
)
}

/// On Windows we do not support alpha versions for now, so this function will panic
/// if the parsed version is an alpha version.
fn to_windows_h_format(version: &str) -> String {
let Version {
year,
Expand All @@ -77,9 +79,10 @@ fn to_windows_h_format(version: &str) -> String {
..
} = Version::parse(version);

if !is_valid_windows_version(&version_type) {
panic!("Invalid Windows version type: {version_type:?}");
}
assert!(
is_valid_windows_version(&version_type),
"Invalid Windows version type: {version_type:?}"
);

format!(
"#define MAJOR_VERSION 20{year}
Expand Down Expand Up @@ -117,7 +120,6 @@ mod tests {

#[test]
fn test_version_code_dev() {
assert_eq!("21349000", to_android_version_code("2021.34-dev"));
assert_eq!("21349000", to_android_version_code("2021.34-dev-be846a5f0"));
}

Expand Down

0 comments on commit 70f47f7

Please sign in to comment.