@@ -407,3 +407,45 @@ func TestEnvInQuoted(t *testing.T) {
407
407
t .Fatalf ("Expected %#v, but %#v:" , expected , args )
408
408
}
409
409
}
410
+
411
+ func TestParseWithEnvs (t * testing.T ) {
412
+ tests := []struct {
413
+ line string
414
+ wantEnvs , wantArgs []string
415
+ }{
416
+ {
417
+ line : "FOO=foo cmd --args=A=B" ,
418
+ wantEnvs : []string {"FOO=foo" },
419
+ wantArgs : []string {"cmd" , "--args=A=B" },
420
+ },
421
+ {
422
+ line : "FOO=foo BAR=bar cmd --args=A=B -A=B" ,
423
+ wantEnvs : []string {"FOO=foo" , "BAR=bar" },
424
+ wantArgs : []string {"cmd" , "--args=A=B" , "-A=B" },
425
+ },
426
+ {
427
+ line : `sh -c "FOO=foo BAR=bar cmd --args=A=B -A=B"` ,
428
+ wantEnvs : []string {},
429
+ wantArgs : []string {"sh" , "-c" , "FOO=foo BAR=bar cmd --args=A=B -A=B" },
430
+ },
431
+ {
432
+ line : "cmd --args=A=B -A=B" ,
433
+ wantEnvs : []string {},
434
+ wantArgs : []string {"cmd" , "--args=A=B" , "-A=B" },
435
+ },
436
+ }
437
+ for _ , tt := range tests {
438
+ t .Run (tt .line , func (t * testing.T ) {
439
+ envs , args , err := ParseWithEnvs (tt .line )
440
+ if err != nil {
441
+ t .Fatal (err )
442
+ }
443
+ if ! reflect .DeepEqual (envs , tt .wantEnvs ) {
444
+ t .Errorf ("Expected %#v, but %#v" , tt .wantEnvs , envs )
445
+ }
446
+ if ! reflect .DeepEqual (args , tt .wantArgs ) {
447
+ t .Errorf ("Expected %#v, but %#v" , tt .wantArgs , args )
448
+ }
449
+ })
450
+ }
451
+ }
0 commit comments