@@ -171,6 +171,7 @@ func TestInitProfile(t *testing.T) {
171
171
{"ProfileWrongFQBN" , initWithWrongFqbn },
172
172
{"ProfileMissingFQBN" , initMissingFqbn },
173
173
{"ExistingProfile" , initExistingProfile },
174
+ {"SetDefaultProfile" , initSetDefaultProfile },
174
175
}.Run (t , env , cli )
175
176
}
176
177
@@ -194,7 +195,7 @@ func initWithCorrectFqbn(t *testing.T, env *integrationtest.Environment, cli *in
194
195
require .FileExists (t , projectFile .String ())
195
196
fileContent , err := projectFile .ReadFile ()
196
197
require .NoError (t , err )
197
- require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n \n " , string (fileContent ))
198
+ require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n \n default_profile: Uno \ n " , string (fileContent ))
198
199
}
199
200
200
201
func initWithWrongFqbn (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
@@ -215,7 +216,16 @@ func initExistingProfile(t *testing.T, env *integrationtest.Environment, cli *in
215
216
// Adding a profile with a name that already exists should return an error
216
217
_ , stderr , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
217
218
require .Error (t , err )
218
- require .Contains (t , string (stderr ), "the profile already exists" )
219
+ require .Contains (t , string (stderr ), "Profile 'Uno' already exists" )
220
+ }
221
+
222
+ func initSetDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
223
+ // Adding a profile with a name that already exists should return an error
224
+ _ , _ , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "new_profile" , "-b" , "arduino:avr:uno" , "--default" )
225
+ require .NoError (t , err )
226
+ fileContent , err := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFileAsLines ()
227
+ require .NoError (t , err )
228
+ require .Contains (t , fileContent , "default_profile: new_profile" )
219
229
}
220
230
221
231
func TestInitProfileMissingSketchFile (t * testing.T ) {
@@ -253,3 +263,105 @@ func TestInitProfilePlatformNotInstalled(t *testing.T) {
253
263
require .Error (t , err )
254
264
require .Contains (t , string (stderr ), "platform not installed" )
255
265
}
266
+
267
+ func TestProfileLib (t * testing.T ) {
268
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
269
+ defer env .CleanUp ()
270
+
271
+ // Init the environment explicitly
272
+ _ , _ , err := cli .Run ("core" , "update-index" )
273
+ require .NoError (t , err )
274
+
275
+ _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
276
+ require .NoError (t , err )
277
+
278
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
279
+ require .NoError (t , err )
280
+
281
+ _ , _ , err = cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
282
+ require .NoError (t , err )
283
+
284
+ integrationtest.CLISubtests {
285
+ {"AddLibToDefaultProfile" , addLibToDefaultProfile },
286
+ {"ChangeLibVersionDefaultProfile" , changeLibVersionDefaultProfile },
287
+ {"RemoveLibFromDefaultProfile" , removeLibFromDefaultProfile },
288
+ {"AddInexistentLibToDefaultProfile" , addInexistentLibToDefaultProfile },
289
+ {"RemoveLibNotInDefaultProfile" , removeLibNotInDefaultProfile },
290
+ }.Run (t , env , cli )
291
+ }
292
+
293
+ func addLibToDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
294
+ _ ,
_ ,
err := cli .
Run (
"profile" ,
"lib" ,
"add" ,
"[email protected] " ,
"--dest-dir" ,
cli .
SketchbookDir ().
Join (
"Simple" ).
String ())
295
+ require .NoError (t , err )
296
+ fileContent , err := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
297
+ require .NoError (t , err )
298
+ require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n - Modulino (0.5.0)\n \n default_profile: Uno\n " , string (fileContent ))
299
+ }
300
+
301
+ func changeLibVersionDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
302
+ fileContent , err := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
303
+ require .NoError (t , err )
304
+ require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n - Modulino (0.5.0)\n \n default_profile: Uno\n " , string (fileContent ))
305
+
306
+ _ ,
_ ,
err = cli .
Run (
"profile" ,
"lib" ,
"add" ,
"[email protected] " ,
"--dest-dir" ,
cli .
SketchbookDir ().
Join (
"Simple" ).
String ())
307
+ require .NoError (t , err )
308
+ fileContent , err = cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
309
+ require .NoError (t , err )
310
+ require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n - Modulino (0.4.0)\n \n default_profile: Uno\n " , string (fileContent ))
311
+ }
312
+
313
+ func removeLibFromDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
314
+ _ , _ , err := cli .Run ("profile" , "lib" , "remove" , "Modulino" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
315
+ require .NoError (t , err )
316
+ fileContent , err := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
317
+ require .NoError (t , err )
318
+ require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n \n default_profile: Uno\n " , string (fileContent ))
319
+ }
320
+
321
+ func addInexistentLibToDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
322
+ _ , stderr , err := cli .Run ("profile" , "lib" , "add" , "foobar" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
323
+ require .Error (t , err )
324
+ require .Equal (t , "Error adding foobar to the profile : Library 'foobar@latest' not found\n " , string (stderr ))
325
+ }
326
+
327
+ func removeLibNotInDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
328
+ _ , stderr , err := cli .Run ("profile" , "lib" , "remove" , "Arduino_JSON" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
329
+ require .Error (t , err )
330
+ require .Equal (t , "Error removing Arduino_JSON from the profile : Library 'Arduino_JSON' not found\n " , string (stderr ))
331
+ }
332
+
333
+ func TestProfileLibSpecificProfile (t * testing.T ) {
334
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
335
+ defer env .CleanUp ()
336
+
337
+ // Init the environment explicitly
338
+ _ , _ , err := cli .Run ("core" , "update-index" )
339
+ require .NoError (t , err )
340
+
341
+ _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
342
+ require .NoError (t , err )
343
+
344
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
345
+ require .NoError (t , err )
346
+
347
+ _ , _ , err = cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
348
+ require .NoError (t , err )
349
+
350
+ // Add a second profile
351
+ _ , _ , err = cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
352
+ require .NoError (t , err )
353
+
354
+ // Add library to a specific profile
355
+ _ ,
_ ,
err = cli .
Run (
"profile" ,
"lib" ,
"add" ,
"[email protected] " ,
"-m" ,
"my_profile" ,
"--dest-dir" ,
cli .
SketchbookDir ().
Join (
"Simple" ).
String ())
356
+ require .NoError (t , err )
357
+ fileContent , err := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
358
+ require .NoError (t , err )
359
+ require .Contains (t , string (fileContent ), " my_profile:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n - Modulino (0.5.0)\n " )
360
+
361
+ // Remove library from a specific profile
362
+ _ , _ , err = cli .Run ("profile" , "lib" , "remove" , "Modulino" , "-m" , "my_profile" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
363
+ require .NoError (t , err )
364
+ fileContent , err = cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
365
+ require .NoError (t , err )
366
+ require .NotContains (t , string (fileContent ), "- Modulino (0.5.0)" )
367
+ }
0 commit comments