@@ -354,17 +354,15 @@ func (cli *ArduinoCLI) RunWithCustomInput(in io.Reader, args ...string) ([]byte,
354354return 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 ) {
358358if cli .cliConfigPath != nil {
359359args = 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.
364364terminalOut := new (bytes.Buffer )
365- defer func () {
366- fmt .Print (terminalOut .String ())
367- }()
365+ terminalErr := new (bytes.Buffer )
368366
369367// Github-actions workflow tags to fold log lines
370368if os .Getenv ("GITHUB_ACTIONS" )!= "" {
@@ -373,6 +371,12 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
373371}
374372
375373fmt .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+
376380cliProc ,err := paths .NewProcessFromPath (cli .convertEnvForExecutils (env ),cli .path ,args ... )
377381cli .t .NoError (err )
378382stdout ,err := cliProc .StdoutPipe ()
@@ -401,20 +405,19 @@ func (cli *ArduinoCLI) run(ctx context.Context, stdoutBuff, stderrBuff io.Writer
401405if stderrBuff == nil {
402406stderrBuff = io .Discard
403407}
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 )
406410}
407411}()
408412if stdinBuff != nil {
409413go func () {
410414if _ ,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 )
412416}
413417}()
414418}
415419cliErr := cliProc .WaitWithinContext (ctx )
416420wg .Wait ()
417- fmt .Fprintln (terminalOut ,color .HiBlackString ("<<< Run completed (err = %v)" ,cliErr ))
418421
419422return cliErr
420423}