@@ -299,13 +299,20 @@ func (cli *ArduinoCLI) run(stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader
299
299
args = append ([]string {"--config-file" , cli .cliConfigPath .String ()}, args ... )
300
300
}
301
301
302
+ // Accumulate all output to terminal and spit-out all at once at the end of the test
303
+ // This allows to correctly group test output when running t.Parallel() tests.
304
+ terminalOut := new (bytes.Buffer )
305
+ defer func () {
306
+ fmt .Print (terminalOut .String ())
307
+ }()
308
+
302
309
// Github-actions workflow tags to fold log lines
303
310
if os .Getenv ("GITHUB_ACTIONS" ) != "" {
304
- fmt .Printf ( "::group::Running %s\n " , strings .Join (args , " " ))
305
- defer fmt .Println ( "::endgroup::" )
311
+ fmt .Fprintf ( terminalOut , "::group::Running %s\n " , strings .Join (args , " " ))
312
+ defer fmt .Fprintln ( terminalOut , "::endgroup::" )
306
313
}
307
314
308
- fmt .Println ( color .HiBlackString (">>> Running: " ) + color .HiYellowString ("%s %s" , cli .path , strings .Join (args , " " )))
315
+ fmt .Fprintln ( terminalOut , color .HiBlackString (">>> Running: " )+ color .HiYellowString ("%s %s" , cli .path , strings .Join (args , " " )))
309
316
cliProc , err := executils .NewProcessFromPath (cli .convertEnvForExecutils (env ), cli .path , args ... )
310
317
cli .t .NoError (err )
311
318
stdout , err := cliProc .StdoutPipe ()
@@ -325,29 +332,29 @@ func (cli *ArduinoCLI) run(stdoutBuff, stderrBuff io.Writer, stdinBuff io.Reader
325
332
if stdoutBuff == nil {
326
333
stdoutBuff = io .Discard
327
334
}
328
- if _ , err := io .Copy (stdoutBuff , io .TeeReader (stdout , os . Stdout )); err != nil {
329
- fmt .Println ( color .HiBlackString ("<<< stdout copy error:" ), err )
335
+ if _ , err := io .Copy (stdoutBuff , io .TeeReader (stdout , terminalOut )); err != nil {
336
+ fmt .Fprintln ( terminalOut , color .HiBlackString ("<<< stdout copy error:" ), err )
330
337
}
331
338
}()
332
339
go func () {
333
340
defer wg .Done ()
334
341
if stderrBuff == nil {
335
342
stderrBuff = io .Discard
336
343
}
337
- if _ , err := io .Copy (stderrBuff , io .TeeReader (stderr , os . Stderr )); err != nil {
338
- fmt .Println ( color .HiBlackString ("<<< stderr copy error:" ), err )
344
+ if _ , err := io .Copy (stderrBuff , io .TeeReader (stderr , terminalOut )); err != nil {
345
+ fmt .Fprintln ( terminalOut , color .HiBlackString ("<<< stderr copy error:" ), err )
339
346
}
340
347
}()
341
348
if stdinBuff != nil {
342
349
go func () {
343
350
if _ , err := io .Copy (stdin , stdinBuff ); err != nil {
344
- fmt .Println ( color .HiBlackString ("<<< stdin copy error:" ), err )
351
+ fmt .Fprintln ( terminalOut , color .HiBlackString ("<<< stdin copy error:" ), err )
345
352
}
346
353
}()
347
354
}
348
355
wg .Wait ()
349
356
cliErr := cliProc .Wait ()
350
- fmt .Println ( color .HiBlackString ("<<< Run completed (err = %v)" , cliErr ))
357
+ fmt .Fprintln ( terminalOut , color .HiBlackString ("<<< Run completed (err = %v)" , cliErr ))
351
358
352
359
return cliErr
353
360
}
0 commit comments