Skip to content

Commit ffd5e47

Browse files
committed
chore: remove CaptureStandardOutput and reference as they aren't needed
1 parent 31100b5 commit ffd5e47

File tree

2 files changed

+2
-50
lines changed

2 files changed

+2
-50
lines changed

command_linux_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,6 @@ func TestWithCustomStdout(t *testing.T) {
125125
assertEqualWithLineBreak(t, "stderr\nstdout", c.Combined())
126126
}
127127

128-
func TestWithStandardStreams(t *testing.T) {
129-
out, err := CaptureStandardOutput(func() interface{} {
130-
c := NewCommand(">&2 echo stderr; sleep 0.01; echo stdout;", WithStandardStreams)
131-
err := c.Execute()
132-
return err
133-
})
134-
135-
assertEqualWithLineBreak(t, "stderr\nstdout", out)
136-
assert.Nil(t, err)
137-
}
138-
139128
func TestWithEnvironmentVariables(t *testing.T) {
140129
c := NewCommand("echo $env", WithEnvironmentVariables(map[string]string{"env": "value"}))
141130
c.Execute()

testing_utils.go

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,11 @@
11
package cmd
22

33
import (
4-
"bytes"
5-
"github.com/stretchr/testify/assert"
6-
"io"
7-
"log"
8-
"os"
94
"runtime"
10-
"sync"
115
"testing"
12-
)
136

14-
// CaptureStandardOutput allows to capture the output which will be written
15-
// to os.Stdout and os.Stderr.
16-
// It returns the captured output and the return value of the called function
17-
func CaptureStandardOutput(f func() interface{}) (string, interface{}) {
18-
reader, writer, err := os.Pipe()
19-
if err != nil {
20-
panic(err)
21-
}
22-
stdout := os.Stdout
23-
stderr := os.Stderr
24-
defer func() {
25-
os.Stdout = stdout
26-
os.Stderr = stderr
27-
log.SetOutput(os.Stderr)
28-
}()
29-
os.Stdout = writer
30-
os.Stderr = writer
31-
log.SetOutput(writer)
32-
out := make(chan string)
33-
wg := new(sync.WaitGroup)
34-
wg.Add(1)
35-
go func() {
36-
var buf bytes.Buffer
37-
wg.Done()
38-
io.Copy(&buf, reader)
39-
out <- buf.String()
40-
}()
41-
wg.Wait()
42-
result := f()
43-
writer.Close()
44-
return <-out, result
45-
}
7+
"github.com/stretchr/testify/assert"
8+
)
469

4710
func assertEqualWithLineBreak(t *testing.T, expected string, actual string) {
4811
if runtime.GOOS == "windows" {

0 commit comments

Comments
 (0)