Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions btest
Original file line number Diff line number Diff line change
Expand Up @@ -3123,28 +3123,14 @@ if __name__ == "__main__":
Config = getcfgparser(defaults)
Config.read(btest_cfg, encoding="utf-8")

# Make sure at this point that any Python-level %()s substitution patterns
# resolve. Cleaner to error now than in mid-processing when we retrieve an
# option. We use itemsNoDefaults() for this since falling back on defaults
# pulls in all of os.environ, some of which may well not be formatted for
# Python substitution.
try:
for section in Config.sections():
for _, _ in Config.itemsNoDefaults(section):
pass
except configparser.InterpolationError as err:
error(
f"{btest_cfg} contains invalid Python configparser interpolation in {err.section}.{err.option}: {err}"
)

defaults["baselinedir"] = getOption("BaselineDir", defaults["baselinedir"])

min_version = getOption("MinVersion", None)
if min_version:
validate_version_requirement(min_version, VERSION)

if Options.alternatives:
# Preprocess to split into list. "-" refers to the default setup, as a
# Preprocess to split into list. "-" refers to the default alternative, as a
# shorthand for "default", to allow combination with select alternatives.
Options.alternatives = [alt.strip() for alt in Options.alternatives.split(",")]
Options.alternatives = [
Expand Down Expand Up @@ -3188,6 +3174,34 @@ if __name__ == "__main__":
None,
transform=lambda x: normalize_path(x),
)
else:
Options.alternatives = []

# Make sure at this point that any Python-level %()s substitution patterns
# resolve. Cleaner to error now than in mid-processing when we retrieve an
# option. We use itemsNoDefaults() for this since falling back on defaults
# pulls in all of os.environ, some of which may well not be formatted for
# Python substitution.
try:
for section in Config.sections():
# Skip interpolating sections of alternatives that aren't selected
# via -a / --alternatives. They aren't needed to run tests
# and aren't expected to properly interpolatable.
if (
section.startswith("environment-")
or section.startswith("filter-")
or section.startswith("substitution-")
):
tag = section.split("-", 1)[-1]
if tag not in Options.alternatives:
continue

for _, _ in Config.itemsNoDefaults(section):
pass
except configparser.InterpolationError as err:
error(
f"{btest_cfg} contains invalid Python configparser interpolation in {err.section}.{err.option}: {err}"
)

orig_cwd = pathlib.Path.cwd()
os.chdir(TestBase)
Expand Down
13 changes: 13 additions & 0 deletions testing/Baseline/tests.btest-cfg-skip-non-selected-env/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
X default
X default
test ... ok
all 1 tests successful
X default
X installation
Y installation
X default
X installation
Y installation
test [installation] ... ok
all 1 tests successful
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
default
MYTEST_X=Xdefault
installation
MYTEST_X=Xinstallation
MYTEST_Y=Yinstallation
29 changes: 29 additions & 0 deletions testing/tests/btest-cfg-skip-non-selected-env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# %TEST-DOC: Validates that a environment-<tag> section isn't interpolated/evaluated
# it is not not selected.
#
# %TEST-EXEC: echo "default" >>test.out
# %TEST-EXEC: btest -dt test >output 2>&1
# %TEST-EXEC: echo "installation" >>test.out
# %TEST-EXEC: btest -dt -a installation test >>output 2>&1
# %TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output
# %TEST-EXEC: btest-diff test.out

# %TEST-START-FILE btest.cfg
[DEFAULT]
val1 = abcd

[btest]
option1=%(val1)s

[environment]
MYTEST_X=`echo X default >&2; echo Xdefault`

[environment-installation]
MYTEST_X=`echo X installation >&2; echo Xinstallation`
MYTEST_Y=`echo Y installation >&2; echo Yinstallation`
# %TEST-END-FILE

# %TEST-START-FILE test
# # This writes into the outer test directory.
# @TEST-EXEC: env | grep MYTEST | sort >> ../../test.out
# %TEST-END-FILE
Loading