@@ -454,3 +454,53 @@ func TestParseWithEnvs(t *testing.T) {
454
454
})
455
455
}
456
456
}
457
+
458
+ func TestSubShellEnv (t * testing.T ) {
459
+ myParser := & Parser {
460
+ ParseEnv : true ,
461
+ }
462
+
463
+ errTmpl := "bad arg parsing:\n expected: %#v\n actual : %#v\n "
464
+
465
+ t .Run ("baseline" , func (t * testing.T ) {
466
+ args , err := myParser .Parse (`program -f abc.txt` )
467
+ if err != nil {
468
+ t .Fatalf ("err should be nil: %v" , err )
469
+ }
470
+ expected := []string {"program" , "-f" , "abc.txt" }
471
+ if len (args ) != 3 {
472
+ t .Fatalf (errTmpl , expected , args )
473
+ }
474
+ if args [0 ] != expected [0 ] || args [1 ] != expected [1 ] || args [2 ] != expected [2 ] {
475
+ t .Fatalf (errTmpl , expected , args )
476
+ }
477
+ })
478
+
479
+ t .Run ("single-quoted" , func (t * testing.T ) {
480
+ args , err := myParser .Parse (`sh -c 'echo foo'` )
481
+ if err != nil {
482
+ t .Fatalf ("err should be nil: %v" , err )
483
+ }
484
+ expected := []string {"sh" , "-c" , "echo foo" }
485
+ if len (args ) != 3 {
486
+ t .Fatalf (errTmpl , expected , args )
487
+ }
488
+ if args [0 ] != expected [0 ] || args [1 ] != expected [1 ] || args [2 ] != expected [2 ] {
489
+ t .Fatalf (errTmpl , expected , args )
490
+ }
491
+ })
492
+
493
+ t .Run ("double-quoted" , func (t * testing.T ) {
494
+ args , err := myParser .Parse (`sh -c "echo foo"` )
495
+ if err != nil {
496
+ t .Fatalf ("err should be nil: %v" , err )
497
+ }
498
+ expected := []string {"sh" , "-c" , "echo foo" }
499
+ if len (args ) != 3 {
500
+ t .Fatalf (errTmpl , expected , args )
501
+ }
502
+ if args [0 ] != expected [0 ] || args [1 ] != expected [1 ] || args [2 ] != expected [2 ] {
503
+ t .Fatalf (errTmpl , expected , args )
504
+ }
505
+ })
506
+ }
0 commit comments