@@ -214,3 +214,39 @@ func TestCompileWithConflictingLibrariesInclude(t *testing.T) {
214214 }
215215 require .Contains (t , string (stdout ), expectedOutput [0 ]+ "\n " + expectedOutput [1 ]+ "\n " + expectedOutput [2 ]+ "\n " )
216216}
217+
218+ func TestCompileWithInvalidBuildOptionJson (t * testing.T ) {
219+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
220+ defer env .CleanUp ()
221+
222+ _ , _ , err := cli .Run ("update" )
223+ require .NoError (t , err )
224+
225+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
226+ require .NoError (t , err )
227+
228+ sketchName := "CompileInvalidBuildOptionsJson"
229+ sketchPath := cli .SketchbookDir ().Join (sketchName )
230+ fqbn := "arduino:avr:uno"
231+
232+ // Create a test sketch
233+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
234+ require .NoError (t , err )
235+
236+ // Get the build directory
237+ md5 := md5 .Sum (([]byte (sketchPath .String ())))
238+ sketchPathMd5 := strings .ToUpper (hex .EncodeToString (md5 [:]))
239+ require .NotEmpty (t , sketchPathMd5 )
240+ buildDir := paths .TempDir ().Join ("arduino-sketch-" + sketchPathMd5 )
241+
242+ _ , _ , err = cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--verbose" )
243+ require .NoError (t , err )
244+
245+ // Breaks the build.options.json file
246+ buildOptionsJson := buildDir .Join ("build.options.json" )
247+ err = buildOptionsJson .WriteFile ([]byte ("invalid json" ))
248+ require .NoError (t , err )
249+
250+ _ , _ , err = cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--verbose" )
251+ require .NoError (t , err )
252+ }
0 commit comments