@@ -28,6 +28,7 @@ import (
28
28
"github.com/arduino/arduino-cli/internal/integrationtest"
29
29
"github.com/arduino/go-paths-helper"
30
30
"github.com/stretchr/testify/require"
31
+ "go.bug.st/testifyjson/requirejson"
31
32
"golang.org/x/exp/slices"
32
33
)
33
34
@@ -954,3 +955,61 @@ func TestMergeSketchWithBootloader(t *testing.T) {
954
955
require .Contains (t , mergedSketchHex , ":100000000C9434000C9446000C9446000C9446006A\n " )
955
956
require .True (t , strings .HasSuffix (mergedSketchHex , ":00000001FF\n " ))
956
957
}
958
+
959
+ func TestBuildOptionsFile (t * testing.T ) {
960
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
961
+ defer env .CleanUp ()
962
+
963
+ sketchPath := cli .CopySketch ("sketch_simple" )
964
+ defer sketchPath .RemoveAll ()
965
+
966
+ _ , _ , err := cli .Run ("core" , "install" , "arduino:avr@1.8.6" )
967
+ require .NoError (t , err )
968
+
969
+ buildPath , err := paths .MkTempDir ("" , "arduino-integration-test" )
970
+ require .NoError (t , err )
971
+ defer buildPath .RemoveAll ()
972
+
973
+ // Build first time
974
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-path" , buildPath .String (), sketchPath .String ())
975
+ require .NoError (t , err )
976
+
977
+ exist , err := buildPath .Join ("build.options.json" ).ExistCheck ()
978
+ require .NoError (t , err )
979
+ require .True (t , exist )
980
+
981
+ buildOptionsBytes , err := buildPath .Join ("build.options.json" ).ReadFile ()
982
+ require .NoError (t , err )
983
+
984
+ requirejson .Query (t , buildOptionsBytes , "keys" , `[
985
+ "additionalFiles",
986
+ "builtInToolsFolders",
987
+ "compiler.optimization_flags",
988
+ "customBuildProperties",
989
+ "fqbn",
990
+ "hardwareFolders",
991
+ "otherLibrariesFolders",
992
+ "sketchLocation"
993
+ ]` )
994
+ requirejson .Query (t , buildOptionsBytes , ".fqbn" , `"arduino:avr:uno"` )
995
+ requirejson .Query (t , buildOptionsBytes , ".customBuildProperties" , `"build.warn_data_percentage=75"` )
996
+
997
+ // Recompiling a second time should provide the same result
998
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-path" , buildPath .String (), sketchPath .String ())
999
+ require .NoError (t , err )
1000
+
1001
+ buildOptionsBytes , err = buildPath .Join ("build.options.json" ).ReadFile ()
1002
+ require .NoError (t , err )
1003
+ requirejson .Query (t , buildOptionsBytes , ".customBuildProperties" , `"build.warn_data_percentage=75"` )
1004
+
1005
+ // Recompiling with a new build option must produce a new `build.options.json`
1006
+ _ , _ , err = cli .Run ("compile" , "-b" , "arduino:avr:uno" , "--build-path" , buildPath .String (),
1007
+ "--build-property" , "custom=prop" ,
1008
+ sketchPath .String (),
1009
+ )
1010
+ require .NoError (t , err )
1011
+
1012
+ buildOptionsBytes , err = buildPath .Join ("build.options.json" ).ReadFile ()
1013
+ require .NoError (t , err )
1014
+ requirejson .Query (t , buildOptionsBytes , ".customBuildProperties" , `"custom=prop,build.warn_data_percentage=75"` )
1015
+ }
0 commit comments