Skip to content

Commit e0f8ece

Browse files
committed
Fix test exclusion code
1 parent 5837953 commit e0f8ece

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

build.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,32 @@ def BuildVariant(context):
235235
return "RelWithDebInfo"
236236
return "RelWithDebInfo"
237237

238+
def MergeCtestExcludeRegex(ctestArgs, filesToExclude):
239+
"""Merge files_to_exclude into one -E regex.
240+
241+
CTest keeps only the last -E flag, so callers (e.g. ECG build.py) and
242+
tests-to-run.json must not each add a separate -E.
243+
"""
244+
if not filesToExclude:
245+
return
246+
247+
extra = "|".join(filesToExclude)
248+
for i, arg in enumerate(ctestArgs):
249+
if arg == "-E":
250+
if i + 1 < len(ctestArgs):
251+
ctestArgs[i + 1] = f'{ctestArgs[i + 1]}|{extra}'
252+
return
253+
if arg.startswith("-E"):
254+
pattern = arg[2:].strip()
255+
if len(pattern) >= 2 and pattern[0] == pattern[-1] and pattern[0] in ('"', "'"):
256+
inner = pattern[1:-1]
257+
ctestArgs[i] = f'-E "{inner}|{extra}"'
258+
else:
259+
ctestArgs[i] = f'-E {pattern}|{extra}'
260+
return
261+
262+
ctestArgs.append(f'-E {extra}')
263+
238264
def FormatMultiProcs(numJobs, generator):
239265
tag = "-j"
240266
if generator:
@@ -815,9 +841,9 @@ def __init__(self, args):
815841
# get labels to be passed for ctest
816842
self.get_ctest_labels()
817843

818-
# add -E args for test file to be excluded by name
819-
if self.kFilesToExclude:
820-
self.ctestArgs.append(f'{"-E"} {"|".join(self.kFilesToExclude)}')
844+
# Merge files_to_exclude into any existing -E from --ctest-args.
845+
# CTest only honors the last -E; a second one would drop ECG exclusions.
846+
MergeCtestExcludeRegex(self.ctestArgs, self.kFilesToExclude)
821847

822848
# add -L args, test with following labels to run
823849
if self.kPluginsToInclude:

0 commit comments

Comments
 (0)