Drops legacy launch API usage. (#387)
* Drops legacy launch API usage. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com> * Adds launch_testing as test dependency. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
This commit is contained in:
parent
b0a124dcf6
commit
e133167524
3 changed files with 40 additions and 32 deletions
|
@ -36,7 +36,7 @@
|
|||
<test_depend>ament_lint_common</test_depend>
|
||||
<test_depend>rmw</test_depend>
|
||||
<test_depend>rmw_implementation_cmake</test_depend>
|
||||
<test_depend>launch</test_depend>
|
||||
<test_depend>launch_testing</test_depend>
|
||||
<test_depend>osrf_testing_tools_cpp</test_depend>
|
||||
<test_depend>test_msgs</test_depend>
|
||||
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
|
||||
import os
|
||||
|
||||
from launch.legacy import LaunchDescriptor
|
||||
from launch.legacy.launcher import DefaultLauncher
|
||||
from launch import LaunchDescription
|
||||
from launch import LaunchService
|
||||
from launch.actions import ExecuteProcess
|
||||
from launch_testing import LaunchTestService
|
||||
|
||||
|
||||
def launch_test(
|
||||
rmw_implementation_env=None, rcl_assert_rmw_id_matches_env=None, expect_failure=False
|
||||
):
|
||||
ld = LaunchDescriptor()
|
||||
launch_test = LaunchTestService()
|
||||
launch_description = LaunchDescription()
|
||||
|
||||
env = dict(os.environ)
|
||||
if rmw_implementation_env is not None:
|
||||
|
@ -17,15 +20,17 @@ def launch_test(
|
|||
if rcl_assert_rmw_id_matches_env is not None:
|
||||
env['RCL_ASSERT_RMW_ID_MATCHES'] = rcl_assert_rmw_id_matches_env
|
||||
|
||||
ld.add_process(
|
||||
launch_test.add_test_action(
|
||||
launch_description, ExecuteProcess(
|
||||
cmd=['@TEST_RMW_IMPL_ID_CHECK_EXECUTABLE_NAME@'],
|
||||
name='@TEST_RMW_IMPL_ID_CHECK_EXECUTABLE_NAME@',
|
||||
env=env,
|
||||
)
|
||||
)
|
||||
|
||||
launcher = DefaultLauncher()
|
||||
launcher.add_launch_descriptor(ld)
|
||||
rc = launcher.launch()
|
||||
launch_service = LaunchService()
|
||||
launch_service.include_launch_description(launch_description)
|
||||
rc = launch_test.run(launch_service)
|
||||
|
||||
if expect_failure:
|
||||
assert rc != 0, 'The executable did not fail as expected.'
|
||||
|
@ -71,6 +76,6 @@ def test_both():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_rmw_impl_env()
|
||||
test_rmw_implementation_env()
|
||||
test_rcl_assert_rmw_id_matches_env()
|
||||
test_both()
|
||||
|
|
|
@ -1,29 +1,32 @@
|
|||
# generated from rcl/test/test_two_executables.py.in
|
||||
|
||||
from launch.legacy import LaunchDescriptor
|
||||
from launch.legacy.exit_handler import ignore_signal_exit_handler
|
||||
from launch.legacy.exit_handler import primary_exit_handler
|
||||
from launch.legacy.launcher import DefaultLauncher
|
||||
from launch import LaunchDescription
|
||||
from launch import LaunchService
|
||||
from launch.actions import ExecuteProcess
|
||||
from launch_testing import LaunchTestService
|
||||
|
||||
|
||||
def @TEST_NAME@():
|
||||
ld = LaunchDescriptor()
|
||||
launch_test = LaunchTestService()
|
||||
launch_description = LaunchDescription()
|
||||
|
||||
ld.add_process(
|
||||
launch_test.add_fixture_action(
|
||||
launch_description, ExecuteProcess(
|
||||
cmd=['@TEST_EXECUTABLE1@'],
|
||||
name='@TEST_EXECUTABLE1_NAME@',
|
||||
exit_handler=ignore_signal_exit_handler,
|
||||
), exit_allowed=True
|
||||
)
|
||||
|
||||
ld.add_process(
|
||||
launch_test.add_test_action(
|
||||
launch_description, ExecuteProcess(
|
||||
cmd=['@TEST_EXECUTABLE2@', '@TEST_EXECUTABLE1_NAME@'],
|
||||
name='@TEST_EXECUTABLE2_NAME@',
|
||||
exit_handler=primary_exit_handler,
|
||||
)
|
||||
)
|
||||
|
||||
launcher = DefaultLauncher()
|
||||
launcher.add_launch_descriptor(ld)
|
||||
rc = launcher.launch()
|
||||
launch_service = LaunchService()
|
||||
launch_service.include_launch_description(launch_description)
|
||||
rc = launch_test.run(launch_service)
|
||||
|
||||
assert rc == 0, "The launch file failed with exit code '" + str(rc) + "'. "
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue