@@ -43,25 +43,27 @@ import (
4343 "github.com/stretchr/testify/require"
4444)
4545
46- func TestBuilderEmptySketch ( t * testing. T ) {
47- DownloadCoresAndToolsAndLibraries ( t )
48-
49- ctx := & types. Context {
46+ func prepareBuilderTestContext ( sketchPath , fqbn string ) * types. Context {
47+ return & types. Context {
48+ SketchLocation : sketchPath ,
49+ FQBN : fqbn ,
5050 HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
5151 ToolsFolders : []string {"downloaded_tools" },
5252 BuiltInLibrariesFolders : []string {"downloaded_libraries" },
5353 OtherLibrariesFolders : []string {"libraries" },
54- SketchLocation : filepath .Join ("sketch1" , "sketch.ino" ),
55- FQBN : "arduino:avr:uno" ,
5654 ArduinoAPIVersion : "10600" ,
57- Verbose : true ,
55+ Verbose : false ,
5856 }
57+ }
58+ func TestBuilderEmptySketch (t * testing.T ) {
59+ DownloadCoresAndToolsAndLibraries (t )
60+
61+ ctx := prepareBuilderTestContext (filepath .Join ("sketch1" , "sketch.ino" ), "arduino:avr:uno" )
62+ ctx .DebugLevel = 10
5963
6064 buildPath := SetupBuildPath (t , ctx )
6165 defer os .RemoveAll (buildPath )
6266
63- ctx .DebugLevel = 10
64-
6567 // Cleanup cached core
6668 coreFolder := filepath .Join ("downloaded_hardware" , "arduino" , "avr" )
6769 coreFile := builder_utils .GetCachedCoreArchiveFileName (ctx .FQBN , coreFolder )
@@ -87,16 +89,7 @@ func TestBuilderEmptySketch(t *testing.T) {
8789func TestBuilderBridge (t * testing.T ) {
8890 DownloadCoresAndToolsAndLibraries (t )
8991
90- ctx := & types.Context {
91- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
92- ToolsFolders : []string {"downloaded_tools" },
93- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
94- OtherLibrariesFolders : []string {"libraries" },
95- SketchLocation : filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ),
96- FQBN : "arduino:avr:leonardo" ,
97- ArduinoAPIVersion : "10600" ,
98- Verbose : true ,
99- }
92+ ctx := prepareBuilderTestContext (filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ), "arduino:avr:leonardo" )
10093
10194 buildPath := SetupBuildPath (t , ctx )
10295 defer os .RemoveAll (buildPath )
@@ -128,15 +121,7 @@ func TestBuilderBridge(t *testing.T) {
128121func TestBuilderSketchWithConfig (t * testing.T ) {
129122 DownloadCoresAndToolsAndLibraries (t )
130123
131- ctx := & types.Context {
132- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
133- ToolsFolders : []string {"downloaded_tools" },
134- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
135- OtherLibrariesFolders : []string {"libraries" },
136- SketchLocation : filepath .Join ("sketch_with_config" , "sketch_with_config.ino" ),
137- FQBN : "arduino:avr:leonardo" ,
138- ArduinoAPIVersion : "10600" ,
139- }
124+ ctx := prepareBuilderTestContext (filepath .Join ("sketch_with_config" , "sketch_with_config.ino" ), "arduino:avr:leonardo" )
140125
141126 buildPath := SetupBuildPath (t , ctx )
142127 defer os .RemoveAll (buildPath )
@@ -168,15 +153,7 @@ func TestBuilderSketchWithConfig(t *testing.T) {
168153func TestBuilderBridgeTwice (t * testing.T ) {
169154 DownloadCoresAndToolsAndLibraries (t )
170155
171- ctx := & types.Context {
172- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
173- ToolsFolders : []string {"downloaded_tools" },
174- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
175- OtherLibrariesFolders : []string {"libraries" },
176- SketchLocation : filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ),
177- FQBN : "arduino:avr:leonardo" ,
178- ArduinoAPIVersion : "10600" ,
179- }
156+ ctx := prepareBuilderTestContext (filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ), "arduino:avr:leonardo" )
180157
181158 buildPath := SetupBuildPath (t , ctx )
182159 defer os .RemoveAll (buildPath )
@@ -213,15 +190,7 @@ func TestBuilderBridgeTwice(t *testing.T) {
213190func TestBuilderBridgeSAM (t * testing.T ) {
214191 DownloadCoresAndToolsAndLibraries (t )
215192
216- ctx := & types.Context {
217- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
218- ToolsFolders : []string {"downloaded_tools" },
219- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
220- OtherLibrariesFolders : []string {"libraries" },
221- SketchLocation : filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ),
222- FQBN : "arduino:sam:arduino_due_x_dbg" ,
223- ArduinoAPIVersion : "10600" ,
224- }
193+ ctx := prepareBuilderTestContext (filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ), "arduino:sam:arduino_due_x_dbg" )
225194
226195 buildPath := SetupBuildPath (t , ctx )
227196 defer os .RemoveAll (buildPath )
@@ -264,16 +233,9 @@ func TestBuilderBridgeSAM(t *testing.T) {
264233func TestBuilderBridgeRedBearLab (t * testing.T ) {
265234 DownloadCoresAndToolsAndLibraries (t )
266235
267- ctx := & types.Context {
268- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" , "downloaded_board_manager_stuff" },
269- ToolsFolders : []string {"downloaded_tools" , "downloaded_board_manager_stuff" },
270- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
271- OtherLibrariesFolders : []string {"libraries" },
272- SketchLocation : filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ),
273- FQBN : "RedBearLab:avr:blend" ,
274- ArduinoAPIVersion : "10600" ,
275- }
276-
236+ ctx := prepareBuilderTestContext (filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ), "RedBearLab:avr:blend" )
237+ ctx .HardwareFolders = append (ctx .HardwareFolders , "downloaded_board_manager_stuff" )
238+ ctx .ToolsFolders = append (ctx .ToolsFolders , "downloaded_board_manager_stuff" )
277239 buildPath := SetupBuildPath (t , ctx )
278240 defer os .RemoveAll (buildPath )
279241
@@ -304,15 +266,9 @@ func TestBuilderBridgeRedBearLab(t *testing.T) {
304266func TestBuilderSketchNoFunctions (t * testing.T ) {
305267 DownloadCoresAndToolsAndLibraries (t )
306268
307- ctx := & types.Context {
308- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" , "downloaded_board_manager_stuff" },
309- ToolsFolders : []string {"downloaded_tools" , "downloaded_board_manager_stuff" },
310- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
311- OtherLibrariesFolders : []string {"libraries" },
312- SketchLocation : filepath .Join ("sketch_no_functions" , "main.ino" ),
313- FQBN : "RedBearLab:avr:blend" ,
314- ArduinoAPIVersion : "10600" ,
315- }
269+ ctx := prepareBuilderTestContext (filepath .Join ("sketch_no_functions" , "main.ino" ), "RedBearLab:avr:blend" )
270+ ctx .HardwareFolders = append (ctx .HardwareFolders , "downloaded_board_manager_stuff" )
271+ ctx .ToolsFolders = append (ctx .ToolsFolders , "downloaded_board_manager_stuff" )
316272
317273 buildPath := SetupBuildPath (t , ctx )
318274 defer os .RemoveAll (buildPath )
@@ -325,15 +281,9 @@ func TestBuilderSketchNoFunctions(t *testing.T) {
325281func TestBuilderSketchWithBackup (t * testing.T ) {
326282 DownloadCoresAndToolsAndLibraries (t )
327283
328- ctx := & types.Context {
329- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" , "downloaded_board_manager_stuff" },
330- ToolsFolders : []string {"downloaded_tools" , "downloaded_board_manager_stuff" },
331- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
332- OtherLibrariesFolders : []string {"libraries" },
333- SketchLocation : filepath .Join ("sketch_with_backup_files" , "sketch.ino" ),
334- FQBN : "arduino:avr:uno" ,
335- ArduinoAPIVersion : "10600" ,
336- }
284+ ctx := prepareBuilderTestContext (filepath .Join ("sketch_with_backup_files" , "sketch.ino" ), "arduino:avr:uno" )
285+ ctx .HardwareFolders = append (ctx .HardwareFolders , "downloaded_board_manager_stuff" )
286+ ctx .ToolsFolders = append (ctx .ToolsFolders , "downloaded_board_manager_stuff" )
337287
338288 buildPath := SetupBuildPath (t , ctx )
339289 defer os .RemoveAll (buildPath )
@@ -346,15 +296,7 @@ func TestBuilderSketchWithBackup(t *testing.T) {
346296func TestBuilderSketchWithOldLib (t * testing.T ) {
347297 DownloadCoresAndToolsAndLibraries (t )
348298
349- ctx := & types.Context {
350- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
351- ToolsFolders : []string {"downloaded_tools" },
352- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
353- OtherLibrariesFolders : []string {"libraries" },
354- SketchLocation : filepath .Join ("sketch_with_old_lib" , "sketch.ino" ),
355- FQBN : "arduino:avr:uno" ,
356- ArduinoAPIVersion : "10600" ,
357- }
299+ ctx := prepareBuilderTestContext (filepath .Join ("sketch_with_old_lib" , "sketch.ino" ), "arduino:avr:uno" )
358300
359301 buildPath := SetupBuildPath (t , ctx )
360302 defer os .RemoveAll (buildPath )
@@ -367,15 +309,7 @@ func TestBuilderSketchWithOldLib(t *testing.T) {
367309func TestBuilderSketchWithSubfolders (t * testing.T ) {
368310 DownloadCoresAndToolsAndLibraries (t )
369311
370- ctx := & types.Context {
371- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
372- ToolsFolders : []string {"downloaded_tools" },
373- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
374- OtherLibrariesFolders : []string {"libraries" },
375- SketchLocation : filepath .Join ("sketch_with_subfolders" , "sketch_with_subfolders.ino" ),
376- FQBN : "arduino:avr:uno" ,
377- ArduinoAPIVersion : "10600" ,
378- }
312+ ctx := prepareBuilderTestContext (filepath .Join ("sketch_with_subfolders" , "sketch_with_subfolders.ino" ), "arduino:avr:uno" )
379313
380314 buildPath := SetupBuildPath (t , ctx )
381315 defer os .RemoveAll (buildPath )
@@ -388,15 +322,7 @@ func TestBuilderSketchWithSubfolders(t *testing.T) {
388322func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary (t * testing.T ) {
389323 DownloadCoresAndToolsAndLibraries (t )
390324
391- ctx := & types.Context {
392- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
393- ToolsFolders : []string {"downloaded_tools" },
394- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
395- OtherLibrariesFolders : []string {"libraries" },
396- SketchLocation : filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ),
397- FQBN : "arduino:avr:leonardo" ,
398- ArduinoAPIVersion : "10600" ,
399- }
325+ ctx := prepareBuilderTestContext (filepath .Join ("downloaded_libraries" , "Bridge" , "examples" , "Bridge" , "Bridge.ino" ), "arduino:avr:leonardo" )
400326
401327 buildPath := SetupBuildPath (t , ctx )
402328 defer os .RemoveAll (buildPath )
@@ -417,16 +343,7 @@ func TestBuilderSketchBuildPathContainsUnusedPreviouslyCompiledLibrary(t *testin
417343func TestBuilderWithBuildPathInSketchDir (t * testing.T ) {
418344 DownloadCoresAndToolsAndLibraries (t )
419345
420- ctx := & types.Context {
421- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
422- ToolsFolders : []string {"downloaded_tools" },
423- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
424- OtherLibrariesFolders : []string {"libraries" },
425- SketchLocation : filepath .Join ("sketch1" , "sketch.ino" ),
426- FQBN : "arduino:avr:uno" ,
427- ArduinoAPIVersion : "10600" ,
428- Verbose : true ,
429- }
346+ ctx := prepareBuilderTestContext (filepath .Join ("sketch1" , "sketch.ino" ), "arduino:avr:uno" )
430347
431348 var err error
432349 ctx .BuildPath , err = filepath .Abs (filepath .Join ("sketch1" , "build" ))
@@ -455,15 +372,8 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
455372func TestBuilderCacheCoreAFile (t * testing.T ) {
456373 DownloadCoresAndToolsAndLibraries (t )
457374
458- ctx := & types.Context {
459- HardwareFolders : []string {filepath .Join (".." , "hardware" ), "hardware" , "downloaded_hardware" },
460- ToolsFolders : []string {"downloaded_tools" },
461- BuiltInLibrariesFolders : []string {"downloaded_libraries" },
462- OtherLibrariesFolders : []string {"libraries" },
463- SketchLocation : filepath .Join ("sketch1" , "sketch.ino" ),
464- FQBN : "arduino:avr:uno" ,
465- ArduinoAPIVersion : "10801" ,
466- }
375+ ctx := prepareBuilderTestContext (filepath .Join ("sketch1" , "sketch.ino" ), "arduino:avr:uno" )
376+
467377 SetupBuildPath (t , ctx )
468378 defer os .RemoveAll (ctx .BuildPath )
469379
0 commit comments