@@ -354,17 +354,15 @@ func (cli *ArduinoCLI) RunWithCustomInput(in io.Reader, args ...string) ([]byte,
354
354
return stdoutBuf .Bytes (), errBuf , err
355
355
}
356
356
357
- func (cli * ArduinoCLI ) run (ctx context.Context , stdoutBuff , stderrBuff io.Writer , stdinBuff io.Reader , env map [string ]string , args ... string ) error {
357
+ func (cli * ArduinoCLI ) run (ctx context.Context , stdoutBuff , stderrBuff io.Writer , stdinBuff io.Reader , env map [string ]string , args ... string ) ( _err error ) {
358
358
if cli .cliConfigPath != nil {
359
359
args = append ([]string {"--config-file" , cli .cliConfigPath .String ()}, args ... )
360
360
}
361
361
362
362
// Accumulate all output to terminal and spit-out all at once at the end of the test
363
363
// This allows to correctly group test output when running t.Parallel() tests.
364
364
terminalOut := new (bytes.Buffer )
365
- defer func () {
366
- fmt .Print (terminalOut .String ())
367
- }()
365
+ terminalErr := new (bytes.Buffer )
368
366
369
367
// Github-actions workflow tags to fold log lines
370
368
if os .Getenv ("GITHUB_ACTIONS" ) != "" {
@@ -373,6 +371,12 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
373
371
}
374
372
375
373
fmt .Fprintln (terminalOut , color .HiBlackString (">>> Running: " )+ color .HiYellowString ("%s %s %s" , cli .path , strings .Join (args , " " ), env ))
374
+ defer func () {
375
+ fmt .Print (terminalOut .String ())
376
+ fmt .Print (terminalErr .String ())
377
+ fmt .Println (color .HiBlackString ("<<< Run completed (err = %v)" , _err ))
378
+ }()
379
+
376
380
cliProc , err := paths .NewProcessFromPath (cli .convertEnvForExecutils (env ), cli .path , args ... )
377
381
cli .t .NoError (err )
378
382
stdout , err := cliProc .StdoutPipe ()
@@ -401,20 +405,19 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
401
405
if stderrBuff == nil {
402
406
stderrBuff = io .Discard
403
407
}
404
- if _ , err := io .Copy (stderrBuff , io .TeeReader (stderr , terminalOut )); err != nil {
405
- fmt .Fprintln (terminalOut , color .HiBlackString ("<<< stderr copy error:" ), err )
408
+ if _ , err := io .Copy (stderrBuff , io .TeeReader (stderr , terminalErr )); err != nil {
409
+ fmt .Fprintln (terminalErr , color .HiBlackString ("<<< stderr copy error:" ), err )
406
410
}
407
411
}()
408
412
if stdinBuff != nil {
409
413
go func () {
410
414
if _ , err := io .Copy (stdin , stdinBuff ); err != nil {
411
- fmt .Fprintln (terminalOut , color .HiBlackString ("<<< stdin copy error:" ), err )
415
+ fmt .Fprintln (terminalErr , color .HiBlackString ("<<< stdin copy error:" ), err )
412
416
}
413
417
}()
414
418
}
415
419
cliErr := cliProc .WaitWithinContext (ctx )
416
420
wg .Wait ()
417
- fmt .Fprintln (terminalOut , color .HiBlackString ("<<< Run completed (err = %v)" , cliErr ))
418
421
419
422
return cliErr
420
423
}
0 commit comments