MCPcopy Create free account
hub / github.com/JordanCoin/codemap / captureMainOutput

Function captureMainOutput

main_helpers_test.go:193–218  ·  view source on GitHub ↗
(fn func())

Source from the content-addressed store, hash-verified

191}
192
193func captureMainOutput(fn func()) string {
194 oldStdout := os.Stdout
195 oldStderr := os.Stderr
196 outFile, err := os.CreateTemp("", "codemap-main-output-*")
197 if err != nil {
198 panic(err)
199 }
200 defer os.Remove(outFile.Name())
201
202 func() {
203 defer func() {
204 _ = outFile.Close()
205 os.Stdout = oldStdout
206 os.Stderr = oldStderr
207 }()
208 os.Stdout = outFile
209 os.Stderr = outFile
210 fn()
211 }()
212
213 data, err := os.ReadFile(outFile.Name())
214 if err != nil {
215 panic(err)
216 }
217 return string(data)
218}
219
220func runMainWithArgs(t *testing.T, args []string) string {
221 t.Helper()

Calls 2

RemoveMethod · 0.80
CloseMethod · 0.80

Tested by

no test coverage detected