@@ -318,3 +318,70 @@ def test_execute_process_prefix_filter_override_in_launch_file():
318318 test_process .execute (lc )
319319 assert 'echo' in test_process .process_details ['cmd' ] and \
320320 'time' not in test_process .process_details ['cmd' ]
321+
322+
323+ preamble = [sys .executable , os .path .join (os .path .dirname (__file__ ), 'argv_echo.py' )]
324+
325+
326+ @pytest .mark .parametrize ('test_parameters' , [
327+ # This case will result in 2 arguments, keeping the --some-arg and "some string" together.
328+ {
329+ 'cmd' : preamble + ['--some-arg "some string"' ],
330+ 'shell' : False ,
331+ 'split_arguments' : False ,
332+ 'expected_number_of_args' : 2 ,
333+ },
334+ # This case will split the --some-arg and "some string" up, resulting in 3 args.
335+ {
336+ 'cmd' : preamble + ['--some-arg "some string"' ],
337+ 'shell' : False ,
338+ 'split_arguments' : True ,
339+ 'expected_number_of_args' : 3 ,
340+ },
341+ # This case the split_arguments is ignored, due to shell=True,
342+ # and produces again 3 arguments, not 4.
343+ {
344+ 'cmd' : preamble + ['--some-arg "some string"' ],
345+ 'shell' : True ,
346+ 'split_arguments' : True ,
347+ 'expected_number_of_args' : 3 ,
348+ },
349+ # This is the "normal" shell=True behavior.
350+ {
351+ 'cmd' : preamble + ['--some-arg "some string"' ],
352+ 'shell' : True ,
353+ 'split_arguments' : False ,
354+ 'expected_number_of_args' : 3 ,
355+ },
356+ # Test single argument for cmd (still a list), which will require shell=True.
357+ {
358+ 'cmd' : [' ' .join (preamble + ['--some-arg "some string"' ])],
359+ 'shell' : True ,
360+ 'split_arguments' : False ,
361+ 'expected_number_of_args' : 3 ,
362+ },
363+ # This case also ignores split_arguments.
364+ {
365+ 'cmd' : [' ' .join (preamble + ['--some-arg "some string"' ])],
366+ 'shell' : True ,
367+ 'split_arguments' : True ,
368+ 'expected_number_of_args' : 3 ,
369+ },
370+ ])
371+ def test_execute_process_split_arguments (test_parameters ):
372+ """Test the use of the split_arguments option."""
373+ execute_process_action = ExecuteProcess (
374+ cmd = test_parameters ['cmd' ],
375+ output = 'screen' ,
376+ shell = test_parameters ['shell' ],
377+ split_arguments = test_parameters ['split_arguments' ],
378+ )
379+
380+ ld = LaunchDescription ([
381+ execute_process_action ,
382+ ])
383+ ls = LaunchService ()
384+ ls .include_launch_description (ld )
385+ assert 0 == ls .run (shutdown_when_idle = True )
386+ assert execute_process_action .return_code == test_parameters ['expected_number_of_args' ], \
387+ execute_process_action .process_details ['cmd' ]
0 commit comments