File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -180,8 +180,12 @@ func Post(url string) *Pipe {
180
180
return NewPipe ().Post (url )
181
181
}
182
182
183
- // Slice creates a pipe containing each element of s, one per line.
183
+ // Slice creates a pipe containing each element of s, one per line. If s is
184
+ // empty or nil, then the pipe is empty.
184
185
func Slice (s []string ) * Pipe {
186
+ if len (s ) == 0 {
187
+ return NewPipe ()
188
+ }
185
189
return Echo (strings .Join (s , "\n " ) + "\n " )
186
190
}
187
191
Original file line number Diff line number Diff line change @@ -1387,6 +1387,18 @@ func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) {
1387
1387
}
1388
1388
}
1389
1389
1390
+ func TestSliceGivenEmptySliceProducesEmptyPipe (t * testing.T ) {
1391
+ t .Parallel ()
1392
+ want := ""
1393
+ got , err := script .Slice ([]string {}).String ()
1394
+ if err != nil {
1395
+ t .Fatal (err )
1396
+ }
1397
+ if want != got {
1398
+ t .Fatalf ("want %q, got %q" , want , got )
1399
+ }
1400
+ }
1401
+
1390
1402
func TestStdoutReturnsErrorGivenReadErrorOnPipe (t * testing.T ) {
1391
1403
t .Parallel ()
1392
1404
brokenReader := iotest .ErrReader (errors .New ("oh no" ))
You can’t perform that action at this time.
0 commit comments