Skip to content

Commit

Permalink
project: output version value with error message (#4284)
Browse files Browse the repository at this point in the history
on version error output the erroneous version
along with error message mentioning the versioning
convention already being output

Co-authored-by: Sergio Schvezov <[email protected]>
  • Loading branch information
aritra24 and sergiusens authored Aug 17, 2023
1 parent d25b49d commit 9d99aa1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
8 changes: 4 additions & 4 deletions snapcraft/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,10 +549,10 @@ def _validate_version(cls, version, values):
r"^[a-zA-Z0-9](?:[a-zA-Z0-9:.+~-]*[a-zA-Z0-9+~])?$", version
):
raise ValueError(
"Snap versions consist of upper- and lower-case alphanumeric characters, "
"as well as periods, colons, plus signs, tildes, and hyphens. They cannot "
"begin with a period, colon, plus sign, tilde, or hyphen. They cannot end "
"with a period, colon, or hyphen"
f"Invalid version '{version}': Snap versions consist of upper- and lower-case "
"alphanumeric characters, as well as periods, colons, plus signs, tildes, "
"and hyphens. They cannot begin with a period, colon, plus sign, tilde, or "
"hyphen. They cannot end with a period, colon, or hyphen"
)

return version
Expand Down
51 changes: 41 additions & 10 deletions tests/unit/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,47 @@ def test_project_version_valid(self, version, project_yaml_data):
@pytest.mark.parametrize(
"version,error",
[
("1_0", "Snap versions consist of"), # _ is an invalid character
("1=1", "Snap versions consist of"), # = is an invalid character
(".1", "Snap versions consist of"), # cannot start with period
(":1", "Snap versions consist of"), # cannot start with colon
("+1", "Snap versions consist of"), # cannot start with plus sign
("~1", "Snap versions consist of"), # cannot start with tilde
("-1", "Snap versions consist of"), # cannot start with hyphen
("1.", "Snap versions consist of"), # cannot end with period
("1:", "Snap versions consist of"), # cannot end with colon
("1-", "Snap versions consist of"), # cannot end with hyphen
(
"1_0",
"Invalid version '1_0': Snap versions consist of",
), # _ is an invalid character
(
"1=1",
"Invalid version '1=1': Snap versions consist of",
), # = is an invalid character
(
".1",
"Invalid version '.1': Snap versions consist of",
), # cannot start with period
(
":1",
"Invalid version ':1': Snap versions consist of",
), # cannot start with colon
(
"+1",
r"Invalid version '\+1': Snap versions consist of",
), # cannot start with plus sign
# escaping + from the regex string to match.
(
"~1",
"Invalid version '~1': Snap versions consist of",
), # cannot start with tilde
(
"-1",
"Invalid version '-1': Snap versions consist of",
), # cannot start with hyphen
(
"1.",
"Invalid version '1.': Snap versions consist of",
), # cannot end with period
(
"1:",
"Invalid version '1:': Snap versions consist of",
), # cannot end with colon
(
"1-",
"Invalid version '1-': Snap versions consist of",
), # cannot end with hyphen
(
"123456789012345678901234567890123",
"ensure this value has at most 32 characters",
Expand Down

0 comments on commit 9d99aa1

Please sign in to comment.