(t *testing.T, fn func())
| 99 | } |
| 100 | |
| 101 | func captureMainStreams(t *testing.T, fn func()) (string, string) { |
| 102 | t.Helper() |
| 103 | |
| 104 | oldOut := os.Stdout |
| 105 | oldErr := os.Stderr |
| 106 | outFile, err := os.CreateTemp("", "codemap-stdout-*") |
| 107 | if err != nil { |
| 108 | t.Fatal(err) |
| 109 | } |
| 110 | errFile, err := os.CreateTemp("", "codemap-stderr-*") |
| 111 | if err != nil { |
| 112 | t.Fatal(err) |
| 113 | } |
| 114 | defer func() { |
| 115 | _ = os.Remove(outFile.Name()) |
| 116 | _ = os.Remove(errFile.Name()) |
| 117 | }() |
| 118 | |
| 119 | func() { |
| 120 | defer func() { |
| 121 | _ = outFile.Close() |
| 122 | _ = errFile.Close() |
| 123 | os.Stdout = oldOut |
| 124 | os.Stderr = oldErr |
| 125 | }() |
| 126 | os.Stdout = outFile |
| 127 | os.Stderr = errFile |
| 128 | fn() |
| 129 | }() |
| 130 | |
| 131 | stdout, err := os.ReadFile(outFile.Name()) |
| 132 | if err != nil { |
| 133 | t.Fatalf("read stdout capture: %v", err) |
| 134 | } |
| 135 | stderr, err := os.ReadFile(errFile.Name()) |
| 136 | if err != nil { |
| 137 | t.Fatalf("read stderr capture: %v", err) |
| 138 | } |
| 139 | return string(stdout), string(stderr) |
| 140 | } |
| 141 | |
| 142 | func runCodemapWithInput(input string, args ...string) (string, string, error) { |
| 143 | cmd := exec.Command(codemapTestBinaryPath, args...) |
no test coverage detected