(fn func())
| 191 | } |
| 192 | |
| 193 | func 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 | |
| 220 | func runMainWithArgs(t *testing.T, args []string) string { |
| 221 | t.Helper() |
no test coverage detected