Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow dots in identifiers #1267

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/alire/alire-crates.adb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package body Alire.Crates is
(AAA.Strings.Empty_Vector
.Append ("Identifiers for crates and indexes must use "
& "lowercase alphanumeric characters from the latin "
& "alphabet. Underscores can also be used except as "
& "the first character.")
& "alphabet. Underscores and dots can also be used, "
& "except as the first character.")
.New_Line
.Append ("Length must be of" & Alire.Min_Name_Length'Img
& " to" & Alire.Max_Name_Length'Img
Expand Down
2 changes: 2 additions & 0 deletions src/alire/alire.adb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ package body Alire is
Err := +"Identifier too long.";
elsif S (S'First) = '_' then
Err := +"Identifiers must not begin with an underscore.";
elsif S (S'First) = Extension_Separator then
Err := +"Identifiers must not begin with a dot.";
elsif (for some C of S => C not in Crate_Character) then
Err := +"Identifiers must be lowercase ASCII alphanumerical.";
end if;
Expand Down
2 changes: 1 addition & 1 deletion testsuite/drivers/alr.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def run_alr(*args, **kwargs):
if (p.status != 0 and complain_on_error) or (p.status == 0 and not complain_on_error):
print('The following command:')
print(' {}'.format(' '.join(quote_arg(arg) for arg in argv)))
print('Exitted with status code {}'.format(p.status))
print('Exited with status code {}'.format(p.status))
print('Output:')
print(p.out)
if complain_on_error:
Expand Down
24 changes: 19 additions & 5 deletions testsuite/tests/index/bad-name/test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
"""
'''
Check that specifying a malformed index name is properly reported
"""
'''

from drivers.alr import run_alr
from drivers.asserts import assert_match

def assert_that(name, fails_with):
p = run_alr('index', '--add', name, '--name', name, complain_on_error=False, debug=False)
assert_match(fails_with, p.out)

p = run_alr('index', '--add', 'xx', '--name', 'xx',
complain_on_error=False, debug=False)
assert_match('.*Identifier too short.*', p.out)
# < min length
assert_that(name='aa', fails_with='.*Identifier too short.*')

# > max length
assert_that(name='a' * 65, fails_with='.*Identifier too long.*')

# Leading underscore
assert_that(name='_aaa', fails_with='.*Identifiers must not begin with an underscore.*')

# Leading dot
assert_that(name='.aaa', fails_with='.*Identifiers must not begin with a dot.*')

# Non lowercase ASCII alnum
assert_that(name='aaą', fails_with='.*Identifiers must be lowercase ASCII alphanumerical.*')

print('SUCCESS')
37 changes: 37 additions & 0 deletions testsuite/tests/init/crate-name-validation/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'''
Check that the crate name is validated properly
'''

import string

from drivers.alr import run_alr
from drivers.asserts import assert_match

CRATE_TYPES = ['bin', 'lib']
VALID_NAME = f"{string.ascii_lowercase}_{string.digits}."

def assert_that(name, fails_with):
for crate_type in CRATE_TYPES:
p = run_alr('init', f"--{crate_type}", name, complain_on_error=False)
assert_match(fails_with, p.out)

# < min length
assert_that(name='aa', fails_with='.*Identifier too short.*')

# > max length
assert_that(name='a' * 65, fails_with='.*Identifier too long.*')

# Leading underscore
assert_that(name='_aaa', fails_with='.*Identifiers must not begin with an underscore.*')

# Leading dot
assert_that(name='.aaa', fails_with='.*Identifiers must not begin with a dot.*')

# Non lowercase ASCII alnum
assert_that(name='aaą', fails_with='.*Identifiers must be lowercase ASCII alphanumerical.*')

# Valid name
for crate_type in CRATE_TYPES:
run_alr('init', f"--{crate_type}", f"{VALID_NAME}{crate_type}")

print('SUCCESS')
4 changes: 4 additions & 0 deletions testsuite/tests/init/crate-name-validation/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
indexes:
basic_index: # needed to avoid cloning the community index
in_fixtures: true