@@ -28,63 +28,42 @@ import (
28
28
"gopkg.in/src-d/go-git.v4/plumbing"
29
29
)
30
30
31
- func TestCompileManuallyInstalledPlatformUsingBoardsLocalTxt (t * testing.T ) {
31
+ func TestCompilePart4 (t * testing.T ) {
32
32
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
33
33
defer env .CleanUp ()
34
34
35
35
_ , _ , err := cli .Run ("update" )
36
36
require .NoError (t , err )
37
37
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:[email protected] " )
42
39
require .NoError (t , err )
43
40
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 {
48
45
URL : gitUrl ,
49
- ReferenceName : plumbing .NewTagReferenceName ("1.8.3 " ),
46
+ ReferenceName : plumbing .NewTagReferenceName ("0.16.1 " ),
50
47
})
51
48
require .NoError (t , err )
52
49
53
- // Installs also the same core via CLI so all the necessary tools are installed
54
- _ ,
_ ,
err = cli .
Run (
"core" ,
"install" ,
"arduino:[email protected] " )
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 )
71
55
}
72
56
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:[email protected] " )
81
- require .NoError (t , err )
82
-
57
+ func compileWithLibrary (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
83
58
sketchName := "CompileSketchWithWiFi101Dependency"
84
59
sketchPath := cli .SketchbookDir ().Join (sketchName )
60
+ defer sketchPath .RemoveAll ()
85
61
fqbn := "arduino:avr:uno"
62
+
63
+ libPath := cli .SketchbookDir ().Join ("my-libraries" , "WiFi101" )
64
+
86
65
// Create new sketch and add library include
87
- _ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
66
+ _ , _ , err : = cli .Run ("sketch" , "new" , sketchPath .String ())
88
67
require .NoError (t , err )
89
68
sketchFile := sketchPath .Join (sketchName + ".ino" )
90
69
lines , err := sketchFile .ReadFileAsLines ()
@@ -97,46 +76,23 @@ func TestCompileWithLibrary(t *testing.T) {
97
76
err = sketchFile .WriteFile (data )
98
77
require .NoError (t , err )
99
78
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
-
109
79
stdout , _ , err := cli .Run ("compile" , "-b" , fqbn , sketchPath .String (), "--library" , libPath .String (), "-v" )
110
80
require .NoError (t , err )
111
81
require .Contains (t , string (stdout ), "WiFi101" )
112
82
}
113
83
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:[email protected] " )
122
- require .NoError (t , err )
123
-
84
+ func compileWithLibraryPriority (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
124
85
sketchName := "CompileSketchWithLibraryPriority"
125
86
sketchPath := cli .SketchbookDir ().Join (sketchName )
87
+ defer sketchPath .RemoveAll ()
126
88
fqbn := "arduino:avr:uno"
127
89
128
- // Manually installs a library
129
- gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
130
90
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 )
136
91
137
92
// Install the same library we installed manually
138
- _ , _ , err = cli .Run ("lib" , "install" , "WiFi101" )
93
+ _ , _ , err : = cli .Run ("lib" , "install" , "WiFi101" )
139
94
require .NoError (t , err )
95
+ defer cli .SketchbookDir ().Join ("libraries" ).RemoveAll ()
140
96
141
97
// Create new sketch and add library include
142
98
_ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
@@ -163,32 +119,18 @@ func TestCompileWithLibraryPriority(t *testing.T) {
163
119
require .Contains (t , string (stdout ), expectedOutput [0 ]+ "\n " + expectedOutput [1 ]+ "\n " + expectedOutput [2 ]+ "\n " )
164
120
}
165
121
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:[email protected] " )
174
- require .NoError (t , err )
175
-
122
+ func recompileWithDifferentLibrary (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
176
123
sketchName := "RecompileCompileSketchWithDifferentLibrary"
177
124
sketchPath := cli .SketchbookDir ().Join (sketchName )
125
+ defer sketchPath .RemoveAll ()
178
126
fqbn := "arduino:avr:uno"
179
127
180
128
// Install library
181
- _ , _ , err = cli .Run ("lib" , "install" , "WiFi101" )
129
+ _ , _ , err : = cli .Run ("lib" , "install" , "WiFi101" )
182
130
require .NoError (t , err )
131
+ defer cli .SketchbookDir ().Join ("libraries" ).RemoveAll ()
183
132
184
- // Manually installs a library
185
- gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
186
133
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 )
192
134
193
135
// Create new sketch and add library include
194
136
_ , _ , err = cli .Run ("sketch" , "new" , sketchPath .String ())
@@ -221,6 +163,48 @@ func TestRecompileWithDifferentLibrary(t *testing.T) {
221
163
require .NotContains (t , string (stdout ), "Using previously compiled file: " + objPath .String ())
222
164
}
223
165
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:[email protected] " )
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
+
224
208
func TestCompileWithConflictingLibrariesInclude (t * testing.T ) {
225
209
env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
226
210
defer env .CleanUp ()
0 commit comments