func TestGrep(t *testing.T) { assert := assrt.NewAssert(t) cmd := exec.Command("grep", "--color=auto", "bar") host := siphon.NewHost(cmd, siphon.NewInternalAddr()) host.Start() go func() { stdin := host.StdinPipe() stdin.Write([]byte("foo\nbar\nbaz\n")) stdin.Write([]byte{4}) // EOT }() outBuffer := new(bytes.Buffer) io.Copy(outBuffer, host.StdoutPipe()) out := string(outBuffer.Bytes()) expected := // I have no idea where the CR characters come from. "foo\r\n" + "bar\r\n" + "baz\r\n" + "[01;31m[Kbar[m[K\r\n" assert.Equal( expected, out, ) }
/** Getting any answer from the tty command at all is pretty good news, since `go test` doesn't let the shell's tty come through. */ func TestActuallyNewTty(t *testing.T) { assert := assrt.NewAssert(t) cmd := exec.Command("tty") host := siphon.NewHost(cmd, siphon.NewInternalAddr()) outBuffer := new(bytes.Buffer) hostOut := host.StdoutPipe() host.Start() io.Copy(outBuffer, hostOut) innerTty := string(outBuffer.Bytes()) assert.NotEqual( "", // what exactly you get varies on the current state of your machine, but something like /dev/pts/12 is reasonable. innerTty, ) }