Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Apr 18, 2024
1 parent 683ea91 commit c95dff8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
combine_specs,
dict_of_lists_to_list_of_dicts,
filter_combined_spec_to_used_keys,
find_used_variables_in_batch_script,
find_used_variables_in_shell_script,
get_package_variants,
get_vars,
validate_spec,
Expand Down Expand Up @@ -715,3 +717,25 @@ def test_get_vars():
]

assert get_vars(variants) == {"nodejs"}


def test_find_used_variables_in_shell_script(tmp_path: Path) -> None:
variants = ("FOO", "BAR", "BAZ", "QUX")
(script := tmp_path / "script.sh").write_text(
f"${variants[0]}\n"
f"${{{variants[1]}}}\n"
f"${{{{{variants[2]}}}}}\n"
f"$${variants[3]}\n"
)
assert find_used_variables_in_shell_script(variants, script) == {"FOO", "BAR"}


def test_find_used_variables_in_batch_script(tmp_path: Path) -> None:
variants = ("FOO", "BAR", "BAZ", "QUX")
(script := tmp_path / "script.sh").write_text(
f"%{variants[0]}%\n"
f"%%{variants[1]}%%\n"
f"${variants[2]}\n"
f"${{{variants[3]}}}\n"
)
assert find_used_variables_in_batch_script(variants, script) == {"FOO", "BAR"}

0 comments on commit c95dff8

Please sign in to comment.