summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDario Vladović <d.vladimyr@gmail.com>2021-04-15 08:48:12 +0200
committerGitHub <noreply@github.com>2021-04-15 08:48:12 +0200
commit51c2ae0a28356301a68a2027c201592c84bd39d2 (patch)
treef7de0512e06a1db42da7f22d387f1b5912522786
parentf765ca3b3f616ead7b10f2410b4f6ee658c05489 (diff)
fix(elixir): correctly parse dev and rc versions (#2573)
-rw-r--r--src/modules/elixir.rs48
1 files changed, 31 insertions, 17 deletions
diff --git a/src/modules/elixir.rs b/src/modules/elixir.rs
index 8d823655e..fa642c085 100644
--- a/src/modules/elixir.rs
+++ b/src/modules/elixir.rs
@@ -4,12 +4,7 @@ use crate::configs::elixir::ElixirConfig;
use crate::formatter::StringFormatter;
use once_cell::sync::Lazy;
-use regex::Regex;
use std::ops::Deref;
-const ELIXIR_VERSION_PATTERN: &str = "\
-Erlang/OTP (?P<otp>\\d+)[^\\n]+
-
-Elixir (?P<elixir>\\d[.\\d]+).*";
/// Create a module with the current Elixir version
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
@@ -73,13 +68,15 @@ fn get_elixir_version(context: &Context) -> Option<(String, String)> {
}
fn parse_elixir_version(version: &str) -> Option<(String, String)> {
- let version_regex = Regex::new(ELIXIR_VERSION_PATTERN).ok()?;
- let captures = version_regex.captures(version)?;
-
- let otp_version = captures["otp"].to_owned();
- let elixir_version = captures["elixir"].to_owned();
-
- Some((otp_version, elixir_version))
+ let mut lines = version.lines();
+ // split line into ["Erlang/OTP", "22", "[erts-10.5]", ...], take "22"
+ let otp_version = lines.next()?.split_whitespace().nth(1)?;
+ // skip empty line
+ let _ = lines.next()?;
+ // split line into ["Elixir", "1.10", "(compiled", ...], take "1.10"
+ let elixir_version = lines.next()?.split_whitespace().nth(1)?;
+
+ Some((otp_version.to_string(), elixir_version.to_string()))
}
#[cfg(test)]
@@ -92,15 +89,32 @@ mod tests {
#[test]
fn test_parse_elixir_version() {
- const OUTPUT: &str = "\
-Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
+ let stable_input = "\
+Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]
+
+Elixir 1.11.3 (compiled with Erlang/OTP 21)
+";
+ let rc_input = "\
+Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]
-Elixir 1.10 (compiled with Erlang/OTP 22)
+Elixir 1.12.0-rc.0 (31d2b99) (compiled with Erlang/OTP 21)
";
+ let dev_input = "\
+Erlang/OTP 23 [erts-11.1.7] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
+Elixir 1.13.0-dev (compiled with Erlang/OTP 23)
+";
+ assert_eq!(
+ parse_elixir_version(stable_input),
+ Some(("23".to_string(), "1.11.3".to_string()))
+ );
+ assert_eq!(
+ parse_elixir_version(rc_input),
+ Some(("23".to_string(), "1.12.0-rc.0".to_string()))
+ );
assert_eq!(
- parse_elixir_version(OUTPUT),
- Some(("22".to_owned(), "1.10".to_owned()))
+ parse_elixir_version(dev_input),
+ Some(("23".to_string(), "1.13.0-dev".to_string()))
);
}