@@ -24,6 +24,7 @@ import (
24
24
"github.com/arduino/arduino-cli/internal/integrationtest"
25
25
"github.com/arduino/go-paths-helper"
26
26
"github.com/stretchr/testify/require"
27
+ "go.bug.st/testifyjson/requirejson"
27
28
)
28
29
29
30
func TestCompileWithOutputDirFlag (t * testing.T ) {
@@ -188,6 +189,56 @@ func TestCompileWithExportBinariesEnvVar(t *testing.T) {
188
189
require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.with_bootloader.hex" ).String ())
189
190
}
190
191
192
+ func TestCompileWithExportBinariesConfig (t * testing.T ) {
193
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
194
+ defer env .CleanUp ()
195
+
196
+ // Init the environment explicitly
197
+ _ , _ , err := cli .Run ("core" , "update-index" )
198
+ require .NoError (t , err )
199
+
200
+ // Download latest AVR
201
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
202
+ require .NoError (t , err )
203
+
204
+ sketchName := "CompileWithExportBinariesEnvVar"
205
+ sketchPath := cli .SketchbookDir ().Join (sketchName )
206
+ fqbn := "arduino:avr:uno"
207
+
208
+ // Create a test sketch
209
+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
210
+ require .NoError (t , err )
211
+
212
+ // Create settings with export binaries set to true
213
+ envVar := cli .GetDefaultEnv ()
214
+ envVar ["ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES" ] = "true"
215
+ _ , _ , err = cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
216
+ require .NoError (t , err )
217
+
218
+ // Test if arduino-cli config file written in the previous run has the `always_export_binaries` flag set.
219
+ stdout , _ , err := cli .Run ("config" , "dump" , "--format" , "json" )
220
+ require .NoError (t , err )
221
+ requirejson .Contains (t , stdout , `
222
+ {
223
+ "sketch": {
224
+ "always_export_binaries": "true"
225
+ }
226
+ }` )
227
+
228
+ // Test compilation with export binaries env var set
229
+ _ , _ , err = cli .Run ("compile" , "-b" , fqbn , sketchPath .String ())
230
+ require .NoError (t , err )
231
+ require .DirExists (t , sketchPath .Join ("build" ).String ())
232
+
233
+ // Verifies binaries are exported when export binaries env var is set
234
+ fqbn = strings .ReplaceAll (fqbn , ":" , "." )
235
+ require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.eep" ).String ())
236
+ require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.elf" ).String ())
237
+ require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.hex" ).String ())
238
+ require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.with_bootloader.bin" ).String ())
239
+ require .FileExists (t , sketchPath .Join ("build" , fqbn , sketchName + ".ino.with_bootloader.hex" ).String ())
240
+ }
241
+
191
242
func TestCompileWithInvalidUrl (t * testing.T ) {
192
243
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
193
244
defer env .CleanUp ()
0 commit comments