MCPcopy
hub / github.com/gin-gonic/gin / captureOutput

Function captureOutput

debug_test.go:136–165  ·  view source on GitHub ↗
(t *testing.T, f func())

Source from the content-addressed store, hash-verified

134}
135
136func captureOutput(t *testing.T, f func()) string {
137 reader, writer, err := os.Pipe()
138 if err != nil {
139 panic(err)
140 }
141 defaultWriter := DefaultWriter
142 defaultErrorWriter := DefaultErrorWriter
143 defer func() {
144 DefaultWriter = defaultWriter
145 DefaultErrorWriter = defaultErrorWriter
146 log.SetOutput(os.Stderr)
147 }()
148 DefaultWriter = writer
149 DefaultErrorWriter = writer
150 log.SetOutput(writer)
151 out := make(chan string)
152 wg := new(sync.WaitGroup)
153 wg.Add(1)
154 go func() {
155 var buf strings.Builder
156 wg.Done()
157 _, err := io.Copy(&buf, reader)
158 assert.NoError(t, err)
159 out <- buf.String()
160 }()
161 wg.Wait()
162 f()
163 writer.Close()
164 return <-out
165}
166
167func TestGetMinVer(t *testing.T) {
168 var m uint64

Callers 13

TestContextRenderHTML2Function · 0.85
TestBindWithFunction · 0.85
TestDebugPrintFunction · 0.85
TestDebugPrintFuncFunction · 0.85
TestDebugPrintErrorFunction · 0.85
TestDebugPrintRoutesFunction · 0.85
TestDebugPrintRouteFuncFunction · 0.85
TestDebugPrintWARNINGNewFunction · 0.85

Calls 4

DoneMethod · 0.80
CopyMethod · 0.80
CloseMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected