Make version regex for python and gradle more concrete
Check that "version" is the start of the string to avoid changing cases like "kotlin_version = ..."
This commit is contained in:
parent
215a9bf0fe
commit
5053b79ad4
2 changed files with 29 additions and 3 deletions
|
@ -48,9 +48,9 @@ class BuildFile(Validateable):
|
|||
def __get_file_type_regex_str(self, file_type: BuildFileType):
|
||||
match file_type:
|
||||
case BuildFileType.JAVA_GRADLE:
|
||||
return r'(?P<pre_version>version\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
return r'(?P<pre_version>\bversion\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
case BuildFileType.PYTHON:
|
||||
return r'(?P<pre_version>version\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"'
|
||||
return r'(?P<pre_version>\bversion\s?=\s?)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"'
|
||||
case BuildFileType.JAVA_CLOJURE:
|
||||
return r'(?P<pre_version>\(defproject\s(\S)*\s)\"(?P<version>\d*\.\d*\.\d*(-SNAPSHOT)?)\"'
|
||||
case _:
|
||||
|
|
|
@ -196,3 +196,29 @@ def test_should_throw_for_clj_wrong_version():
|
|||
|
||||
with pytest.raises(RuntimeError):
|
||||
sut.get_version()
|
||||
|
||||
def test_should_ignore_first_version_for_py():
|
||||
sut = BuildFile(
|
||||
Path("./build.py"),
|
||||
"""
|
||||
from pybuilder.core import init, use_plugin, Author
|
||||
use_plugin("python.core")
|
||||
|
||||
name = "ddadevops"
|
||||
project_version = "0.0.2-dev1"
|
||||
version = "1.1.5-dev12"
|
||||
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
|
||||
""",
|
||||
)
|
||||
assert sut.get_version() == Version.from_str("1.1.5-dev12", "dev")
|
||||
|
||||
def test_should_ignore_first_version_for_gradle():
|
||||
sut = BuildFile(
|
||||
Path("./build.gradle"),
|
||||
"""
|
||||
kotlin_version = "3.3.3"
|
||||
version = "1.1.5-SNAPSHOT"
|
||||
|
||||
""",
|
||||
)
|
||||
assert sut.get_version() == Version.from_str("1.1.5-SNAPSHOT", "SNAPSHOT")
|
Loading…
Reference in a new issue