Skip to content

Commit

Permalink
Change: Loosen the version regex for go projects
Browse files Browse the repository at this point in the history
Verifying the version information should not be done via a regexp. If
the version information is valid depends on the versioning schema which
might by dynamic in the future. Therefore just parse the version string.
  • Loading branch information
bjoernricks committed Mar 3, 2023
1 parent ad748f2 commit aa554de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pontos/version/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .helper import get_last_release_version
from .version import Version, VersionCommand, VersionUpdate, parse_version

VERSION_MATCH = r'var [Vv]ersion = "([abcderv0-9.+]+)"'
VERSION_MATCH = r'var [Vv]ersion = "(.+)"'
TEMPLATE = """package main
// THIS IS AN AUTOGENERATED FILE. DO NOT TOUCH!
Expand Down
11 changes: 11 additions & 0 deletions tests/version/test_go_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def test_no_version_file(self):
):
GoVersionCommand().get_current_version()

def test_invalid_version(self):
with temp_file(
name="go.mod",
change_into=True,
), self.assertRaisesRegex(VersionError, "^Invalid version: 'abc'"):
version_file_path = Path(VERSION_FILE_PATH)
version_file_path.write_text(
TEMPLATE.format("main", "abc"), encoding="utf-8"
)
GoVersionCommand().get_current_version()


class VerifyGoVersionCommandTestCase(unittest.TestCase):
def test_verify_version(self):
Expand Down

0 comments on commit aa554de

Please sign in to comment.