func (S) TestReplaceNoNewLine(c *C) { p := pipe.Line( pipe.Print("out1\nout2\nout3"), pipe.Replace(func(line []byte) []byte { if bytes.HasPrefix(line, []byte("out")) { if line[3] == '2' { return nil } return []byte{'l', line[3], ','} } return line }), ) output, err := pipe.Output(p) c.Assert(err, IsNil) c.Assert(string(output), Equals, "l1,l3,") }
func (S) TestReplace(c *C) { p := pipe.Line( pipe.System("echo out1; echo err1 1>&2; echo out2; echo err2 1>&2; echo out3"), pipe.Replace(func(line []byte) []byte { if bytes.HasPrefix(line, []byte("out")) { if line[3] == '3' { return nil } return []byte{'l', line[3], ','} } return line }), ) output, err := pipe.Output(p) c.Assert(err, IsNil) c.Assert(string(output), Equals, "l1,l2,") }