@@ -34,7 +34,6 @@ import (
3434 "arduino.cc/builder/constants"
3535 "arduino.cc/builder/types"
3636 "github.com/stretchr/testify/require"
37- "io/ioutil"
3837 "os"
3938 "path/filepath"
4039 "strings"
@@ -117,11 +116,7 @@ func TestPrototypesAdderSketchWithIfDef(t *testing.T) {
117116 NoError (t , err )
118117 }
119118
120- bytes , err := ioutil .ReadFile (filepath .Join ("sketch2" , "SketchWithIfDef.preprocessed.txt" ))
121- NoError (t , err )
122-
123- preprocessed := string (bytes )
124-
119+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch2" , "SketchWithIfDef.preprocessed.txt" ), context )
125120 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
126121}
127122
@@ -161,11 +156,7 @@ func TestPrototypesAdderBaladuino(t *testing.T) {
161156 NoError (t , err )
162157 }
163158
164- bytes , err := ioutil .ReadFile (filepath .Join ("sketch3" , "Baladuino.preprocessed.txt" ))
165- NoError (t , err )
166-
167- preprocessed := string (bytes )
168-
159+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch3" , "Baladuino.preprocessed.txt" ), context )
169160 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
170161}
171162
@@ -205,11 +196,7 @@ func TestPrototypesAdderCharWithEscapedDoubleQuote(t *testing.T) {
205196 NoError (t , err )
206197 }
207198
208- bytes , err := ioutil .ReadFile (filepath .Join ("sketch4" , "CharWithEscapedDoubleQuote.preprocessed.txt" ))
209- NoError (t , err )
210-
211- preprocessed := string (bytes )
212-
199+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch4" , "CharWithEscapedDoubleQuote.preprocessed.txt" ), context )
213200 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
214201}
215202
@@ -249,11 +236,7 @@ func TestPrototypesAdderIncludeBetweenMultilineComment(t *testing.T) {
249236 NoError (t , err )
250237 }
251238
252- bytes , err := ioutil .ReadFile (filepath .Join ("sketch5" , "IncludeBetweenMultilineComment.preprocessed.txt" ))
253- NoError (t , err )
254-
255- preprocessed := string (bytes )
256-
239+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch5" , "IncludeBetweenMultilineComment.preprocessed.txt" ), context )
257240 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
258241}
259242
@@ -293,11 +276,7 @@ func TestPrototypesAdderLineContinuations(t *testing.T) {
293276 NoError (t , err )
294277 }
295278
296- bytes , err := ioutil .ReadFile (filepath .Join ("sketch6" , "LineContinuations.preprocessed.txt" ))
297- NoError (t , err )
298-
299- preprocessed := string (bytes )
300-
279+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch6" , "LineContinuations.preprocessed.txt" ), context )
301280 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
302281}
303282
@@ -337,11 +316,7 @@ func TestPrototypesAdderStringWithComment(t *testing.T) {
337316 NoError (t , err )
338317 }
339318
340- bytes , err := ioutil .ReadFile (filepath .Join ("sketch7" , "StringWithComment.preprocessed.txt" ))
341- NoError (t , err )
342-
343- preprocessed := string (bytes )
344-
319+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch7" , "StringWithComment.preprocessed.txt" ), context )
345320 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
346321}
347322
@@ -381,11 +356,7 @@ func TestPrototypesAdderSketchWithStruct(t *testing.T) {
381356 NoError (t , err )
382357 }
383358
384- bytes , err := ioutil .ReadFile (filepath .Join ("sketch8" , "SketchWithStruct.preprocessed.txt" ))
385- NoError (t , err )
386-
387- preprocessed := string (bytes )
388-
359+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch8" , "SketchWithStruct.preprocessed.txt" ), context )
389360 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
390361}
391362
@@ -428,11 +399,7 @@ func TestPrototypesAdderSketchWithConfig(t *testing.T) {
428399 require .Equal (t , "#include <Arduino.h>\n #line 1\n " , context [constants .CTX_INCLUDE_SECTION ].(string ))
429400 require .Equal (t , "void setup();\n void loop();\n #line 13\n " , context [constants .CTX_PROTOTYPE_SECTION ].(string ))
430401
431- bytes , err := ioutil .ReadFile (filepath .Join ("sketch_with_config" , "sketch_with_config.preprocessed.txt" ))
432- NoError (t , err )
433-
434- preprocessed := string (bytes )
435-
402+ preprocessed := LoadAndInterpolate (t , filepath .Join ("sketch_with_config" , "sketch_with_config.preprocessed.txt" ), context )
436403 require .Equal (t , preprocessed , strings .Replace (context [constants .CTX_SOURCE ].(string ), "\r \n " , "\n " , - 1 ))
437404}
438405
0 commit comments