From bd37591a3238ad6dddcbe017af7b66f29294b270 Mon Sep 17 00:00:00 2001 From: Zac Brown Date: Mon, 9 Sep 2019 09:55:45 -0700 Subject: [PATCH 1/2] - Modify the version parsing code to support macOS Beta versions which don't include a patch version (e.g. 10.15). Signed-off-by: Zac Brown --- src/macos/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/macos/mod.rs b/src/macos/mod.rs index 615c1a3d..df6b3511 100644 --- a/src/macos/mod.rs +++ b/src/macos/mod.rs @@ -60,7 +60,7 @@ fn product_version() -> Option { fn parse(sw_vers_output: &str) -> Option { lazy_static! { - static ref VERSION: Regex = Regex::new(r"ProductVersion:\s(\w+\.\w+\.\w+)").unwrap(); + static ref VERSION: Regex = Regex::new(r"ProductVersion:\s(\w+\.\w+[\.\w]?)").unwrap(); } Some( @@ -129,4 +129,16 @@ mod tests { ProductVersion: 10.10.5\n\ BuildVersion: 14F27" } + + #[test] + fn parse_beta_version() { + let parse_output = parse(sw_vers_output_beta()); + assert_eq!(parse_output, Some("10.15".to_string())); + } + + fn sw_vers_output_beta() -> &'static str { + "ProductName: Mac OS X\n\ + ProductVersion: 10.15\n\ + BuildVersion: 19A546d" + } } From 3ae2ce9a403b0fcc356c68991e80a688ccc11417 Mon Sep 17 00:00:00 2001 From: Zac Brown Date: Mon, 9 Sep 2019 13:02:35 -0700 Subject: [PATCH 2/2] Fix regex to use capture group to better handle more variants of patch versions. Signed-off-by: Zac Brown --- src/macos/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/macos/mod.rs b/src/macos/mod.rs index df6b3511..c0b18f86 100644 --- a/src/macos/mod.rs +++ b/src/macos/mod.rs @@ -60,7 +60,7 @@ fn product_version() -> Option { fn parse(sw_vers_output: &str) -> Option { lazy_static! { - static ref VERSION: Regex = Regex::new(r"ProductVersion:\s(\w+\.\w+[\.\w]?)").unwrap(); + static ref VERSION: Regex = Regex::new(r"ProductVersion:\s(\w+\.\w+(\.\w+)?)").unwrap(); } Some( @@ -141,4 +141,16 @@ mod tests { ProductVersion: 10.15\n\ BuildVersion: 19A546d" } + + #[test] + fn parse_double_digit_patch_version() { + let parse_output = parse(sw_vers_output_double_digit_patch_version()); + assert_eq!(parse_output, Some("10.15.21".to_string())); + } + + fn sw_vers_output_double_digit_patch_version() -> &'static str { + "ProductName: Mac OS X\n\ + ProductVersion: 10.15.21\n\ + BuildVersion: ABCD123" + } }