@@ -30,6 +30,7 @@ import (
30
30
31
31
"github.com/spf13/viper"
32
32
33
+ "github.com/arduino/arduino-cli/cli/errorcodes"
33
34
"github.com/arduino/arduino-cli/cli/feedback"
34
35
35
36
"bou.ke/monkey"
@@ -42,26 +43,28 @@ var (
42
43
// Redirecting stdOut so we can analyze output line by
43
44
// line and check with what we want.
44
45
stdOut = os .Stdout
46
+ stdErr = os .Stderr
45
47
46
48
currDownloadDir string
47
49
currDataDir string
48
50
currUserDir string
49
51
)
50
52
51
- type stdOutRedirect struct {
53
+ type outputRedirect struct {
52
54
tempFile * os.File
53
55
}
54
56
55
- func (grabber * stdOutRedirect ) Open () {
57
+ func (grabber * outputRedirect ) Open () {
56
58
tempFile , err := ioutil .TempFile (os .TempDir (), "test" )
57
59
if err != nil {
58
60
panic ("Opening temp output file" )
59
61
}
60
62
os .Stdout = tempFile
63
+ os .Stderr = tempFile
61
64
grabber .tempFile = tempFile
62
65
}
63
66
64
- func (grabber * stdOutRedirect ) GetOutput () []byte {
67
+ func (grabber * outputRedirect ) GetOutput () []byte {
65
68
_ , err := grabber .tempFile .Seek (0 , 0 )
66
69
if err != nil {
67
70
panic ("Rewinding temp output file" )
@@ -75,13 +78,14 @@ func (grabber *stdOutRedirect) GetOutput() []byte {
75
78
return output
76
79
}
77
80
78
- func (grabber * stdOutRedirect ) Close () {
81
+ func (grabber * outputRedirect ) Close () {
79
82
grabber .tempFile .Close ()
80
83
err := os .Remove (grabber .tempFile .Name ())
81
84
if err != nil {
82
85
panic ("Removing temp output file" )
83
86
}
84
87
os .Stdout = stdOut
88
+ os .Stderr = stdErr
85
89
}
86
90
87
91
func TestMain (m * testing.M ) {
@@ -136,7 +140,7 @@ func executeWithArgs(args ...string) (int, []byte) {
136
140
137
141
// This closure is here because we won't that the defer are executed after the end of the "executeWithArgs" method
138
142
func () {
139
- redirect := & stdOutRedirect {}
143
+ redirect := & outputRedirect {}
140
144
redirect .Open ()
141
145
// re-init feedback so it'll write to our grabber
142
146
feedback .SetDefaultFeedback (feedback .New (os .Stdout , os .Stdout , feedback .Text ))
@@ -170,7 +174,9 @@ func executeWithArgs(args ...string) (int, []byte) {
170
174
ArduinoCli .ResetFlags ()
171
175
createCliCommandTree (ArduinoCli )
172
176
ArduinoCli .SetArgs (args )
173
- ArduinoCli .Execute ()
177
+ if err := ArduinoCli .Execute (); err != nil {
178
+ exitCode = errorcodes .ErrGeneric
179
+ }
174
180
}()
175
181
176
182
return exitCode , output
@@ -307,7 +313,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
307
313
// Build sketch without FQBN
308
314
exitCode , d = executeWithArgs ("compile" , sketchPath )
309
315
require .NotZero (t , exitCode )
310
- require .Contains (t , string (d ), "no FQBN provided " )
316
+ require .Contains (t , string (d ), "required flag(s) \" fqbn \" not set " )
311
317
312
318
// Build sketch for arduino:avr:uno
313
319
exitCode , d = executeWithArgs ("compile" , "-b" , "arduino:avr:uno" , sketchPath )
0 commit comments