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