1
0
Fork 0
mirror of synced 2024-12-12 10:25:45 -05:00

Properly handle missing "." in alternate conditions

This commit is contained in:
Tim Byrne 2019-10-12 09:14:45 -05:00
parent 4ea3ed9e2a
commit 6d5467951a
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
3 changed files with 6 additions and 2 deletions

View file

@ -100,7 +100,8 @@ def test_alt_conditions(
@pytest.mark.usefixtures('ds1_copy')
@pytest.mark.parametrize('kind', ['builtin', '', 'envtpl', 'j2cli', 'j2'])
@pytest.mark.parametrize(
'kind', ['builtin', '', None, 'envtpl', 'j2cli', 'j2'])
@pytest.mark.parametrize('label', ['t', 'template', 'yadm', ])
def test_alt_templates(
runner, paths, kind, label):
@ -108,6 +109,8 @@ def test_alt_templates(
yadm_dir = setup_standard_yadm_dir(paths)
suffix = f'##{label}.{kind}'
if kind is None:
suffix = f'##{label}'
utils.create_alt_files(paths, suffix)
run = runner([paths.pgm, '-Y', yadm_dir, 'alt'])
assert run.success

View file

@ -59,7 +59,7 @@ def create_alt_files(paths, suffix,
# Do not test directory support for jinja alternates
test_paths = [new_file1, new_file2]
test_names = [ALT_FILE1, ALT_FILE2]
if not re.match(r'##(t|template|yadm)\.', suffix):
if not re.match(r'##(t$|t\.|template|yadm)', suffix):
test_paths += [new_dir]
test_names += [ALT_DIR]

1
yadm
View file

@ -148,6 +148,7 @@ function score_file() {
for field in "${fields[@]}"; do
label=${field%%.*}
value=${field#*.}
[ "$field" = "$label" ] && value="" # when .value is omitted
score=$((score + 1000))
# default condition
if [[ "$label" =~ ^(default)$ ]]; then