Skip to content

Commit 91b6bcc

Browse files
committed
Additional testcase for subst on Variables
This tests the other side of the coin: when vars.Add(..., subst=True) is used, substitution *is* performaed. Signed-off-by: Mats Wichmann <[email protected]>
1 parent 272d72b commit 91b6bcc

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

SCons/Variables/VariablesTests.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,26 +151,46 @@ def test_Update(self) -> None:
151151
assert env['ANSWER'] == 54
152152

153153
# Test that the value is not substituted if 'subst' is False
154-
def check_subst(key, value, env) -> None:
154+
# and that it is if 'subst' is True.
155+
def check_no_subst(key, value, env) -> None:
155156
"""Check that variable was not substituted before we get called."""
156157
assert value == "$ORIGIN", \
157158
f"Validator: '$ORIGIN' was substituted to {value!r}"
158159

159-
def conv_subst(value) -> None:
160+
def conv_no_subst(value) -> None:
160161
"""Check that variable was not substituted before we get called."""
161162
assert value == "$ORIGIN", \
162163
f"Converter: '$ORIGIN' was substituted to {value!r}"
163164
return value
164165

166+
def check_subst(key, value, env) -> None:
167+
"""Check that variable was substituted before we get called."""
168+
assert value == "Value", \
169+
f"Validator: '$SUB' was not substituted {value!r} instead of 'Value'"
170+
171+
def conv_subst(value) -> None:
172+
"""Check that variable was not substituted before we get called."""
173+
assert value == "Value", \
174+
f"Converter: '$SUB' was substituted to {value!r} instead of 'Value'"
175+
return value
176+
165177
opts.Add('NOSUB',
166178
help='Variable whose value will not be substituted',
167179
default='$ORIGIN',
180+
validator=check_no_subst,
181+
converter=conv_no_subst,
182+
subst=False)
183+
opts.Add('SUB',
184+
help='Variable whose value will be substituted',
185+
default='$VAR',
168186
validator=check_subst,
169187
converter=conv_subst,
170-
subst=False)
188+
subst=True)
171189
env = Environment()
190+
env['VAR'] = "Value"
172191
opts.Update(env)
173-
assert env['NOSUB'] == "$ORIGIN"
192+
assert env['NOSUB'] == "$ORIGIN", env['NOSUB']
193+
assert env['SUB'] == env['VAR'], env['SUB']
174194

175195
# Test that a bad value from the file is used and
176196
# validation fails correctly.

0 commit comments

Comments
 (0)