Skip to content

Commit b1edf70

Browse files
authored
Run tests in RPM builds for ament and cmake packages (#585)
1 parent cb08434 commit b1edf70

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

bloom/generators/rpm/templates/ament_cmake/template.spec.em

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
%bcond_without tests
12
%bcond_without weak_deps
23

34
%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
@@ -56,6 +57,19 @@ mkdir -p obj-%{_target_platform} && cd obj-%{_target_platform}
5657
if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.sh"; fi
5758
%make_install -C obj-%{_target_platform}
5859

60+
%if 0%{?with_tests}
61+
%check
62+
# Look for a Makefile target with a name indicating that it runs tests
63+
TEST_TARGET=$(%__make -qp -C obj-%{_target_platform} | sed "s/^\(test\|check\):.*/\\1/;t f;d;:f;q0")
64+
if [ -n "$TEST_TARGET" ]; then
65+
# In case we're installing to a non-standard location, look for a setup.sh
66+
# in the install tree and source it. It will set things like
67+
# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
68+
if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.sh"; fi
69+
%make_build -C obj-%{_target_platform} $TEST_TARGET || echo "RPM TESTS FAILED"
70+
else echo "RPM TESTS SKIPPED"; fi
71+
%endif
72+
5973
%files
6074
@(InstallationPrefix)
6175

bloom/generators/rpm/templates/ament_python/template.spec.em

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
%bcond_without tests
12
%bcond_without weak_deps
23

34
%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
@@ -43,6 +44,19 @@ if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.
4344
if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.sh"; fi
4445
%py3_install -- --prefix "@(InstallationPrefix)"
4546

47+
%if 0%{?with_tests}
48+
%check
49+
# Look for a directory with a name indicating that it contains tests
50+
TEST_TARGET=$(ls -d * | grep -m1 "\(test\|tests\)" ||:)
51+
if [ -n "$TEST_TARGET" ] && %__python3 -m pytest --version; then
52+
# In case we're installing to a non-standard location, look for a setup.sh
53+
# in the install tree and source it. It will set things like
54+
# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
55+
if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.sh"; fi
56+
%__python3 -m pytest $TEST_TARGET || echo "RPM TESTS FAILED"
57+
else echo "RPM TESTS SKIPPED"; fi
58+
%endif
59+
4660
%files
4761
@(InstallationPrefix)
4862

bloom/generators/rpm/templates/cmake/template.spec.em

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
%bcond_without tests
12
%bcond_without weak_deps
23

34
%global __os_install_post %(echo '%{__os_install_post}' | sed -e 's!/usr/lib[^[:space:]]*/brp-python-bytecompile[[:space:]].*$!!g')
@@ -56,6 +57,19 @@ mkdir -p obj-%{_target_platform} && cd obj-%{_target_platform}
5657
if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.sh"; fi
5758
%make_install -C obj-%{_target_platform}
5859

60+
%if 0%{?with_tests}
61+
%check
62+
# Look for a Makefile target with a name indicating that it runs tests
63+
TEST_TARGET=$(%__make -qp -C obj-%{_target_platform} | sed "s/^\(test\|check\):.*/\\1/;t f;d;:f;q0")
64+
if [ -n "$TEST_TARGET" ]; then
65+
# In case we're installing to a non-standard location, look for a setup.sh
66+
# in the install tree and source it. It will set things like
67+
# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
68+
if [ -f "@(InstallationPrefix)/setup.sh" ]; then . "@(InstallationPrefix)/setup.sh"; fi
69+
%make_build -C obj-%{_target_platform} $TEST_TARGET || echo "RPM TESTS FAILED"
70+
else echo "RPM TESTS SKIPPED"; fi
71+
%endif
72+
5973
%files
6074
@(InstallationPrefix)
6175

0 commit comments

Comments
 (0)