Skip to content

Commit 97443b5

Browse files
author
Massimiliano Pippi
committed
fix tests
1 parent f9376d0 commit 97443b5

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

cli/cli_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"path/filepath"
2727
"testing"
2828

29+
"github.com/arduino/arduino-cli/cli/feedback"
30+
2931
"bou.ke/monkey"
3032
paths "github.com/arduino/go-paths-helper"
3133
"github.com/stretchr/testify/require"
@@ -144,6 +146,8 @@ func executeWithArgs(args ...string) (int, []byte) {
144146

145147
redirect := &stdOutRedirect{}
146148
redirect.Open()
149+
// re-init feedback so it'll write to our grabber
150+
feedback.SetDefaultFeedback(feedback.New(os.Stdout, os.Stdout))
147151
defer func() {
148152
output = redirect.GetOutput()
149153
redirect.Close()
@@ -288,8 +292,9 @@ func TestUploadIntegration(t *testing.T) {
288292
}
289293

290294
func TestSketchCommandsIntegration(t *testing.T) {
291-
exitCode, _ := executeWithArgs("sketch", "new", "Test")
295+
exitCode, d := executeWithArgs("sketch", "new", "Test")
292296
require.Zero(t, exitCode)
297+
require.Contains(t, string(d), "Sketch created")
293298
}
294299

295300
func TestCompileCommandsIntegration(t *testing.T) {
@@ -311,7 +316,6 @@ func TestCompileCommandsIntegration(t *testing.T) {
311316
// Create a test sketch
312317
exitCode, d := executeWithArgs("sketch", "new", "Test1")
313318
require.Zero(t, exitCode)
314-
require.Contains(t, string(d), "Sketch created")
315319

316320
// Build sketch without FQBN
317321
test1 := filepath.Join(currSketchbookDir, "Test1")

cli/feedback/exported.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ var (
2323
fb = DefaultFeedback()
2424
)
2525

26+
// SetDefaultFeedback lets callers override the default feedback object. Mostly
27+
// useful for testing.
28+
func SetDefaultFeedback(f *Feedback) {
29+
fb = f
30+
}
31+
2632
// OutputWriter returns the underlying io.Writer to be used when the Print*
2733
// api is not enough
2834
func OutputWriter() io.Writer {

cli/feedback/feedback.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@ type Feedback struct {
3131
err io.Writer
3232
}
3333

34-
// DefaultFeedback provides a basic feedback object to be used as default.
35-
func DefaultFeedback() *Feedback {
34+
// New creates a Feedback instance
35+
func New(out, err io.Writer) *Feedback {
3636
return &Feedback{
37-
out: os.Stdout,
38-
err: os.Stderr,
37+
out: out,
38+
err: err,
3939
}
4040
}
4141

42+
// DefaultFeedback provides a basic feedback object to be used as default.
43+
func DefaultFeedback() *Feedback {
44+
return New(os.Stdout, os.Stderr)
45+
}
46+
4247
// OutputWriter returns the underlying io.Writer to be used when the Print*
4348
// api is not enough.
4449
func (fb *Feedback) OutputWriter() io.Writer {

0 commit comments

Comments
 (0)