@@ -30,6 +30,7 @@ import (
3030
3131 "github.com/spf13/viper"
3232
33+ "github.com/arduino/arduino-cli/cli/errorcodes"
3334 "github.com/arduino/arduino-cli/cli/feedback"
3435
3536 "bou.ke/monkey"
@@ -42,26 +43,28 @@ var (
4243 // Redirecting stdOut so we can analyze output line by
4344 // line and check with what we want.
4445 stdOut = os .Stdout
46+ stdErr = os .Stderr
4547
4648 currDownloadDir string
4749 currDataDir string
4850 currUserDir string
4951)
5052
51- type stdOutRedirect struct {
53+ type outputRedirect struct {
5254 tempFile * os.File
5355}
5456
55- func (grabber * stdOutRedirect ) Open () {
57+ func (grabber * outputRedirect ) Open () {
5658 tempFile , err := ioutil .TempFile (os .TempDir (), "test" )
5759 if err != nil {
5860 panic ("Opening temp output file" )
5961 }
6062 os .Stdout = tempFile
63+ os .Stderr = tempFile
6164 grabber .tempFile = tempFile
6265}
6366
64- func (grabber * stdOutRedirect ) GetOutput () []byte {
67+ func (grabber * outputRedirect ) GetOutput () []byte {
6568 _ , err := grabber .tempFile .Seek (0 , 0 )
6669 if err != nil {
6770 panic ("Rewinding temp output file" )
@@ -75,13 +78,14 @@ func (grabber *stdOutRedirect) GetOutput() []byte {
7578 return output
7679}
7780
78- func (grabber * stdOutRedirect ) Close () {
81+ func (grabber * outputRedirect ) Close () {
7982 grabber .tempFile .Close ()
8083 err := os .Remove (grabber .tempFile .Name ())
8184 if err != nil {
8285 panic ("Removing temp output file" )
8386 }
8487 os .Stdout = stdOut
88+ os .Stderr = stdErr
8589}
8690
8791func TestMain (m * testing.M ) {
@@ -136,7 +140,7 @@ func executeWithArgs(args ...string) (int, []byte) {
136140
137141 // This closure is here because we won't that the defer are executed after the end of the "executeWithArgs" method
138142 func () {
139- redirect := & stdOutRedirect {}
143+ redirect := & outputRedirect {}
140144 redirect .Open ()
141145 // re-init feedback so it'll write to our grabber
142146 feedback .SetDefaultFeedback (feedback .New (os .Stdout , os .Stdout , feedback .Text ))
@@ -170,7 +174,9 @@ func executeWithArgs(args ...string) (int, []byte) {
170174 ArduinoCli .ResetFlags ()
171175 createCliCommandTree (ArduinoCli )
172176 ArduinoCli .SetArgs (args )
173- ArduinoCli .Execute ()
177+ if err := ArduinoCli .Execute (); err != nil {
178+ exitCode = errorcodes .ErrGeneric
179+ }
174180 }()
175181
176182 return exitCode , output
@@ -307,7 +313,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
307313 // Build sketch without FQBN
308314 exitCode , d = executeWithArgs ("compile" , sketchPath )
309315 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 " )
311317
312318 // Build sketch for arduino:avr:uno
313319 exitCode , d = executeWithArgs ("compile" , "-b" , "arduino:avr:uno" , sketchPath )
0 commit comments