@@ -28,63 +28,42 @@ import (
2828 "gopkg.in/src-d/go-git.v4/plumbing"
2929)
3030
31- func TestCompileManuallyInstalledPlatformUsingBoardsLocalTxt (t * testing.T ) {
31+ func TestCompilePart4 (t * testing.T ) {
3232 env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
3333 defer env .CleanUp ()
3434
3535 _ , _ , err := cli .Run ("update" )
3636 require .NoError (t , err )
3737
38- sketchName := "CompileSketchManuallyInstalledPlatformUsingBoardsLocalTxt"
39- sketchPath := cli .SketchbookDir ().Join (sketchName )
40- fqbn := "arduino-beta-development:avr:nessuno"
41- _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
38+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
4239 require .NoError (t , err )
4340
44- // Manually installs a core in sketchbooks hardware folder
45- gitUrl := "https://github.com/arduino/ArduinoCore-avr .git"
46- repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development " , "avr " )
47- _ , err = git .PlainClone (repoDir .String (), false , & git.CloneOptions {
41+ // Manually installs a library
42+ gitUrl := "https://github.com/arduino-libraries/WiFi101 .git"
43+ libPath := cli .SketchbookDir ().Join ("my-libraries " , "WiFi101 " )
44+ _ , err = git .PlainClone (libPath .String (), false , & git.CloneOptions {
4845 URL : gitUrl ,
49- ReferenceName : plumbing .NewTagReferenceName ("1.8.3 " ),
46+ ReferenceName : plumbing .NewTagReferenceName ("0.16.1 " ),
5047 })
5148 require .NoError (t , err )
5249
53- // Installs also the same core via CLI so all the necessary tools are installed
54- _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
55- require .NoError (t , err )
56-
57- // Verifies compilation fails because board doesn't exist
58- _ , stderr , err := cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
59- require .Error (t , err )
60- require .Contains (t , string (stderr ), "Error during build: Error resolving FQBN: board arduino-beta-development:avr:nessuno not found" )
61-
62- // Use custom boards.local.txt with made arduino:avr:nessuno board
63- boardsLocalTxt := repoDir .Join ("boards.local.txt" )
64- wd , err := paths .Getwd ()
65- require .NoError (t , err )
66- err = wd .Parent ().Join ("testdata" , "boards.local.txt" ).CopyTo (boardsLocalTxt )
67- require .NoError (t , err )
68-
69- _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
70- require .NoError (t , err )
50+ integrationtest.CLISubtests {
51+ {"WithLibrary" , compileWithLibrary },
52+ {"WithLibraryPriority" , compileWithLibraryPriority },
53+ {"WithDifferentLibrary" , recompileWithDifferentLibrary },
54+ }.Run (t , env , cli )
7155}
7256
73- func TestCompileWithLibrary (t * testing.T ) {
74- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
75- defer env .CleanUp ()
76-
77- _ , _ , err := cli .Run ("update" )
78- require .NoError (t , err )
79-
80- _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
81- require .NoError (t , err )
82-
57+ func compileWithLibrary (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
8358 sketchName := "CompileSketchWithWiFi101Dependency"
8459 sketchPath := cli .SketchbookDir ().Join (sketchName )
60+ defer sketchPath .RemoveAll ()
8561 fqbn := "arduino:avr:uno"
62+
63+ libPath := cli .SketchbookDir ().Join ("my-libraries" , "WiFi101" )
64+
8665 // Create new sketch and add library include
87- _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
66+ _ , _ , err : = cli .Run ("sketch" , "new" , sketchPath .String ())
8867 require .NoError (t , err )
8968 sketchFile := sketchPath .Join (sketchName + ".ino" )
9069 lines , err := sketchFile .ReadFileAsLines ()
@@ -97,46 +76,23 @@ func TestCompileWithLibrary(t *testing.T) {
9776 err = sketchFile .WriteFile (data )
9877 require .NoError (t , err )
9978
100- // Manually installs a library
101- gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
102- libPath := cli .SketchbookDir ().Join ("my-libraries" , "WiFi101" )
103- _ , err = git .PlainClone (libPath .String (), false , & git.CloneOptions {
104- URL : gitUrl ,
105- ReferenceName : plumbing .NewTagReferenceName ("0.16.1" ),
106- })
107- require .NoError (t , err )
108-
10979 stdout , _ , err := cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--library" , libPath .String (), "-v" )
11080 require .NoError (t , err )
11181 require .Contains (t , string (stdout ), "WiFi101" )
11282}
11383
114- func TestCompileWithLibraryPriority (t * testing.T ) {
115- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
116- defer env .CleanUp ()
117-
118- _ , _ , err := cli .Run ("update" )
119- require .NoError (t , err )
120-
121- _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
122- require .NoError (t , err )
123-
84+ func compileWithLibraryPriority (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
12485 sketchName := "CompileSketchWithLibraryPriority"
12586 sketchPath := cli .SketchbookDir ().Join (sketchName )
87+ defer sketchPath .RemoveAll ()
12688 fqbn := "arduino:avr:uno"
12789
128- // Manually installs a library
129- gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
13090 manuallyInstalledLibPath := cli .SketchbookDir ().Join ("my-libraries" , "WiFi101" )
131- _ , err = git .PlainClone (manuallyInstalledLibPath .String (), false , & git.CloneOptions {
132- URL : gitUrl ,
133- ReferenceName : plumbing .NewTagReferenceName ("0.16.1" ),
134- })
135- require .NoError (t , err )
13691
13792 // Install the same library we installed manually
138- _ , _ , err = cli .Run ("lib" , "install" , "WiFi101" )
93+ _ , _ , err : = cli .Run ("lib" , "install" , "WiFi101" )
13994 require .NoError (t , err )
95+ defer cli .SketchbookDir ().Join ("libraries" ).RemoveAll ()
14096
14197 // Create new sketch and add library include
14298 _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
@@ -163,32 +119,18 @@ func TestCompileWithLibraryPriority(t *testing.T) {
163119 require .Contains (t , string (stdout ), expectedOutput [0 ]+ "\n " + expectedOutput [1 ]+ "\n " + expectedOutput [2 ]+ "\n " )
164120}
165121
166- func TestRecompileWithDifferentLibrary (t * testing.T ) {
167- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
168- defer env .CleanUp ()
169-
170- _ , _ , err := cli .Run ("update" )
171- require .NoError (t , err )
172-
173- _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
174- require .NoError (t , err )
175-
122+ func recompileWithDifferentLibrary (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
176123 sketchName := "RecompileCompileSketchWithDifferentLibrary"
177124 sketchPath := cli .SketchbookDir ().Join (sketchName )
125+ defer sketchPath .RemoveAll ()
178126 fqbn := "arduino:avr:uno"
179127
180128 // Install library
181- _ , _ , err = cli .Run ("lib" , "install" , "WiFi101" )
129+ _ , _ , err : = cli .Run ("lib" , "install" , "WiFi101" )
182130 require .NoError (t , err )
131+ defer cli .SketchbookDir ().Join ("libraries" ).RemoveAll ()
183132
184- // Manually installs a library
185- gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
186133 manuallyInstalledLibPath := cli .SketchbookDir ().Join ("my-libraries" , "WiFi101" )
187- _ , err = git .PlainClone (manuallyInstalledLibPath .String (), false , & git.CloneOptions {
188- URL : gitUrl ,
189- ReferenceName : plumbing .NewTagReferenceName ("0.16.1" ),
190- })
191- require .NoError (t , err )
192134
193135 // Create new sketch and add library include
194136 _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
@@ -221,6 +163,48 @@ func TestRecompileWithDifferentLibrary(t *testing.T) {
221163 require .NotContains (t , string (stdout ), "Using previously compiled file: " + objPath .String ())
222164}
223165
166+ func TestCompileManuallyInstalledPlatformUsingBoardsLocalTxt (t * testing.T ) {
167+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
168+ defer env .CleanUp ()
169+
170+ _ , _ , err := cli .Run ("update" )
171+ require .NoError (t , err )
172+
173+ sketchName := "CompileSketchManuallyInstalledPlatformUsingBoardsLocalTxt"
174+ sketchPath := cli .SketchbookDir ().Join (sketchName )
175+ fqbn := "arduino-beta-development:avr:nessuno"
176+ _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
177+ require .NoError (t , err )
178+
179+ // Manually installs a core in sketchbooks hardware folder
180+ gitUrl := "https://github.com/arduino/ArduinoCore-avr.git"
181+ repoDir := cli .SketchbookDir ().Join ("hardware" , "arduino-beta-development" , "avr" )
182+ _ , err = git .PlainClone (repoDir .String (), false , & git.CloneOptions {
183+ URL : gitUrl ,
184+ ReferenceName : plumbing .NewTagReferenceName ("1.8.3" ),
185+ })
186+ require .NoError (t , err )
187+
188+ // Installs also the same core via CLI so all the necessary tools are installed
189+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr@1.8.3" )
190+ require .NoError (t , err )
191+
192+ // Verifies compilation fails because board doesn't exist
193+ _ , stderr , err := cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
194+ require .Error (t , err )
195+ require .Contains (t , string (stderr ), "Error during build: Error resolving FQBN: board arduino-beta-development:avr:nessuno not found" )
196+
197+ // Use custom boards.local.txt with made arduino:avr:nessuno board
198+ boardsLocalTxt := repoDir .Join ("boards.local.txt" )
199+ wd , err := paths .Getwd ()
200+ require .NoError (t , err )
201+ err = wd .Parent ().Join ("testdata" , "boards.local.txt" ).CopyTo (boardsLocalTxt )
202+ require .NoError (t , err )
203+
204+ _ , _ , err = cli .Run ("compile" , "--clean" , "-b" , fqbn , sketchPath .String ())
205+ require .NoError (t , err )
206+ }
207+
224208func TestCompileWithConflictingLibrariesInclude (t * testing.T ) {
225209 env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
226210 defer env .CleanUp ()
0 commit comments