Skip to content

Commit 7b43ed4

Browse files
committed
Add failing test
1 parent 00b2600 commit 7b43ed4

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

unit_test/options_test.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from __future__ import annotations
22

3+
import os
34
import platform as platform_module
45
import textwrap
6+
from pathlib import Path
57

68
import pytest
79

810
from cibuildwheel.__main__ import get_build_identifiers
11+
from cibuildwheel.bashlex_eval import local_environment_executor
912
from cibuildwheel.environment import parse_environment
1013
from cibuildwheel.options import Options, _get_pinned_container_images
1114

@@ -133,16 +136,53 @@ def test_toml_environment_evil(tmp_path, monkeypatch, env_var_value):
133136
args = get_default_command_line_arguments()
134137
args.package_dir = tmp_path
135138

136-
with tmp_path.joinpath("pyproject.toml").open("w") as f:
137-
f.write(
138-
textwrap.dedent(
139-
f"""\
140-
[tool.cibuildwheel.environment]
141-
EXAMPLE='''{env_var_value}'''
142-
"""
143-
)
139+
tmp_path.joinpath("pyproject.toml").write_text(
140+
textwrap.dedent(
141+
f"""\
142+
[tool.cibuildwheel.environment]
143+
EXAMPLE='''{env_var_value}'''
144+
"""
144145
)
146+
)
145147

146148
options = Options(platform="linux", command_line_arguments=args)
147149
parsed_environment = options.build_options(identifier=None).environment
148150
assert parsed_environment.as_dictionary(prev_environment={}) == {"EXAMPLE": env_var_value}
151+
152+
153+
@pytest.mark.parametrize(
154+
"toml_assignment,result_value",
155+
[
156+
('TEST_VAR="simple_value"', "simple_value"),
157+
# spaces
158+
('TEST_VAR="simple value"', "simple value"),
159+
# env var
160+
('TEST_VAR="$PARAM"', "spam"),
161+
('TEST_VAR="$PARAM $PARAM"', "spam spam"),
162+
# env var extension
163+
('TEST_VAR="before:$PARAM:after"', "before:spam:after"),
164+
# env var extension with spaces
165+
('TEST_VAR="before $PARAM after"', "before spam after"),
166+
],
167+
)
168+
def test_toml_environment_quoting(tmp_path: Path, toml_assignment, result_value):
169+
args = get_default_command_line_arguments()
170+
args.package_dir = tmp_path
171+
172+
tmp_path.joinpath("pyproject.toml").write_text(
173+
textwrap.dedent(
174+
f"""\
175+
[tool.cibuildwheel.environment]
176+
{toml_assignment}
177+
"""
178+
)
179+
)
180+
181+
options = Options(platform="linux", command_line_arguments=args)
182+
parsed_environment = options.build_options(identifier=None).environment
183+
environment_values = parsed_environment.as_dictionary(
184+
prev_environment={**os.environ, "PARAM": "spam"},
185+
executor=local_environment_executor,
186+
)
187+
188+
assert environment_values["TEST_VAR"] == result_value

0 commit comments

Comments
 (0)