Skip to content

Commit a64e901

Browse files
author
Massimiliano Pippi
committed
fix tests
1 parent 2775ff0 commit a64e901

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
@@ -27,6 +27,8 @@ import (
2727
"runtime"
2828
"testing"
2929

30+
"github.com/arduino/arduino-cli/cli/feedback"
31+
3032
"bou.ke/monkey"
3133
paths "github.com/arduino/go-paths-helper"
3234
"github.com/stretchr/testify/require"
@@ -145,6 +147,8 @@ func executeWithArgs(args ...string) (int, []byte) {
145147

146148
redirect := &stdOutRedirect{}
147149
redirect.Open()
150+
// re-init feedback so it'll write to our grabber
151+
feedback.SetDefaultFeedback(feedback.New(os.Stdout, os.Stdout))
148152
defer func() {
149153
output = redirect.GetOutput()
150154
redirect.Close()
@@ -293,8 +297,9 @@ func TestUploadIntegration(t *testing.T) {
293297
}
294298

295299
func TestSketchCommandsIntegration(t *testing.T) {
296-
exitCode, _ := executeWithArgs("sketch", "new", "Test")
300+
exitCode, d := executeWithArgs("sketch", "new", "Test")
297301
require.Zero(t, exitCode)
302+
require.Contains(t, string(d), "Sketch created")
298303
}
299304

300305
func TestCompileCommandsIntegration(t *testing.T) {
@@ -316,7 +321,6 @@ func TestCompileCommandsIntegration(t *testing.T) {
316321
// Create a test sketch
317322
exitCode, d := executeWithArgs("sketch", "new", "Test1")
318323
require.Zero(t, exitCode)
319-
require.Contains(t, string(d), "Sketch created")
320324

321325
// Build sketch without FQBN
322326
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)