@@ -63,6 +63,11 @@ func TestCompileOfProblematicSketches(t *testing.T) {
63
63
_ , _ , err = cli .Run ("lib" , "install" , "CapacitiveSensor@0.5" )
64
64
require .NoError (t , err )
65
65
66
+ // Install custom hardware required for tests
67
+ customHwDir , err := paths .New ("testdata" , "user_hardware" ).Abs ()
68
+ require .NoError (t , err )
69
+ require .NoError (t , customHwDir .CopyDirTo (cli .SketchbookDir ().Join ("hardware" )))
70
+
66
71
integrationtest.CLISubtests {
67
72
{"SketchWithInlineFunction" , testBuilderSketchWithInlineFunction },
68
73
{"SketchWithConst" , testBuilderSketchWithConst },
@@ -98,6 +103,7 @@ func TestCompileOfProblematicSketches(t *testing.T) {
98
103
{"USBHostExample" , testBuilderUSBHostExample },
99
104
{"SketchWithConflictingLibraries" , testBuilderSketchWithConflictingLibraries },
100
105
{"SketchLibraryProvidesAllIncludes" , testBuilderSketchLibraryProvidesAllIncludes },
106
+ {"UserHardware" , testBuilderWithUserHardware },
101
107
}.Run (t , env , cli )
102
108
}
103
109
@@ -328,7 +334,7 @@ func testBuilderBridgeExample(t *testing.T, env *integrationtest.Environment, cl
328
334
require .Equal (t , "Bridge" , libs [0 ].Name )
329
335
330
336
// Build again...
331
- out2 , err2 := tryBuild (t , env , cli , "arduino:avr:leonardo" , "no-clean" )
337
+ out2 , err2 := tryBuild (t , env , cli , "arduino:avr:leonardo" , & buildOptions { NoClean : true } )
332
338
require .NoError (t , err2 )
333
339
buildPath2 := out2 .BuilderResult .BuildPath
334
340
require .True (t , buildPath2 .Join ("core" , "HardwareSerial.cpp.o" ).Exist ())
@@ -340,7 +346,7 @@ func testBuilderBridgeExample(t *testing.T, env *integrationtest.Environment, cl
340
346
341
347
t .Run ("BuildForSAM" , func (t * testing.T ) {
342
348
// Build again for SAM...
343
- out , err := tryBuild (t , env , cli , "arduino:sam:arduino_due_x_dbg" , "all-warnings" )
349
+ out , err := tryBuild (t , env , cli , "arduino:sam:arduino_due_x_dbg" , & buildOptions { AllWarnings : true } )
344
350
require .NoError (t , err )
345
351
346
352
buildPath := out .BuilderResult .BuildPath
@@ -363,7 +369,7 @@ func testBuilderBridgeExample(t *testing.T, env *integrationtest.Environment, cl
363
369
364
370
t .Run ("BuildForRedBearAVR" , func (t * testing.T ) {
365
371
// Build again for RedBearLab...
366
- out , err := tryBuild (t , env , cli , "RedBear:avr:blend" , "verbose" )
372
+ out , err := tryBuild (t , env , cli , "RedBear:avr:blend" , & buildOptions { Verbose : true } )
367
373
require .NoError (t , err )
368
374
buildPath := out .BuilderResult .BuildPath
369
375
require .True (t , buildPath .Join ("core" , "HardwareSerial.cpp.o" ).Exist ())
@@ -382,7 +388,7 @@ func testBuilderBridgeExample(t *testing.T, env *integrationtest.Environment, cl
382
388
require .NoError (t , buildPath .Join ("libraries" , "SPI" ).MkdirAll ())
383
389
384
390
// Build again...
385
- _ , err = tryBuild (t , env , cli , "arduino:avr:leonardo" , "no-clean" )
391
+ _ , err = tryBuild (t , env , cli , "arduino:avr:leonardo" , & buildOptions { NoClean : true } )
386
392
require .NoError (t , err )
387
393
388
394
require .False (t , buildPath .Join ("libraries" , "SPI" ).Exist ())
@@ -566,6 +572,39 @@ func testBuilderSketchLibraryProvidesAllIncludes(t *testing.T, env *integrationt
566
572
})
567
573
}
568
574
575
+ func testBuilderWithUserHardware (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
576
+ coreSPILib , err := cli .SketchbookDir ().Join ("hardware" , "my_avr_platform" , "avr" , "libraries" , "SPI" ).Abs ()
577
+ require .NoError (t , err )
578
+ sketchPath := coreSPILib .Join ("examples" , "BarometricPressureSensor" , "BarometricPressureSensor.ino" )
579
+
580
+ t .Run ("TestIncludesToIncludeFoldersDuplicateLibs" , func (t * testing.T ) {
581
+ out , err := tryBuild (t , env , cli , "my_avr_platform:avr:custom_yun" , & buildOptions {
582
+ Sketch : sketchPath ,
583
+ NoTestLibraries : true ,
584
+ })
585
+ require .NoError (t , err )
586
+
587
+ importedLibraries := out .BuilderResult .UsedLibraries
588
+ require .Equal (t , 1 , len (importedLibraries ))
589
+ require .Equal (t , "SPI" , importedLibraries [0 ].Name )
590
+ require .True (t , importedLibraries [0 ].SourceDir .EquivalentTo (coreSPILib ))
591
+ })
592
+
593
+ t .Run ("TestIncludesToIncludeFoldersDuplicateLibsWithConflictingLibsOutsideOfPlatform" , func (t * testing.T ) {
594
+ SPILib , err := paths .New ("testdata" , "libraries" , "SPI" ).Abs ()
595
+ require .NoError (t , err )
596
+ out , err := tryBuild (t , env , cli , "my_avr_platform:avr:custom_yun" , & buildOptions {
597
+ Sketch : sketchPath ,
598
+ })
599
+ require .NoError (t , err )
600
+
601
+ importedLibraries := out .BuilderResult .UsedLibraries
602
+ require .Equal (t , 1 , len (importedLibraries ))
603
+ require .Equal (t , "SPI" , importedLibraries [0 ].Name )
604
+ require .True (t , importedLibraries [0 ].SourceDir .EquivalentTo (SPILib ))
605
+ })
606
+ }
607
+
569
608
func tryBuildAvrLeonardo (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
570
609
_ , err := tryBuild (t , env , cli , "arduino:avr:leonardo" )
571
610
require .NoError (t , err )
@@ -586,25 +625,49 @@ type builderLibrary struct {
586
625
SourceDir * paths.Path `json:"source_dir"`
587
626
}
588
627
589
- func tryBuild (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI , fqbn string , options ... string ) (* builderOutput , error ) {
590
- subTestName := strings .Split (t .Name (), "/" )[1 ]
591
- sketchPath , err := paths .New ("testdata" , subTestName ).Abs ()
592
- require .NoError (t , err )
593
- libsPath , err := paths .New ("testdata" , "libraries" ).Abs ()
594
- require .NoError (t , err )
628
+ type buildOptions struct {
629
+ Sketch * paths.Path
630
+ NoTestLibraries bool
631
+ CustomLibPath * paths.Path
632
+ NoClean bool
633
+ AllWarnings bool
634
+ Verbose bool
635
+ }
636
+
637
+ func tryBuild (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI , fqbn string , optionsArg ... * buildOptions ) (* builderOutput , error ) {
638
+ var options * buildOptions
639
+ if len (optionsArg ) == 0 {
640
+ options = & buildOptions {}
641
+ } else {
642
+ require .Len (t , optionsArg , 1 )
643
+ options = optionsArg [0 ]
644
+ }
645
+ if options .Sketch == nil {
646
+ subTestName := strings .Split (t .Name (), "/" )[1 ]
647
+ sketchPath , err := paths .New ("testdata" , subTestName ).Abs ()
648
+ require .NoError (t , err )
649
+ options .Sketch = sketchPath
650
+ }
595
651
args := []string {
596
652
"compile" ,
597
653
"-b" , fqbn ,
598
- "--libraries" , libsPath .String (),
599
654
"--format" , "json" ,
600
- sketchPath .String ()}
601
- if ! slices .Contains (options , "no-clean" ) {
655
+ options .Sketch .String ()}
656
+ if ! options .NoTestLibraries {
657
+ libsPath , err := paths .New ("testdata" , "libraries" ).Abs ()
658
+ require .NoError (t , err )
659
+ args = append (args , "--libraries" , libsPath .String ())
660
+ }
661
+ if options .CustomLibPath != nil {
662
+ args = append (args , "--library" , options .CustomLibPath .String ())
663
+ }
664
+ if ! options .NoClean {
602
665
args = append (args , "--clean" )
603
666
}
604
- if slices . Contains ( options , "all-warnings" ) {
667
+ if options . AllWarnings {
605
668
args = append (args , "--warnings" , "all" )
606
669
}
607
- if slices . Contains ( options , "verbose" ) {
670
+ if options . Verbose {
608
671
args = append (args , "-v" )
609
672
}
610
673
jsonOut , _ , err := cli .Run (args ... )
0 commit comments