package testing

import (
	"bytes"
	"io"
	"os"
)

//MockStdout to read result from tests
func MockStdout() (io.WriteCloser, chan string) {
	r, w, _ := os.Pipe()
	outC := make(chan string)
	// copy the output in a separate goroutine so printing can't block indefinitely
	go func() {
		var buf bytes.Buffer
		io.Copy(&buf, r)
		outC <- buf.String()
	}()

	return w, outC
}
