MCPcopy Index your code
hub / github.com/expr-lang/expr / redirStdout

Function redirStdout

internal/spew/spew_test.go:109–124  ·  view source on GitHub ↗

redirStdout is a helper function to return the standard output from f as a byte slice.

(f func())

Source from the content-addressed store, hash-verified

107// redirStdout is a helper function to return the standard output from f as a
108// byte slice.
109func redirStdout(f func()) ([]byte, error) {
110 tempFile, err := ioutil.TempFile("", "ss-test")
111 if err != nil {
112 return nil, err
113 }
114 fileName := tempFile.Name()
115 defer os.Remove(fileName) // Ignore error
116
117 origStdout := os.Stdout
118 os.Stdout = tempFile
119 f()
120 os.Stdout = origStdout
121 tempFile.Close()
122
123 return ioutil.ReadFile(fileName)
124}
125
126func initSpewTests() {
127 // Config states with various settings.

Callers 1

TestSpewFunction · 0.85

Calls 2

CloseMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…