| 165 | } |
| 166 | |
| 167 | func formatTestOutput(testOutput string, cfg RenderSettings) string { |
| 168 | if cfg.Formatter == "" { |
| 169 | return testOutput |
| 170 | } |
| 171 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 172 | defer cancel() |
| 173 | var shell []string |
| 174 | if runtime.GOOS == "windows" { |
| 175 | shell = []string{ |
| 176 | "cmd.exe", |
| 177 | "/C", |
| 178 | cfg.Formatter, |
| 179 | } |
| 180 | } else { |
| 181 | shell = []string{ |
| 182 | "/bin/bash", |
| 183 | "-c", |
| 184 | cfg.Formatter, |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | stdout := &bytes.Buffer{} |
| 189 | stderr := &bytes.Buffer{} |
| 190 | |
| 191 | run := exec.CommandContext(ctx, shell[0], shell[1:]...) |
| 192 | run.Stdin = bytes.NewReader([]byte(testOutput)) |
| 193 | run.Stdout = stdout |
| 194 | run.Stderr = stderr |
| 195 | if err := run.Run(); err != nil { |
| 196 | panic(fmt.Errorf( |
| 197 | "failed to run test output formatter '%s', stderr was: %s (%w)", |
| 198 | strings.Join(shell, " "), |
| 199 | stderr.String(), |
| 200 | err, |
| 201 | )) |
| 202 | } |
| 203 | return stdout.String() |
| 204 | } |
| 205 | |
| 206 | func renderTemplate(templateName string, templateText []byte, data interface{}) []byte { |
| 207 | result := bytes.Buffer{} |