@@ -272,15 +272,9 @@ func TestProfileLib(t *testing.T) {
272
272
_ , _ , err := cli .Run ("core" , "update-index" )
273
273
require .NoError (t , err )
274
274
275
- _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
276
- require .NoError (t , err )
277
-
278
275
_ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
279
276
require .NoError (t , err )
280
277
281
- _ , _ , err = cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
282
- require .NoError (t , err )
283
-
284
278
integrationtest.CLISubtests {
285
279
{"AddLibToDefaultProfile" , addLibToDefaultProfile },
286
280
{"ChangeLibVersionDefaultProfile" , changeLibVersionDefaultProfile },
@@ -291,43 +285,93 @@ func TestProfileLib(t *testing.T) {
291
285
}
292
286
293
287
func addLibToDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
294
- _ , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , cli .SketchbookDir ().Join ("Simple" ).String ())
288
+ sk := cli .SketchbookDir ().Join ("addLibToDefaultProfile" )
289
+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
295
290
require .NoError (t , err )
296
- fileContent , err : = cli .SketchbookDir (). Join ( "Simple " , "sketch.yaml" ). ReadFile ( )
291
+ _ , _ , err = cli .Run ( "profile " , "init" , sk . String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
297
292
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
293
301
- func changeLibVersionDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
302
- fileContent , err := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
294
+ out , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , sk .String (), "--json" )
303
295
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 ) )
296
+ requirejson . Parse (t , out ). Query ( ".added_libraries" ). MustContain ( `[{"name":" Modulino", "version":" 0.5.0"}]` )
305
297
306
- _ , _ , err = cli . Run ( "profile" , "lib" , "add" , "Modulino@0.4.0" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ). String () )
298
+ fileContent , err := sk . Join ( "sketch.yaml" ). ReadFile ( )
307
299
require .NoError (t , err )
308
- fileContent , err = cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" ).ReadFile ()
300
+ require .Contains (t , string (fileContent ), " - Modulino (0.5.0)\n " )
301
+ require .Contains (t , string (fileContent ), " - Arduino_LSM6DSOX (" ) // dependency added as well
302
+ }
303
+
304
+ func changeLibVersionDefaultProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
305
+ sk := cli .SketchbookDir ().Join ("changeLibVersionDefaultProfile" )
306
+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
309
307
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 ))
308
+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
309
+ require .NoError (t , err )
310
+
311
+ {
312
+ out , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , sk .String (), "--json" )
313
+ outjson := requirejson .Parse (t , out )
314
+ outjson .Query (".added_libraries" ).MustContain (`[{"name":"Modulino", "version":"0.5.0"},{"name":"Arduino_LSM6DSOX"}]` )
315
+ outjson .Query (".skipped_libraries" ).LengthMustEqualTo (0 )
316
+
317
+ fileContent , err := sk .Join ("sketch.yaml" ).ReadFile ()
318
+ require .NoError (t , err )
319
+ require .Contains (t , string (fileContent ), " - Modulino (0.5.0)\n " )
320
+ require .Contains (t , string (fileContent ), " - Arduino_LSM6DSOX (" ) // dependency added as well
321
+ }
322
+
323
+ {
324
+ out , _ , err := cli .Run ("profile" , "lib" , "add" , "Modulino@0.4.0" , "--dest-dir" , sk .String (), "--json" )
325
+ require .NoError (t , err )
326
+ outjson := requirejson .Parse (t , out )
327
+ outjson .Query (".added_libraries" ).MustContain (`[{"name":"Modulino", "version":"0.4.0"}]` )
328
+ outjson .Query (".skipped_libraries" ).MustContain (`[{"name":"Arduino_LSM6DSOX"}]` )
329
+
330
+ fileContent , err := sk .Join ("sketch.yaml" ).ReadFile ()
331
+ require .NoError (t , err )
332
+ require .Contains (t , string (fileContent ), " - Modulino (0.4.0)\n " )
333
+ }
311
334
}
312
335
313
336
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 ())
337
+ sk := cli .SketchbookDir ().Join ("removeLibFromDefaultProfile" )
338
+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
315
339
require .NoError (t , err )
316
- fileContent , err : = cli .SketchbookDir (). Join ( "Simple " , "sketch.yaml" ). ReadFile ( )
340
+ _ , _ , err = cli .Run ( "profile " , "init" , sk . String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
317
341
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 \n default_profile: Uno\n " , string (fileContent ))
342
+
343
+ _ , _ , err = cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "--dest-dir" , sk .String (), "--json" )
344
+ require .NoError (t , err )
345
+
346
+ _ , _ , err = cli .Run ("profile" , "lib" , "remove" , "Modulino" , "--dest-dir" , sk .String ())
347
+ require .NoError (t , err )
348
+ fileContent , err := sk .Join ("sketch.yaml" ).ReadFile ()
349
+ require .NoError (t , err )
350
+ require .NotContains (t , string (fileContent ), " - Modulino" )
319
351
}
320
352
321
353
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 ())
354
+ sk := cli .SketchbookDir ().Join ("addInexistentLibToDefaultProfile" )
355
+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
356
+ require .NoError (t , err )
357
+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
358
+ require .NoError (t , err )
359
+
360
+ _ , stderr , err := cli .Run ("profile" , "lib" , "add" , "foobar" , "--dest-dir" , sk .String ())
323
361
require .Error (t , err )
324
362
require .Equal (t , "Error adding foobar to the profile : Library 'foobar@latest' not found\n " , string (stderr ))
325
363
}
326
364
327
365
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 ())
366
+ sk := cli .SketchbookDir ().Join ("removeLibNotInDefaultProfile" )
367
+ _ , _ , err := cli .Run ("sketch" , "new" , sk .String ())
368
+ require .NoError (t , err )
369
+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
370
+ require .NoError (t , err )
371
+
372
+ _ , stderr , err := cli .Run ("profile" , "lib" , "remove" , "Arduino_JSON" , "--dest-dir" , sk .String ())
329
373
require .Error (t , err )
330
- require .Equal (t , "Error removing Arduino_JSON from the profile: Library 'Arduino_JSON' not found\n " , string (stderr ))
374
+ require .Equal (t , "Error removing library Arduino_JSON from the profile: Library 'Arduino_JSON' not found\n " , string (stderr ))
331
375
}
332
376
333
377
func TestProfileLibSpecificProfile (t * testing.T ) {
@@ -338,30 +382,31 @@ func TestProfileLibSpecificProfile(t *testing.T) {
338
382
_ , _ , err := cli .Run ("core" , "update-index" )
339
383
require .NoError (t , err )
340
384
341
- _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
385
+ sk := cli .SketchbookDir ().Join ("Simple" )
386
+ _ , _ , err = cli .Run ("sketch" , "new" , sk .String ())
342
387
require .NoError (t , err )
343
388
344
389
_ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
345
390
require .NoError (t , err )
346
391
347
- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
392
+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
348
393
require .NoError (t , err )
349
394
350
395
// Add a second profile
351
- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
396
+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
352
397
require .NoError (t , err )
353
398
354
399
// Add library to a specific profile
355
- _ , _ , err = cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "-m" , "my_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ). String () )
400
+ _ , _ , err = cli .Run ("profile" , "lib" , "add" , "Modulino@0.5.0" , "-m" , "my_profile" , "--dest-dir" , sk . String (), "--no-deps" )
356
401
require .NoError (t , err )
357
- fileContent , err := cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFile ()
402
+ fileContent , err := sk . Join ("sketch.yaml" ).ReadFile ()
358
403
require .NoError (t , err )
359
404
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
405
361
406
// Remove library from a specific profile
362
- _ , _ , err = cli .Run ("profile" , "lib" , "remove" , "Modulino" , "-m" , "my_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ) .String ())
407
+ _ , _ , err = cli .Run ("profile" , "lib" , "remove" , "Modulino" , "-m" , "my_profile" , "--dest-dir" , sk .String ())
363
408
require .NoError (t , err )
364
- fileContent , err = cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFile ()
409
+ fileContent , err = sk . Join ("sketch.yaml" ).ReadFile ()
365
410
require .NoError (t , err )
366
411
require .NotContains (t , string (fileContent ), "- Modulino (0.5.0)" )
367
412
}
@@ -374,33 +419,34 @@ func TestProfileSetDefault(t *testing.T) {
374
419
_ , _ , err := cli .Run ("core" , "update-index" )
375
420
require .NoError (t , err )
376
421
377
- _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
422
+ sk := cli .SketchbookDir ().Join ("Simple" )
423
+ _ , _ , err = cli .Run ("sketch" , "new" , sk .String ())
378
424
require .NoError (t , err )
379
425
380
426
_ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
381
427
require .NoError (t , err )
382
428
383
- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
429
+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
384
430
require .NoError (t , err )
385
431
386
432
// Add a second profile
387
- _ , _ , err = cli .Run ("profile" , "init" , cli . SketchbookDir (). Join ( "Simple" ) .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
433
+ _ , _ , err = cli .Run ("profile" , "init" , sk .String (), "-m" , "my_profile" , "-b" , "arduino:avr:uno" )
388
434
require .NoError (t , err )
389
- fileContent , err := cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFileAsLines ()
435
+ fileContent , err := sk . Join ("sketch.yaml" ).ReadFileAsLines ()
390
436
require .NoError (t , err )
391
437
require .Contains (t , fileContent , "default_profile: Uno" )
392
438
require .NotContains (t , fileContent , "default_profile: my_profile" )
393
439
394
440
// Change default profile
395
- _ , _ , err = cli .Run ("profile" , "set-default" , "my_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ) .String ())
441
+ _ , _ , err = cli .Run ("profile" , "set-default" , "my_profile" , "--dest-dir" , sk .String ())
396
442
require .NoError (t , err )
397
- fileContent , err = cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFileAsLines ()
443
+ fileContent , err = sk . Join ("sketch.yaml" ).ReadFileAsLines ()
398
444
require .NoError (t , err )
399
445
require .NotContains (t , fileContent , "default_profile: Uno" )
400
446
require .Contains (t , fileContent , "default_profile: my_profile" )
401
447
402
448
// Changing to an inexistent profile returns an error
403
- _ , stderr , err := cli .Run ("profile" , "set-default" , "inexistent_profile" , "--dest-dir" , cli . SketchbookDir (). Join ( "Simple" ) .String ())
449
+ _ , stderr , err := cli .Run ("profile" , "set-default" , "inexistent_profile" , "--dest-dir" , sk .String ())
404
450
require .Error (t , err )
405
451
require .Equal (t , "Cannot set inexistent_profile as default profile: Profile 'inexistent_profile' not found\n " , string (stderr ))
406
452
}
0 commit comments