Skip to content

Commit

Permalink
Test init with valid crate name
Browse files Browse the repository at this point in the history
  • Loading branch information
0rzech committed Dec 12, 2022
1 parent 58861e5 commit fa4eca6
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions testsuite/tests/init/crate-name-validation/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,36 @@
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 ['--bin', '--lib']:
p = run_alr('init', crate_type, name, complain_on_error=False)
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
# < min length
assert_that(name='aa', fails_with='.*Identifier too short.*')

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

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

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

# Lowercase ASCII alnum
# 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')

0 comments on commit fa4eca6

Please sign in to comment.