@@ -272,15 +272,9 @@ func TestProfileLib(t *testing.T) {
272272 _ , _ , err := cli .Run ("core" , "update-index" )
273273 require .NoError (t , err )
274274
275- _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
276- require .NoError (t , err )
277-
278275 _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
279276 require .NoError (t , err )
280277
281- _ , _ , err = cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
282- require .NoError (t , err )
283-
284278 integrationtest.CLISubtests {
285279 {"AddLibToDefaultProfile" , addLibToDefaultProfile },
286280 {"ChangeLibVersionDefaultProfile" , changeLibVersionDefaultProfile },
@@ -291,43 +285,94 @@ func TestProfileLib(t *testing.T) {
291285}
292286
293287func 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 ())
295290 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" )
297292 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- }
300293
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" )
303295 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"}]` )
305297
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 ( )
307299 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 ())
309307 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+ }
311335}
312336
313337func 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 ())
315340 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" )
317342 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" )
319352}
320353
321354func 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 ())
323362 require .Error (t , err )
324363 require .Equal (t , "Error adding foobar to the profile : Library 'foobar@latest' not found\n " , string (stderr ))
325364}
326365
327366func 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 ())
329374 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 ))
331376}
332377
333378func TestProfileLibSpecificProfile (t * testing.T ) {
@@ -338,30 +383,31 @@ func TestProfileLibSpecificProfile(t *testing.T) {
338383 _ , _ , err := cli .Run ("core" , "update-index" )
339384 require .NoError (t , err )
340385
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 ())
342388 require .NoError (t , err )
343389
344390 _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
345391 require .NoError (t , err )
346392
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" )
348394 require .NoError (t , err )
349395
350396 // 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" )
352398 require .NoError (t , err )
353399
354400 // 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" )
356402 require .NoError (t , err )
357- fileContent , err := cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFile ()
403+ fileContent , err := sk . Join ("sketch.yaml" ).ReadFile ()
358404 require .NoError (t , err )
359405 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 " )
360406
361407 // 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 ())
363409 require .NoError (t , err )
364- fileContent , err = cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFile ()
410+ fileContent , err = sk . Join ("sketch.yaml" ).ReadFile ()
365411 require .NoError (t , err )
366412 require .NotContains (t , string (fileContent ), "- Modulino (0.5.0)" )
367413}
@@ -374,33 +420,34 @@ func TestProfileSetDefault(t *testing.T) {
374420 _ , _ , err := cli .Run ("core" , "update-index" )
375421 require .NoError (t , err )
376422
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 ())
378425 require .NoError (t , err )
379426
380427 _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
381428 require .NoError (t , err )
382429
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" )
384431 require .NoError (t , err )
385432
386433 // 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" )
388435 require .NoError (t , err )
389- fileContent , err := cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFileAsLines ()
436+ fileContent , err := sk . Join ("sketch.yaml" ).ReadFileAsLines ()
390437 require .NoError (t , err )
391438 require .Contains (t , fileContent , "default_profile: Uno" )
392439 require .NotContains (t , fileContent , "default_profile: my_profile" )
393440
394441 // 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 ())
396443 require .NoError (t , err )
397- fileContent , err = cli . SketchbookDir (). Join ("Simple" , "sketch.yaml" ).ReadFileAsLines ()
444+ fileContent , err = sk . Join ("sketch.yaml" ).ReadFileAsLines ()
398445 require .NoError (t , err )
399446 require .NotContains (t , fileContent , "default_profile: Uno" )
400447 require .Contains (t , fileContent , "default_profile: my_profile" )
401448
402449 // 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 ())
404451 require .Error (t , err )
405452 require .Equal (t , "Cannot set inexistent_profile as default profile: Profile 'inexistent_profile' not found\n " , string (stderr ))
406453}
0 commit comments