Skip to content

Commit 9679f1c

Browse files
committed
testsuite: Added colored output to arduino-cli Run helper
1 parent dae3242 commit 9679f1c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

testsuite/arduino-cli.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23+
"strings"
2324
"testing"
2425

2526
"github.com/arduino/arduino-cli/executils"
2627
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2728
"github.com/arduino/go-paths-helper"
29+
"github.com/fatih/color"
2830
"github.com/stretchr/testify/require"
2931
"google.golang.org/grpc"
3032
)
@@ -75,6 +77,7 @@ func (cli *ArduinoCLI) CleanUp() {
7577

7678
// Run executes the given arduino-cli command and returns the output.
7779
func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) {
80+
fmt.Println(color.HiBlackString(">>> Running: ") + color.HiYellowString("%s %s", cli.path, strings.Join(args, " ")))
7881
if cli.cliConfigPath != nil {
7982
args = append([]string{"--config-file", cli.cliConfigPath.String()}, args...)
8083
}
@@ -93,15 +96,17 @@ func (cli *ArduinoCLI) Run(args ...string) ([]byte, []byte, error) {
9396
stdoutCtx, stdoutCancel := context.WithCancel(context.Background())
9497
stderrCtx, stderrCancel := context.WithCancel(context.Background())
9598
go func() {
96-
io.Copy(&stdoutBuf, stdout)
99+
io.Copy(&stdoutBuf, io.TeeReader(stdout, os.Stdout))
97100
stdoutCancel()
98101
}()
99102
go func() {
100-
io.Copy(&stderrBuf, stderr)
103+
io.Copy(&stderrBuf, io.TeeReader(stderr, os.Stderr))
101104
stderrCancel()
102105
}()
103106
cliErr := cliProc.Wait()
104107
<-stdoutCtx.Done()
105108
<-stderrCtx.Done()
109+
fmt.Println(color.HiBlackString("<<< Run completed (err = %v)", cliErr))
110+
106111
return stdoutBuf.Bytes(), stderrBuf.Bytes(), cliErr
107112
}

0 commit comments

Comments
 (0)