// WithStderrMocked runs given testFunction with substituted stderr.
// All content written to stderr by the function is captured and returned as a string.
WithStderrMocked runs given testFunction with substituted stderr.
All content written to stderr by the function is captured and returned as a string.
// WithStderrMocked runs given testFunction with substituted stderr . // All content written to stderr by the function is captured and returned as a string .
func WithStderrMocked(testFunction func()) (string, error) {
	r, w, err := os.Pipe()
	if err != nil {
		return "", err
	}
	tmp := os.Stderr
	defer func() {
		os.Stderr = tmp
	}()
	os.Stderr = w
	go func() {
		defer w.Close() 
		testFunction()
	}()
	buffer, err := ioutil.ReadAll(r)
	if err != nil {
		return "", err
	}
	return string(buffer), nil
}
func WithStderrMocked ( testFunction func ( ) ) ( string , error ) { r , w , err := os . Pipe ( ) if err != nil { return " " , err } tmp := os . Stderr defer func ( ) { os . Stderr = tmp } ( ) os . Stderr = w go func ( ) { defer w . Close ( ) testFunction ( ) } ( ) buffer , err := ioutil . ReadAll ( r ) if err != nil { return " " , err } return string ( buffer ) , nil }
WithStderrMocked runs given testFunction with substituted stderr.
WithStderrMocked runs given testFunction with substituted stderr .
// nolint: errcheck