@@ -28,18 +28,66 @@ func TestLibDiscoveryCache(t *testing.T) {
2828 env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
2929 t .Cleanup (env .CleanUp )
3030
31- // Install Arduino AVR Boards
32- _ , _ , err := cli .Run ("core" , "install" , "arduino:avr@1.8.6" )
33- require .NoError (t , err )
34-
3531 // Copy the testdata sketchbook
3632 testdata , err := paths .New ("testdata" , "libraries_discovery_caching" ).Abs ()
3733 require .NoError (t , err )
3834 sketchbook := cli .SketchbookDir ()
3935 require .NoError (t , sketchbook .RemoveAll ())
4036 require .NoError (t , testdata .CopyDirTo (cli .SketchbookDir ()))
4137
42- t .Run ("BasicLibDiscovery" , func (t * testing.T ) {
38+ // Install Arduino AVR Boards
39+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.6" )
40+ require .NoError (t , err )
41+ // Install Ethernet library
42+ _ , _ , err = cli .Run ("lib" , "install" , "Ethernet" )
43+ require .NoError (t , err )
44+
45+ t .Run ("RemoveLibWithoutError" , func (t * testing.T ) {
46+ sketchA := sketchbook .Join ("SketchA" )
47+ buildpath , err := sketchA .Join ("build" ).Abs ()
48+ require .NoError (t , err )
49+ t .Cleanup (func () { buildpath .RemoveAll () })
50+
51+ {
52+ require .NoError (t , sketchA .Join ("SketchA.ino" ).WriteFile ([]byte (`
53+ #include <SPI.h>
54+ #include <Ethernet.h>
55+ void setup() {}
56+ void loop() {}` )))
57+ outjson , _ , err := cli .Run ("compile" , "-v" , "-b" , "arduino:avr:uno" , "--build-path" , buildpath .String (), "--json" , sketchA .String ())
58+ require .NoError (t , err )
59+ j := requirejson .Parse (t , outjson )
60+ usedLibs := j .Query ("[.builder_result.used_libraries[].name]" )
61+ usedLibs .MustEqual (`["SPI", "Ethernet"]` )
62+ }
63+
64+ {
65+ // Update SketchA
66+ require .NoError (t , sketchA .Join ("SketchA.ino" ).WriteFile ([]byte (`
67+ #include <SPI.h>
68+ void setup() {}
69+ void loop() {}` )))
70+ // This compile should not include Ethernet
71+ outjson , _ , err := cli .Run ("compile" , "-v" , "-b" , "arduino:avr:uno" , "--build-path" , buildpath .String (), "--json" , sketchA .String ())
72+ require .NoError (t , err )
73+ j := requirejson .Parse (t , outjson )
74+ usedLibs := j .Query ("[.builder_result.used_libraries[].name]" )
75+ usedLibs .MustEqual (`["SPI"]` )
76+ j .Query (".compiler_out" ).MustContain (`"The list of included libraries has been changed... rebuilding all libraries."` )
77+ }
78+
79+ {
80+ // This compile should not rebuild libs
81+ outjson , _ , err := cli .Run ("compile" , "-v" , "-b" , "arduino:avr:uno" , "--build-path" , buildpath .String (), "--json" , sketchA .String ())
82+ require .NoError (t , err )
83+ j := requirejson .Parse (t , outjson )
84+ usedLibs := j .Query ("[.builder_result.used_libraries[].name]" )
85+ usedLibs .MustEqual (`["SPI"]` )
86+ j .Query (".compiler_out" ).MustNotContain (`"The list of included libraries has changed... rebuilding all libraries."` )
87+ }
88+ })
89+
90+ t .Run ("RemoveLibWithError" , func (t * testing.T ) {
4391 sketchA := sketchbook .Join ("SketchA" )
4492 buildpath , err := sketchA .Join ("build" ).Abs ()
4593 require .NoError (t , err )
0 commit comments