Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9174ed5
Python 3.15 added `frozendict` as a built-in type.
StephanTLavavej Oct 13, 2026
3739e8c
Replace deprecated Dict, List, Set, Tuple aliases.
StephanTLavavej Oct 13, 2026
4a72d0e
Replace Optional and Union with union type expressions.
StephanTLavavej Oct 13, 2026
a33530e
Use `str.removesuffix()`.
StephanTLavavej Oct 13, 2026
8df3225
Remove Windows workaround in `subprocess.Popen()`.
StephanTLavavej Oct 13, 2026
f41045b
Use `itertools.pairwise()`.
StephanTLavavej Oct 14, 2026
3d4614f
Use `enumerate()`.
StephanTLavavej Oct 14, 2026
3d09925
Use `yield from`.
StephanTLavavej Oct 14, 2026
1071eef
Use set comprehensions.
StephanTLavavej Oct 14, 2026
75b4bc0
Directly `enumerate()` a file's lines.
StephanTLavavej Oct 14, 2026
4b43f90
Pass a generator expression to `any()`.
StephanTLavavej Oct 14, 2026
6d552e7
Directly read an exception's `__traceback__`.
StephanTLavavej Oct 14, 2026
2448345
Python 3.15 added explicit lazy imports.
StephanTLavavej Oct 14, 2026
582c991
Python 3.15 added unpacking in comprehensions.
StephanTLavavej Oct 14, 2026
61bf108
Use f-strings, especially after Python 3.12 improved them.
StephanTLavavej Oct 14, 2026
6bff8b1
Use f-strings instead of string concatenation (simple cases).
StephanTLavavej Oct 14, 2026
1d8cb63
Use f-strings instead of string concatenation (moderate cases).
StephanTLavavej Oct 14, 2026
46818ac
Use f-strings (complex case).
StephanTLavavej Oct 14, 2026
664165c
Use `set.isdisjoint`.
StephanTLavavej Oct 14, 2026
c3bff19
Use list comprehensions.
StephanTLavavej Oct 14, 2026
dadbd1a
Use `super().__init__()`.
StephanTLavavej Oct 14, 2026
e572b69
Use `os.scandir()`.
StephanTLavavej Oct 14, 2026
0db50df
Python 3.15 added `re.prefixmatch()` and soft-deprecated `re.match()`.
StephanTLavavej Oct 15, 2026
b7bb528
Use augmented assignments.
StephanTLavavej Oct 15, 2026
9b163d0
Use set equality.
StephanTLavavej Oct 15, 2026
a5fa772
Test for membership directly.
StephanTLavavej Oct 15, 2026
52b69c1
Call `sys.exit()`.
StephanTLavavej Oct 15, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ def getBuildSteps(self, test, litConfig, shared):
outputDir, _ = test.getTempPaths()
dllOutput = os.path.join(outputDir, 'TestDll.DLL')

cmd = [test.cxx, dllSource, *test.flags, *test.compileFlags, '/Fe' + dllOutput,
cmd = [test.cxx, dllSource, *test.flags, *test.compileFlags, f'/Fe{dllOutput}',
'/link', '/DLL', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)

for step in super().getBuildSteps(test, litConfig, shared):
yield step
yield from super().getBuildSteps(test, litConfig, shared)
4 changes: 2 additions & 2 deletions tests/std/tests/Dev09_172666_tr1_tuple_odr/custom_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def getBuildSteps(self, test, litConfig, shared):
if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', exeSource, test2Source, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
cmd = [test.cxx, exeSource, test2Source, *test.flags, *test.compileFlags, '/Fe' + shared.execFile,
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, exeSource, test2Source, *test.flags, *test.compileFlags, f'/Fe{shared.execFile}',
'/link', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)
10 changes: 4 additions & 6 deletions tests/std/tests/GH_000545_include_compare/custom_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ def getBuildSteps(self, test, litConfig, shared):
exeSourceDir = os.path.dirname(test.getSourcePath())
_, outputBase = test.getTempPaths()

sourceFiles = []
for filename in os.listdir(exeSourceDir):
if filename.endswith('.cpp'):
sourceFiles.append(os.path.join(exeSourceDir, filename))
sourceFiles = [os.path.join(exeSourceDir, filename)
for filename in os.listdir(exeSourceDir) if filename.endswith('.cpp')]

if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', *sourceFiles, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
cmd = [test.cxx, *sourceFiles, *test.flags, *test.compileFlags, '/Fe' + shared.execFile,
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, *sourceFiles, *test.flags, *test.compileFlags, f'/Fe{shared.execFile}',
'/link', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def getBuildSteps(self, test, litConfig, shared):
if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', exeSource, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
cmd = [test.cxx, exeSource, *test.flags, *test.compileFlags, '/Fe' + shared.execFile,
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, exeSource, *test.flags, *test.compileFlags, f'/Fe{shared.execFile}',
'/link', *test.linkFlags, f'/MANIFESTINPUT:{manifestFile}']

yield TestStep(cmd, shared.execDir, shared.env, False)
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ def getBuildSteps(self, test, litConfig, shared):
exeSourceDir = os.path.dirname(test.getSourcePath())
_, outputBase = test.getTempPaths()

sourceFiles = []
for filename in os.listdir(exeSourceDir):
if filename.endswith('.cpp'):
sourceFiles.append(os.path.join(exeSourceDir, filename))
sourceFiles = [os.path.join(exeSourceDir, filename)
for filename in os.listdir(exeSourceDir) if filename.endswith('.cpp')]

if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', *sourceFiles, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
cmd = [test.cxx, *sourceFiles, *test.flags, *test.compileFlags, '/Fe' + shared.execFile,
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, *sourceFiles, *test.flags, *test.compileFlags, f'/Fe{shared.execFile}',
'/link', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)
4 changes: 2 additions & 2 deletions tests/std/tests/P0607R0_inline_variables/custom_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def getBuildSteps(self, test, litConfig, shared):
if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', exeSource, test2Source, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
cmd = [test.cxx, exeSource, test2Source, *test.flags, *test.compileFlags, '/Fe' + shared.execFile,
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, exeSource, test2Source, *test.flags, *test.compileFlags, f'/Fe{shared.execFile}',
'/link', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ def getBuildSteps(self, test, litConfig, shared):
}

# Add compiler options to consume the header units that we just built.
for hdr in readyToBuild:
consumeBuiltHeaderUnits += ['/headerUnit:angle', f'{hdr}={hdr}.ifc']
consumeBuiltHeaderUnits += [*('/headerUnit:angle', f'{hdr}={hdr}.ifc') for hdr in readyToBuild]
else: # Build independent header units:
stlHeaders = getImportableCxxLibraryHeaders(sourcePath)
exportHeaderOptions = ['/exportHeader', '/headerName:angle', '/Fo', '/MP']
for hdr in stlHeaders:
consumeBuiltHeaderUnits += ['/headerUnit:angle', f'{hdr}={hdr}.ifc']
objFilenames.append(f'{hdr}.obj')
consumeBuiltHeaderUnits = [*('/headerUnit:angle', f'{hdr}={hdr}.ifc') for hdr in stlHeaders]
objFilenames = [f'{hdr}.obj' for hdr in stlHeaders]

if noisyProgress:
print('Building independent header units...')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class CustomTest(STLTest):
def __init__(self, suite, pathInSuite, litConfig, testConfig, envlstEntry, envNum):
STLTest.__init__(self, suite, pathInSuite, litConfig, testConfig, envlstEntry, envNum)
super().__init__(suite, pathInSuite, litConfig, testConfig, envlstEntry, envNum)
self.callingConventionA = envlstEntry.getEnvVal('CALLING_CONVENTION_A')
self.callingConventionB = envlstEntry.getEnvVal('CALLING_CONVENTION_B')

Expand All @@ -25,19 +25,19 @@ def getBuildSteps(self, test, litConfig, shared):
outputDir, outputBase = test.getTempPaths()
aObj = os.path.join(outputDir, 'a.obj')

cmd = [test.cxx, aSource, test.callingConventionA, *test.flags, '/c', *test.compileFlags, '/Fo' + aObj]
cmd = [test.cxx, aSource, test.callingConventionA, *test.flags, '/c', *test.compileFlags, f'/Fo{aObj}']

yield TestStep(cmd, shared.execDir, shared.env, False)

shared.execFile = outputBase + '.exe'
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, exeSource, aObj, test.callingConventionB, *test.flags, *test.compileFlags,
'/Fe' + shared.execFile, '/link', *test.linkFlags]
f'/Fe{shared.execFile}', '/link', *test.linkFlags]

if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', exeSource, aObj, test.callingConventionB, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, exeSource, aObj, test.callingConventionB, *test.flags, *test.compileFlags,
'/Fe' + shared.execFile, '/link', *test.linkFlags]
f'/Fe{shared.execFile}', '/link', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def getBuildSteps(self, test, litConfig, shared):
if TestType.COMPILE in test.testType:
cmd = [test.cxx, '/c', exeSource, test2Source, *test.flags, *test.compileFlags]
elif TestType.RUN in test.testType:
shared.execFile = outputBase + '.exe'
cmd = [test.cxx, exeSource, test2Source, *test.flags, *test.compileFlags, '/Fe' + shared.execFile,
shared.execFile = f'{outputBase}.exe'
cmd = [test.cxx, exeSource, test2Source, *test.flags, *test.compileFlags, f'/Fe{shared.execFile}',
'/link', *test.linkFlags]

yield TestStep(cmd, shared.execDir, shared.env, False)
2 changes: 1 addition & 1 deletion tests/utils/stl-lit/stl-lit.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def assert_same_platform_for_build_and_test():
build_platform = '$ENV{VSCMD_ARG_TGT_ARCH}'
test_platform = os.getenv('VSCMD_ARG_TGT_ARCH', default='')
if build_platform != '' and test_platform != '' and build_platform != test_platform:
exit(f'Target platform mismatch: the STL was built for {build_platform} but tested for {test_platform}.')
sys.exit(f'Target platform mismatch: the STL was built for {build_platform} but tested for {test_platform}.')

if __name__=='__main__':
assert_same_platform_for_build_and_test()
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/stl/test/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def configure(parameters, features, config, lit_config):
lit_config.test_subdirs[config.name] = [os.path.normpath(subdir) for subdir in lit_config.test_subdirs[config.name]]
for subdir in lit_config.test_subdirs[config.name]:
if not os.path.exists(subdir):
lit_config.fatal("The directory {} does not exist and was marked as a subdirectory to test".format(subdir))
lit_config.fatal(f"The directory {subdir} does not exist and was marked as a subdirectory to test")

lit_config.flags = getattr(lit_config, 'flags', dict())
lit_config.compile_flags = getattr(lit_config, 'compile_flags', dict())
lit_config.link_flags = getattr(lit_config, 'link_flags', dict())

lit_config.flags[config.name] = []
lit_config.compile_flags[config.name] = \
['-I' + os.path.normpath(dir) for dir in lit_config.include_dirs[config.name]]
[f'-I{os.path.normpath(dir)}' for dir in lit_config.include_dirs[config.name]]
lit_config.link_flags[config.name] = \
['-LIBPATH:' + os.path.normpath(dir) for dir in lit_config.library_dirs[config.name]]
[f'-LIBPATH:{os.path.normpath(dir)}' for dir in lit_config.library_dirs[config.name]]

lit_config.test_env = {'PATH' : os.path.normpath(lit_config.cxx_runtime)}

Expand Down
64 changes: 28 additions & 36 deletions tests/utils/stl/test/file_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from dataclasses import dataclass, field
from pathlib import Path
from typing import Dict, List, Optional, Set, Tuple, Union
import itertools
import os
import re
Expand All @@ -19,38 +18,31 @@

@dataclass
class _TmpEnvEntry:
env: Dict[str, str] = field(default_factory=dict)
tags: Set[str] = field(default_factory=set)
env: dict[str, str] = field(default_factory=dict)
tags: set[str] = field(default_factory=set)


@dataclass(frozen=True)
class EnvEntry:
def __init__(self, tmp_env: _TmpEnvEntry):
object.__setattr__(self, "_env_keys", tuple(tmp_env.env.keys()))
object.__setattr__(self, "_env_vals", tuple(tmp_env.env.values()))
object.__setattr__(self, "_env", frozendict(tmp_env.env))
object.__setattr__(self, "_env_tags", tmp_env.tags)

def hasAnyTag(self, tags: Set[str]) -> bool:
return bool(self._env_tags & tags)
def hasAnyTag(self, tags: set[str]) -> bool:
return not self._env_tags.isdisjoint(tags)

def getEnvVal(self, key: str, default: Optional[str] = None) \
-> Optional[str]:
if key not in self._env_keys:
return default
def getEnvVal(self, key: str, default: str | None = None) \
-> str | None:
return self._env.get(key, default)

# TRANSITION: All of this is to avoid having to install frozendict.
# Reconsider this at a future date.
return self._env_vals[self._env_keys.index(key)]

_env_keys: Tuple[str]
_env_vals: Tuple[str]
_env_tags: Set[str]
_env: frozendict[str, str]
_env_tags: set[str]


@dataclass
class _ParseCtx:
current: List[_TmpEnvEntry] = field(default_factory=list)
result: List[List[_TmpEnvEntry]] = field(default_factory=list)
current: list[_TmpEnvEntry] = field(default_factory=list)
result: list[list[_TmpEnvEntry]] = field(default_factory=list)


_COMMENT_REGEX = re.compile(r"\s*#.*", re.DOTALL)
Expand All @@ -61,11 +53,11 @@ class _ParseCtx:
_EXPECTED_RESULT_REGEX = re.compile(r'^(?P<prefix>[^ ]+) (?P<result>\w+)$')


def _parse_env_line(line: str) -> Optional[_TmpEnvEntry]:
def _parse_env_line(line: str) -> _TmpEnvEntry | None:
result = _TmpEnvEntry()
if (m:=_TAGS_REGEX.match(line)) is not None:
if (m:=_TAGS_REGEX.prefixmatch(line)) is not None:
tags = m.group("tags").split(',')
result.tags = set([x.strip().casefold() for x in tags])
result.tags = {x.strip().casefold() for x in tags}
line = m.group("remainder")
for env_match in _ENV_VAR_MULTI_ITEM_REGEX.finditer(line):
name = env_match.group("name")
Expand All @@ -76,12 +68,12 @@ def _parse_env_line(line: str) -> Optional[_TmpEnvEntry]:

def _merge_crosslist_entries(*args) -> _TmpEnvEntry:
result = _TmpEnvEntry()
result.tags = set(['*'])
result.tags = {'*'}
for entry in args:
# tags are intersected; `*` matches everything
if len(entry.tags) == 1 and '*' in entry.tags:
if entry.tags == {'*'}:
pass
elif len(result.tags) == 1 and '*' in result.tags:
elif result.tags == {'*'}:
result.tags = entry.tags
else:
result.tags &= entry.tags
Expand All @@ -102,25 +94,25 @@ def _do_crosslist(ctx: _ParseCtx):

def _parse_env_lst(env_lst: Path, ctx: _ParseCtx):
for _, line in _parse_commented_file(env_lst):
if (m:=_INCLUDE_REGEX.match(line)) is not None:
if (m:=_INCLUDE_REGEX.prefixmatch(line)) is not None:
p = env_lst.parent / Path(m.group("filename"))
_parse_env_lst(p, ctx)
elif _CROSSLIST_REGEX.match(line) is not None:
elif _CROSSLIST_REGEX.prefixmatch(line) is not None:
ctx.result.append(ctx.current)
ctx.current = []
else:
ctx.current.append(_parse_env_line(line))


def _parse_commented_file(filename: Union[str, bytes, os.PathLike]) \
-> List[Tuple[int, str]]:
def _parse_commented_file(filename: str | bytes | os.PathLike) \
-> list[tuple[int, str]]:
if str(filename) in _preprocessed_file_cache:
return _preprocessed_file_cache[str(filename)]

filename_path = Path(filename)
result = list()
with filename_path.open() as f:
for line_number, line in enumerate(f.readlines(), start=1):
for line_number, line in enumerate(f, start=1):
if (line:=_COMMENT_REGEX.sub("", line)):
line = line.strip()
if line:
Expand All @@ -130,14 +122,14 @@ def _parse_commented_file(filename: Union[str, bytes, os.PathLike]) \
return result


def parse_result_file(filename: Union[str, bytes, os.PathLike]) \
-> Dict[str, lit.Test.ResultCode]:
def parse_result_file(filename: str | bytes | os.PathLike) \
-> dict[str, lit.Test.ResultCode]:
if str(filename) in _expected_result_entry_cache:
return _expected_result_entry_cache[str(filename)]

res = dict()
for line_number, line in _parse_commented_file(filename):
m = _EXPECTED_RESULT_REGEX.match(line)
m = _EXPECTED_RESULT_REGEX.prefixmatch(line)
if m is None:
raise Exception(f'Incorrectly formatted line {line_number}: "{line}" in {filename}.')
prefix = m.group("prefix")
Expand All @@ -153,8 +145,8 @@ def parse_result_file(filename: Union[str, bytes, os.PathLike]) \
return res


def parse_env_lst_file(env_list: Union[str, bytes, os.PathLike]) \
-> Tuple[EnvEntry, ...]:
def parse_env_lst_file(env_list: str | bytes | os.PathLike) \
-> tuple[EnvEntry, ...]:
if str(env_list) in _envlst_cache:
return _envlst_cache[str(env_list)]

Expand Down
Loading