@@ -38,9 +38,19 @@ import (
38
38
"github.com/arduino/arduino-builder/constants"
39
39
"github.com/arduino/arduino-builder/types"
40
40
paths "github.com/arduino/go-paths-helper"
41
+ "github.com/bcmi-labs/arduino-cli/arduino/libraries"
41
42
"github.com/stretchr/testify/require"
42
43
)
43
44
45
+ func extractLibraries (ctx * types.Context ) []* libraries.Library {
46
+ res := []* libraries.Library {}
47
+ for _ , lib := range ctx .LibrariesManager .Libraries {
48
+ for _ , libAlternative := range lib .Alternatives {
49
+ res = append (res , libAlternative )
50
+ }
51
+ }
52
+ return res
53
+ }
44
54
func TestLoadLibrariesAVR (t * testing.T ) {
45
55
DownloadCoresAndToolsAndLibraries (t )
46
56
@@ -69,7 +79,7 @@ func TestLoadLibrariesAVR(t *testing.T) {
69
79
require .True (t , Abs (t , paths .New ("downloaded_hardware" , "arduino" , "avr" , "libraries" )).EquivalentTo (librariesFolders [1 ]))
70
80
require .True (t , Abs (t , paths .New ("libraries" )).EquivalentTo (librariesFolders [2 ]))
71
81
72
- libs := ctx . Libraries
82
+ libs := extractLibraries ( ctx )
73
83
require .Equal (t , 24 , len (libs ))
74
84
75
85
sort .Sort (ByLibraryName (libs ))
@@ -134,18 +144,24 @@ func TestLoadLibrariesAVR(t *testing.T) {
134
144
135
145
headerToLibraries := ctx .HeaderToLibraries
136
146
require .Equal (t , 2 , len (headerToLibraries ["Audio.h" ]))
137
- require .Equal (t , "Audio" , headerToLibraries ["Audio.h" ][0 ].Name )
138
- require .Equal (t , "FakeAudio" , headerToLibraries ["Audio.h" ][1 ].Name )
139
- require .Equal (t , 1 , len (headerToLibraries ["FakeAudio.h" ]))
147
+
148
+ libs = headerToLibraries ["Audio.h" ]
149
+ require .Len (t , libs , 2 )
150
+ sort .Sort (ByLibraryName (libs ))
151
+ require .Equal (t , "Audio" , libs [0 ].Name )
152
+ require .Equal (t , "FakeAudio" , libs [1 ].Name )
153
+
154
+ require .Len (t , headerToLibraries ["FakeAudio.h" ], 1 )
140
155
require .Equal (t , "FakeAudio" , headerToLibraries ["FakeAudio.h" ][0 ].Name )
141
- require .Equal (t , 1 , len (headerToLibraries ["Adafruit_PN532.h" ]))
156
+
157
+ require .Len (t , headerToLibraries ["Adafruit_PN532.h" ], 1 )
142
158
require .Equal (t , "Adafruit_PN532" , headerToLibraries ["Adafruit_PN532.h" ][0 ].Name )
143
159
144
- require .Equal (t , 2 , len ( headerToLibraries ["IRremote.h" ]) )
160
+ require .Len (t , headerToLibraries ["IRremote.h" ], 2 )
145
161
146
162
libs = headerToLibraries ["IRremote.h" ]
163
+ require .Len (t , libs , 2 )
147
164
sort .Sort (ByLibraryName (libs ))
148
-
149
165
require .Equal (t , "IRremote" , libs [0 ].Name )
150
166
require .Equal (t , "Robot_IR_Remote" , libs [1 ].Name )
151
167
}
@@ -178,7 +194,7 @@ func TestLoadLibrariesSAM(t *testing.T) {
178
194
require .True (t , Abs (t , paths .New ("downloaded_hardware" , "arduino" , "sam" , "libraries" )).EquivalentTo (librariesFolders [1 ]))
179
195
require .True (t , Abs (t , paths .New ("libraries" )).EquivalentTo (librariesFolders [2 ]))
180
196
181
- libraries := ctx . Libraries
197
+ libraries := extractLibraries ( ctx )
182
198
require .Equal (t , 22 , len (libraries ))
183
199
184
200
sort .Sort (ByLibraryName (libraries ))
@@ -220,17 +236,20 @@ func TestLoadLibrariesSAM(t *testing.T) {
220
236
221
237
headerToLibraries := ctx .HeaderToLibraries
222
238
223
- require . Equal ( t , 2 , len ( headerToLibraries ["Audio.h" ]))
224
- libraries = headerToLibraries [ "Audio.h" ]
225
- sort .Sort (ByLibraryName (libraries ))
226
- require .Equal (t , "Audio" , libraries [0 ].Name )
227
- require .Equal (t , "FakeAudio" , libraries [1 ].Name )
239
+ libs := headerToLibraries ["Audio.h" ]
240
+ require . Len ( t , libs , 2 )
241
+ sort .Sort (ByLibraryName (libs ))
242
+ require .Equal (t , "Audio" , libs [0 ].Name )
243
+ require .Equal (t , "FakeAudio" , libs [1 ].Name )
228
244
229
245
require .Equal (t , 1 , len (headerToLibraries ["FakeAudio.h" ]))
230
246
require .Equal (t , "FakeAudio" , headerToLibraries ["FakeAudio.h" ][0 ].Name )
231
- require .Equal (t , 2 , len (headerToLibraries ["IRremote.h" ]))
232
- require .Equal (t , "Robot_IR_Remote" , headerToLibraries ["IRremote.h" ][0 ].Name )
233
- require .Equal (t , "IRremote" , headerToLibraries ["IRremote.h" ][1 ].Name )
247
+
248
+ libs = headerToLibraries ["IRremote.h" ]
249
+ require .Len (t , libs , 2 )
250
+ sort .Sort (ByLibraryName (libs ))
251
+ require .Equal (t , "IRremote" , libs [0 ].Name )
252
+ require .Equal (t , "Robot_IR_Remote" , libs [1 ].Name )
234
253
}
235
254
236
255
func TestLoadLibrariesAVRNoDuplicateLibrariesFolders (t * testing.T ) {
0 commit comments