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
39 changes: 37 additions & 2 deletions colcon_cmake/task/cmake/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Licensed under the Apache License, Version 2.0

import os
import shutil
from contextlib import suppress
from pathlib import Path

from colcon_cmake.task.cmake import CTEST_EXECUTABLE
from colcon_cmake.task.cmake import get_variable_from_cmake_cache
Expand Down Expand Up @@ -88,6 +91,11 @@ async def test(self, *, additional_hooks=None): # noqa: D102
'--repeat-until-fail', str(count),
]

# delete an existing Testing/TAG file to ensure a new tag name is used
tag_file = Path(args.build_base) / 'Testing' / 'TAG'
with suppress(FileNotFoundError):
tag_file.unlink()

rerun = 0
while True:
# invoke CTest
Expand All @@ -97,7 +105,7 @@ async def test(self, *, additional_hooks=None): # noqa: D102
cwd=args.build_base, env=env)

if not completed.returncode:
return
break

# try again if requested
if args.retest_until_pass > rerun:
Expand All @@ -112,13 +120,40 @@ async def test(self, *, additional_hooks=None): # noqa: D102
if completed.returncode == 8:
self.context.put_event_into_queue(TestFailure(pkg.name))
# the return code should still be 0
return 0
break
return completed.returncode

# copy Testing/TAG and Testing/<tagname>/Test.xml to custom location
if args.test_result_base and args.test_result_base != args.build_base:
if not tag_file.is_file():
return

# find the latest Test.xml file
latest_xml_dir = tag_file.read_text().splitlines()[0]
latest_xml_path = tag_file.parent / latest_xml_dir / 'Test.xml'
if not latest_xml_path.exists():
logger.warning(
"Skipping '{tag_file}': could not find latest XML file "
"'{latest_xml_path}'".format_map(locals()))
return

dst = Path(args.test_result_base) / 'Testing' / latest_xml_dir
dst.mkdir(parents=True, exist_ok=True)
_copy_file(tag_file, str(dst.parent / tag_file.name))
_copy_file(latest_xml_path, str(dst / latest_xml_path.name))

def _get_configuration_from_cmake(self, build_base):
# get for CMake build type from the CMake cache
build_type = get_variable_from_cmake_cache(
build_base, 'CMAKE_BUILD_TYPE')
if build_type in ('Debug', 'MinSizeRel', 'RelWithDebInfo'):
return build_type
return 'Release'


def _copy_file(src, dst):
if os.path.islink(dst):
os.unlink(dst)
elif os.path.isdir(dst):
shutil.rmtree(dst)
shutil.copy2(src, dst)
2 changes: 2 additions & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ prepend
pytest
returncode
rindex
rmtree
rtype
samefile
scspell
setuptools
stepanas
tagname
thomas
vcxproj
xcode