@@ -354,16 +354,19 @@ func (cli *ArduinoCLI) RunWithCustomInput(in io.Reader, args ...string) ([]byte,
354354 return stdoutBuf .Bytes (), errBuf , err
355355}
356356
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 ) {
358358 if cli .cliConfigPath != nil {
359359 args = append ([]string {"--config-file" , cli .cliConfigPath .String ()}, args ... )
360360 }
361361
362362 // Accumulate all output to terminal and spit-out all at once at the end of the test
363363 // This allows to correctly group test output when running t.Parallel() tests.
364364 terminalOut := new (bytes.Buffer )
365+ terminalErr := new (bytes.Buffer )
365366 defer func () {
366367 fmt .Print (terminalOut .String ())
368+ fmt .Print (terminalErr .String ())
369+ fmt .Fprintln (terminalOut , color .HiBlackString ("<<< Run completed (err = %v)" , _err ))
367370 }()
368371
369372 // Github-actions workflow tags to fold log lines
@@ -401,20 +404,19 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
401404 if stderrBuff == nil {
402405 stderrBuff = io .Discard
403406 }
404- if _ , err := io .Copy (stderrBuff , io .TeeReader (stderr , terminalOut )); err != nil {
405- fmt .Fprintln (terminalOut , color .HiBlackString ("<<< stderr copy error:" ), err )
407+ if _ , err := io .Copy (stderrBuff , io .TeeReader (stderr , terminalErr )); err != nil {
408+ fmt .Fprintln (terminalErr , color .HiBlackString ("<<< stderr copy error:" ), err )
406409 }
407410 }()
408411 if stdinBuff != nil {
409412 go func () {
410413 if _ , err := io .Copy (stdin , stdinBuff ); err != nil {
411- fmt .Fprintln (terminalOut , color .HiBlackString ("<<< stdin copy error:" ), err )
414+ fmt .Fprintln (terminalErr , color .HiBlackString ("<<< stdin copy error:" ), err )
412415 }
413416 }()
414417 }
415418 cliErr := cliProc .WaitWithinContext (ctx )
416419 wg .Wait ()
417- fmt .Fprintln (terminalOut , color .HiBlackString ("<<< Run completed (err = %v)" , cliErr ))
418420
419421 return cliErr
420422}
0 commit comments