From 8f46dff9dcae01f38057b25c939f0fb92c13c7b4 Mon Sep 17 00:00:00 2001 From: "Bao, Huang-Huang" Date: Fri, 12 Mar 2021 22:30:25 +0800 Subject: [PATCH] fix(package): fix meson version extraction if 'meson_version' is present (#2397) --- src/modules/package.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/package.rs b/src/modules/package.rs index 14e7f38d..909998d7 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -165,7 +165,7 @@ fn extract_maven_version(file_contents: &str) -> Option { fn extract_meson_version(file_contents: &str) -> Option { let file_contents = file_contents.split_ascii_whitespace().collect::(); - let re = Regex::new(r#"project\([^())]*version:'(?P[^']+)'[^())]*\)"#).unwrap(); + let re = Regex::new(r#"project\([^())]*,version:'(?P[^']+)'[^())]*\)"#).unwrap(); let caps = re.captures(&file_contents)?; let formatted_version = format_version(&caps["version"]); @@ -756,6 +756,18 @@ end"; project_dir.close() } + #[test] + fn test_extract_meson_version_with_meson_version() -> io::Result<()> { + let config_name = "meson.build"; + let config_content = + "project('starship', 'rust', version: '0.1.0', meson_version: '>= 0.57.0')".to_string(); + + let project_dir = create_project_dir()?; + fill_config(&project_dir, config_name, Some(&config_content))?; + expect_output(&project_dir, Some("v0.1.0"), None); + project_dir.close() + } + fn create_project_dir() -> io::Result { tempfile::tempdir() }