MCPcopy Create free account
hub / github.com/commander-cli/commander / captureOutput

Function captureOutput

pkg/app/test_command_test.go:205–233  ·  view source on GitHub ↗
(f func())

Source from the content-addressed store, hash-verified

203}
204
205func captureOutput(f func()) string {
206 reader, writer, err := os.Pipe()
207 if err != nil {
208 panic(err)
209 }
210 stdout := os.Stdout
211 stderr := os.Stderr
212 defer func() {
213 os.Stdout = stdout
214 os.Stderr = stderr
215 log.SetOutput(os.Stderr)
216 }()
217 os.Stdout = writer
218 os.Stderr = writer
219 log.SetOutput(writer)
220 out := make(chan string)
221 wg := new(sync.WaitGroup)
222 wg.Add(1)
223 go func() {
224 var buf bytes.Buffer
225 wg.Done()
226 io.Copy(&buf, reader)
227 out <- buf.String()
228 }()
229 wg.Wait()
230 f()
231 writer.Close()
232 return <-out
233}

Callers 7

Test_TestCommand_VerboseFunction · 0.85
Test_TestCommand_DirFunction · 0.85
Test_TestCommand_HttpFunction · 0.85
Test_TestCommand_StdInFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected