diff --git a/catkin_tools/jobs/catkin.py b/catkin_tools/jobs/catkin.py index cd5e4430..636915cd 100644 --- a/catkin_tools/jobs/catkin.py +++ b/catkin_tools/jobs/catkin.py @@ -583,6 +583,7 @@ def create_catkin_test_job( context, package, package_path, + test_target, ): """Generate a job that tests a package""" @@ -606,10 +607,21 @@ def create_catkin_test_job( verbose=False, )) + # Check if the test target exists + # make -q target_name returns 2 if the target does not exist, in that case we want to terminate this test job + # the other cases (0=target is up-to-date, 1=target exists but is not up-to-date) can be ignored + stages.append(CommandStage( + 'findtest', + [MAKE_EXEC, '-q', test_target], + cwd=build_space, + early_termination_retcode=2, + success_retcodes=(0, 1, 2), + )) + # Make command stages.append(CommandStage( 'make', - [MAKE_EXEC, 'run_tests'], + [MAKE_EXEC, test_target], cwd=build_space, logger_factory=CMakeMakeRunTestsIOBufferProtocol.factory, )) diff --git a/catkin_tools/jobs/cmake.py b/catkin_tools/jobs/cmake.py index ddf24596..60ddfec4 100644 --- a/catkin_tools/jobs/cmake.py +++ b/catkin_tools/jobs/cmake.py @@ -410,6 +410,7 @@ def create_cmake_test_job( context, package, package_path, + test_target ): """Generate a job to test a cmake package""" # Package build space path @@ -433,11 +434,11 @@ def create_cmake_test_job( )) # Check if the test target exists - # make -q test returns 2 if the test target does not exist, in that case we want to terminate this test job + # make -q target_name returns 2 if the target does not exist, in that case we want to terminate this test job # the other cases (0=target is up-to-date, 1=target exists but is not up-to-date) can be ignored stages.append(CommandStage( 'findtest', - [MAKE_EXEC, '-q', 'test'], + [MAKE_EXEC, '-q', test_target], cwd=build_space, early_termination_retcode=2, success_retcodes=(0, 1, 2), @@ -446,7 +447,7 @@ def create_cmake_test_job( # Make command stages.append(CommandStage( 'make', - [MAKE_EXEC, 'test'], + [MAKE_EXEC, test_target], cwd=build_space, logger_factory=IOBufferProtocol.factory, )) diff --git a/catkin_tools/verbs/catkin_test/cli.py b/catkin_tools/verbs/catkin_test/cli.py index 9e071984..75be9c1d 100644 --- a/catkin_tools/verbs/catkin_test/cli.py +++ b/catkin_tools/verbs/catkin_test/cli.py @@ -55,6 +55,10 @@ def prepare_arguments(parser): add = config_group.add_argument add('-p', '--parallel-packages', metavar='PACKAGE_JOBS', dest='parallel_jobs', default=None, type=int, help='Maximum number of packages allowed to be built in parallel (default is cpu count)') + add('-t', '--test-target', metavar='TARGET', default=None, type=str, + help='Make target to run for tests (default is "run_tests" for catkin and "test" for cmake)') + add('--catkin-test-target', metavar='TARGET', default=None, type=str, + help='Make target to run for tests for catkin packages, overwrites --test-target (default is "run_tests")') interface_group = parser.add_argument_group('Interface', 'The behavior of the command-line interface.') add = interface_group.add_argument @@ -124,6 +128,15 @@ def main(opts): if opts.verbose and 'VERBOSE' not in os.environ: os.environ['VERBOSE'] = '1' + # Get test targets + catkin_test_target = 'run_tests' + cmake_test_target = 'test' + if opts.test_target: + catkin_test_target = opts.test_target + cmake_test_target = opts.test_target + if opts.catkin_test_target: + catkin_test_target = opts.catkin_test_target + return test_workspace( ctx, packages=opts.packages, @@ -134,4 +147,6 @@ def main(opts): no_notify=opts.no_notify, continue_on_failure=opts.continue_on_failure, summarize_build=opts.summarize, + catkin_test_target=catkin_test_target, + cmake_test_target=cmake_test_target, ) diff --git a/catkin_tools/verbs/catkin_test/test.py b/catkin_tools/verbs/catkin_test/test.py index 0c22c556..9baec6b1 100644 --- a/catkin_tools/verbs/catkin_test/test.py +++ b/catkin_tools/verbs/catkin_test/test.py @@ -35,6 +35,8 @@ def test_workspace( no_notify=False, continue_on_failure=False, summarize_build=False, + catkin_test_target='run_tests', + cmake_test_target='test', ): """Tests a catkin workspace @@ -56,6 +58,10 @@ def test_workspace( :type continue_on_failure: bool :param summarize_build: summarizes the build at the end :type summarize_build: bool + :param catkin_test_target: make target for tests in catkin packages + :type catkin_test_target: str + :param cmake_test_target: make target for tests in cmake packages + :type cmake_test_target: str """ pre_start_time = time.time() @@ -141,6 +147,11 @@ def test_workspace( # Create the job based on the build type build_type = pkg.get_build_type() + if build_type == 'catkin': + test_job_kwargs['test_target'] = catkin_test_target + elif build_type == 'cmake': + test_job_kwargs['test_target'] = cmake_test_target + if build_type in test_job_creators: jobs.append(test_job_creators[build_type](**test_job_kwargs)) diff --git a/tests/system/resources/catkin_pkgs/python_tests_targets/CMakeLists.txt b/tests/system/resources/catkin_pkgs/python_tests_targets/CMakeLists.txt new file mode 100644 index 00000000..4e349acd --- /dev/null +++ b/tests/system/resources/catkin_pkgs/python_tests_targets/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 2.8.12) +project(python_tests_targets) +find_package(catkin REQUIRED) + +catkin_package() + +if(CATKIN_ENABLE_TESTING) + catkin_add_nosetests(test_good.py) + catkin_add_nosetests(test_bad.py) +endif() diff --git a/tests/system/resources/catkin_pkgs/python_tests_targets/package.xml b/tests/system/resources/catkin_pkgs/python_tests_targets/package.xml new file mode 100644 index 00000000..9b4b2e6b --- /dev/null +++ b/tests/system/resources/catkin_pkgs/python_tests_targets/package.xml @@ -0,0 +1,11 @@ + + python_tests_targets + 0.1.0 + BSD + todo + This package contains two python tests. + + catkin + unittest + + diff --git a/tests/system/resources/catkin_pkgs/python_tests_targets/setup.py b/tests/system/resources/catkin_pkgs/python_tests_targets/setup.py new file mode 100644 index 00000000..fb1311ce --- /dev/null +++ b/tests/system/resources/catkin_pkgs/python_tests_targets/setup.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python +from distutils.core import setup +from catkin_pkg.python_setup import generate_distutils_setup + +d = generate_distutils_setup() +setup(**d) diff --git a/tests/system/resources/catkin_pkgs/python_tests_targets/test_bad.py b/tests/system/resources/catkin_pkgs/python_tests_targets/test_bad.py new file mode 100644 index 00000000..f46637e8 --- /dev/null +++ b/tests/system/resources/catkin_pkgs/python_tests_targets/test_bad.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import unittest + + +class TestBad(unittest.TestCase): + + def test_zero(self): + self.assertEqual(0, 1) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/system/resources/catkin_pkgs/python_tests_targets/test_good.py b/tests/system/resources/catkin_pkgs/python_tests_targets/test_good.py new file mode 100644 index 00000000..0ae625a2 --- /dev/null +++ b/tests/system/resources/catkin_pkgs/python_tests_targets/test_good.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import unittest + + +class TestGood(unittest.TestCase): + + def test_zero(self): + self.assertEqual(0, 0) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/system/verbs/catkin_test/test_unit_tests.py b/tests/system/verbs/catkin_test/test_unit_tests.py index 199cc059..dd3fcd7a 100644 --- a/tests/system/verbs/catkin_test/test_unit_tests.py +++ b/tests/system/verbs/catkin_test/test_unit_tests.py @@ -69,3 +69,18 @@ def test_skip_missing_test(): with redirected_stdio() as (out, err): assert catkin_success(['build', 'cmake_pkg', '--no-notify', '--no-status']) assert catkin_success(['test', '--no-notify', '--no-status']) + + +@in_temporary_directory +def test_other_target(): + """Test with a manually specified target""" + cwd = os.getcwd() + source_space = os.path.join(cwd, 'src') + shutil.copytree(os.path.join(RESOURCES_DIR, 'catkin_pkgs', 'python_tests_targets'), source_space) + + with redirected_stdio() as (out, err): + assert catkin_success(['build', 'python_tests_targets', '--no-notify', '--no-status']) + assert catkin_success(['test', '--test-target', 'run_tests_python_tests_targets_nosetests_test_good.py', + '--no-notify', '--no-status']) + assert catkin_failure(['test', '--test-target', 'run_tests_python_tests_targets_nosetests_test_bad.py', + '--no-notify', '--no-status'])