@@ -246,7 +246,8 @@ mod prepare {
246
246
#[ test]
247
247
fn multiple_arguments_in_one_line_with_auto_split ( ) {
248
248
let cmd = std:: process:: Command :: from (
249
- gix_command:: prepare ( "echo first second third" ) . with_shell_allow_manual_argument_splitting ( ) ,
249
+ gix_command:: prepare ( "echo first second third" )
250
+ . command_may_be_shell_script_allow_manual_argument_splitting ( ) ,
250
251
) ;
251
252
assert_eq ! (
252
253
format!( "{cmd:?}" ) ,
@@ -267,7 +268,8 @@ mod prepare {
267
268
268
269
#[ test]
269
270
fn single_and_multiple_arguments_as_part_of_command_with_shell ( ) {
270
- let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls first second third" ) . with_shell ( ) ) ;
271
+ let cmd =
272
+ std:: process:: Command :: from ( gix_command:: prepare ( "ls first second third" ) . command_may_be_shell_script ( ) ) ;
271
273
assert_eq ! (
272
274
format!( "{cmd:?}" ) ,
273
275
if cfg!( windows) {
@@ -283,7 +285,7 @@ mod prepare {
283
285
fn single_and_multiple_arguments_as_part_of_command_with_given_shell ( ) {
284
286
let cmd = std:: process:: Command :: from (
285
287
gix_command:: prepare ( "ls first second third" )
286
- . with_shell ( )
288
+ . command_may_be_shell_script ( )
287
289
. with_shell_program ( "/somepath/to/bash" ) ,
288
290
) ;
289
291
assert_eq ! (
@@ -299,7 +301,11 @@ mod prepare {
299
301
300
302
#[ test]
301
303
fn single_and_complex_arguments_as_part_of_command_with_shell ( ) {
302
- let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "ls --foo \" a b\" " ) . arg ( "additional" ) . with_shell ( ) ) ;
304
+ let cmd = std:: process:: Command :: from (
305
+ gix_command:: prepare ( "ls --foo \" a b\" " )
306
+ . arg ( "additional" )
307
+ . command_may_be_shell_script ( ) ,
308
+ ) ;
303
309
assert_eq ! (
304
310
format!( "{cmd:?}" ) ,
305
311
if cfg!( windows) {
@@ -314,7 +320,7 @@ mod prepare {
314
320
#[ test]
315
321
fn single_and_complex_arguments_with_auto_split ( ) {
316
322
let cmd = std:: process:: Command :: from (
317
- gix_command:: prepare ( "ls --foo=\" a b\" " ) . with_shell_allow_manual_argument_splitting ( ) ,
323
+ gix_command:: prepare ( "ls --foo=\" a b\" " ) . command_may_be_shell_script_allow_manual_argument_splitting ( ) ,
318
324
) ;
319
325
assert_eq ! (
320
326
format!( "{cmd:?}" ) ,
@@ -326,15 +332,29 @@ mod prepare {
326
332
#[ test]
327
333
fn single_and_complex_arguments_without_auto_split ( ) {
328
334
let cmd = std:: process:: Command :: from (
329
- gix_command:: prepare ( "ls --foo=\" a b\" " ) . with_shell_disallow_manual_argument_splitting ( ) ,
335
+ gix_command:: prepare ( "ls --foo=\" a b\" " ) . command_may_be_shell_script_disallow_manual_argument_splitting ( ) ,
330
336
) ;
331
337
assert_eq ! ( format!( "{cmd:?}" ) , quoted( & [ SH , "-c" , r#"ls --foo=\"a b\""# , "--" ] ) ) ;
332
338
}
333
339
340
+ #[ test]
341
+ fn single_and_simple_arguments_without_auto_split_with_shell ( ) {
342
+ let cmd = std:: process:: Command :: from (
343
+ gix_command:: prepare ( "ls" )
344
+ . arg ( "--foo=a b" )
345
+ . command_may_be_shell_script_disallow_manual_argument_splitting ( )
346
+ . with_shell ( ) ,
347
+ ) ;
348
+ assert_eq ! (
349
+ format!( "{cmd:?}" ) ,
350
+ quoted( & [ SH , "-c" , "ls \\ \" $@\\ \" " , "--" , "--foo=a b" ] )
351
+ ) ;
352
+ }
353
+
334
354
#[ test]
335
355
fn single_and_complex_arguments_will_not_auto_split_on_special_characters ( ) {
336
356
let cmd = std:: process:: Command :: from (
337
- gix_command:: prepare ( "ls --foo=~/path" ) . with_shell_allow_manual_argument_splitting ( ) ,
357
+ gix_command:: prepare ( "ls --foo=~/path" ) . command_may_be_shell_script_allow_manual_argument_splitting ( ) ,
338
358
) ;
339
359
assert_eq ! (
340
360
format!( "{cmd:?}" ) ,
@@ -345,7 +365,8 @@ mod prepare {
345
365
346
366
#[ test]
347
367
fn tilde_path_and_multiple_arguments_as_part_of_command_with_shell ( ) {
348
- let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "~/bin/exe --foo \" a b\" " ) . with_shell ( ) ) ;
368
+ let cmd =
369
+ std:: process:: Command :: from ( gix_command:: prepare ( "~/bin/exe --foo \" a b\" " ) . command_may_be_shell_script ( ) ) ;
349
370
assert_eq ! (
350
371
format!( "{cmd:?}" ) ,
351
372
format!( r#""{SH}" "-c" "~/bin/exe --foo \"a b\"" "--""# ) ,
@@ -355,7 +376,11 @@ mod prepare {
355
376
356
377
#[ test]
357
378
fn script_with_dollar_at ( ) {
358
- let cmd = std:: process:: Command :: from ( gix_command:: prepare ( "echo \" $@\" >&2" ) . with_shell ( ) . arg ( "store" ) ) ;
379
+ let cmd = std:: process:: Command :: from (
380
+ gix_command:: prepare ( "echo \" $@\" >&2" )
381
+ . command_may_be_shell_script ( )
382
+ . arg ( "store" ) ,
383
+ ) ;
359
384
assert_eq ! (
360
385
format!( "{cmd:?}" ) ,
361
386
format!( r#""{SH}" "-c" "echo \"$@\" >&2" "--" "store""# ) ,
@@ -374,7 +399,7 @@ mod spawn {
374
399
let out = gix_command:: prepare ( "echo $FIRST $SECOND" )
375
400
. env ( "FIRST" , "first" )
376
401
. env ( "SECOND" , "second" )
377
- . with_shell ( )
402
+ . command_may_be_shell_script ( )
378
403
. spawn ( ) ?
379
404
. wait_with_output ( ) ?;
380
405
assert_eq ! ( out. stdout. as_bstr( ) , "first second\n " ) ;
@@ -385,12 +410,15 @@ mod spawn {
385
410
#[ cfg( unix) ]
386
411
fn disallow_shell ( ) -> crate :: Result {
387
412
let out = gix_command:: prepare ( "PATH= echo hi" )
388
- . with_shell ( )
413
+ . command_may_be_shell_script ( )
389
414
. spawn ( ) ?
390
415
. wait_with_output ( ) ?;
391
416
assert_eq ! ( out. stdout. as_bstr( ) , "hi\n " ) ;
392
417
393
- let mut cmd: std:: process:: Command = gix_command:: prepare ( "echo hi" ) . with_shell ( ) . without_shell ( ) . into ( ) ;
418
+ let mut cmd: std:: process:: Command = gix_command:: prepare ( "echo hi" )
419
+ . command_may_be_shell_script ( )
420
+ . without_shell ( )
421
+ . into ( ) ;
394
422
assert ! (
395
423
cmd. env_remove( "PATH" ) . spawn( ) . is_err( ) ,
396
424
"no command named 'echo hi' exists"
@@ -400,9 +428,13 @@ mod spawn {
400
428
401
429
#[ test]
402
430
fn script_with_dollar_at ( ) -> crate :: Result {
403
- let out = std:: process:: Command :: from ( gix_command:: prepare ( "echo \" $@\" " ) . with_shell ( ) . arg ( "arg" ) )
404
- . spawn ( ) ?
405
- . wait_with_output ( ) ?;
431
+ let out = std:: process:: Command :: from (
432
+ gix_command:: prepare ( "echo \" $@\" " )
433
+ . command_may_be_shell_script ( )
434
+ . arg ( "arg" ) ,
435
+ )
436
+ . spawn ( ) ?
437
+ . wait_with_output ( ) ?;
406
438
assert_eq ! (
407
439
out. stdout. to_str_lossy( ) . trim( ) ,
408
440
"arg" ,
@@ -433,7 +465,7 @@ mod spawn {
433
465
#[ test]
434
466
fn command_in_path_with_args ( ) -> crate :: Result {
435
467
assert ! ( gix_command:: prepare( if cfg!( unix) { "ls -l" } else { "dir.exe -a" } )
436
- . with_shell ( )
468
+ . command_may_be_shell_script ( )
437
469
. spawn( ) ?
438
470
. wait( ) ?
439
471
. success( ) ) ;
@@ -442,14 +474,18 @@ mod spawn {
442
474
443
475
#[ test]
444
476
fn sh_shell_specific_script_code ( ) -> crate :: Result {
445
- assert ! ( gix_command:: prepare( ":;:;:" ) . with_shell( ) . spawn( ) ?. wait( ) ?. success( ) ) ;
477
+ assert ! ( gix_command:: prepare( ":;:;:" )
478
+ . command_may_be_shell_script( )
479
+ . spawn( ) ?
480
+ . wait( ) ?
481
+ . success( ) ) ;
446
482
Ok ( ( ) )
447
483
}
448
484
449
485
#[ test]
450
486
fn sh_shell_specific_script_code_with_single_extra_arg ( ) -> crate :: Result {
451
487
let out = gix_command:: prepare ( "printf" )
452
- . with_shell ( )
488
+ . command_may_be_shell_script ( )
453
489
. arg ( "1" )
454
490
. spawn ( ) ?
455
491
. wait_with_output ( ) ?;
@@ -461,7 +497,7 @@ mod spawn {
461
497
#[ test]
462
498
fn sh_shell_specific_script_code_with_multiple_extra_args ( ) -> crate :: Result {
463
499
let out = gix_command:: prepare ( "printf" )
464
- . with_shell ( )
500
+ . command_may_be_shell_script ( )
465
501
. arg ( "%s" )
466
502
. arg ( "arg" )
467
503
. spawn ( ) ?
0 commit comments