@@ -150,3 +150,106 @@ func TestCompileWithDefaultProfile(t *testing.T) {
150
150
jsonOut .Query (".builder_result.build_properties" ).MustContain (`[ "build.fqbn=arduino:avr:nano" ]` )
151
151
}
152
152
}
153
+
154
+ func TestInitProfile (t * testing.T ) {
155
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
156
+ defer env .CleanUp ()
157
+
158
+ // Init the environment explicitly
159
+ _ , _ , err := cli .Run ("core" , "update-index" )
160
+ require .NoError (t , err )
161
+
162
+ _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
163
+ require .NoError (t , err )
164
+
165
+ _ , _ , err = cli .Run ("core" , "install" , "arduino:avr" )
166
+ require .NoError (t , err )
167
+
168
+ integrationtest.CLISubtests {
169
+ {"NoProfile" , initNoProfile },
170
+ {"ProfileCorrectFQBN" , initWithCorrectFqbn },
171
+ {"ProfileWrongFQBN" , initWithWrongFqbn },
172
+ {"ProfileMissingFQBN" , initMissingFqbn },
173
+ {"ExistingProfile" , initExistingProfile },
174
+ }.Run (t , env , cli )
175
+ }
176
+
177
+ func initNoProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
178
+ projectFile := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" )
179
+ // Create an empty project file
180
+ stdout , _ , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String ())
181
+ require .NoError (t , err )
182
+ require .Contains (t , string (stdout ), "Project file created in: " + projectFile .String ())
183
+ require .FileExists (t , projectFile .String ())
184
+ fileContent , err := projectFile .ReadFile ()
185
+ require .NoError (t , err )
186
+ require .Equal (t , "profiles:\n " , string (fileContent ))
187
+ }
188
+
189
+ func initWithCorrectFqbn (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
190
+ projectFile := cli .SketchbookDir ().Join ("Simple" , "sketch.yaml" )
191
+ // Add a profile with a correct FQBN
192
+ _ , _ , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
193
+ require .NoError (t , err )
194
+ require .FileExists (t , projectFile .String ())
195
+ fileContent , err := projectFile .ReadFile ()
196
+ require .NoError (t , err )
197
+ require .Equal (t , "profiles:\n Uno:\n fqbn: arduino:avr:uno\n platforms:\n - platform: arduino:avr (1.8.6)\n libraries:\n \n " , string (fileContent ))
198
+ }
199
+
200
+ func initWithWrongFqbn (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
201
+ // Adding a profile with an incorrect FQBN should return an error
202
+ _ , stderr , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "wrong_fqbn" , "-b" , "foo:bar" )
203
+ require .Error (t , err )
204
+ require .Contains (t , string (stderr ), "Invalid FQBN" )
205
+ }
206
+
207
+ func initMissingFqbn (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
208
+ // Add a profile with no FQBN should return an error
209
+ _ , stderr , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" )
210
+ require .Error (t , err )
211
+ require .Contains (t , string (stderr ), "Missing FQBN (Fully Qualified Board Name)" )
212
+ }
213
+
214
+ func initExistingProfile (t * testing.T , env * integrationtest.Environment , cli * integrationtest.ArduinoCLI ) {
215
+ // Adding a profile with a name that already exists should return an error
216
+ _ , stderr , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
217
+ require .Error (t , err )
218
+ require .Contains (t , string (stderr ), "the profile already exists" )
219
+ }
220
+
221
+ func TestInitProfileMissingSketchFile (t * testing.T ) {
222
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
223
+ defer env .CleanUp ()
224
+
225
+ // Init the environment explicitly
226
+ _ , _ , err := cli .Run ("core" , "update-index" )
227
+ require .NoError (t , err )
228
+
229
+ _ , stderr , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String ())
230
+ require .Error (t , err )
231
+ require .Contains (t , string (stderr ), "no such file or directory" )
232
+
233
+ err = cli .SketchbookDir ().Join ("Simple" ).MkdirAll ()
234
+ require .NoError (t , err )
235
+ _ , stderr , err = cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String ())
236
+ require .Error (t , err )
237
+ require .Contains (t , string (stderr ), "main file missing from sketch" )
238
+ }
239
+
240
+ func TestInitProfilePlatformNotInstalled (t * testing.T ) {
241
+ env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
242
+ defer env .CleanUp ()
243
+
244
+ // Init the environment explicitly
245
+ _ , _ , err := cli .Run ("core" , "update-index" )
246
+ require .NoError (t , err )
247
+
248
+ _ , _ , err = cli .Run ("sketch" , "new" , cli .SketchbookDir ().Join ("Simple" ).String ())
249
+ require .NoError (t , err )
250
+
251
+ // Adding a profile with a name that already exists should return an error
252
+ _ , stderr , err := cli .Run ("profile" , "init" , cli .SketchbookDir ().Join ("Simple" ).String (), "-m" , "Uno" , "-b" , "arduino:avr:uno" )
253
+ require .Error (t , err )
254
+ require .Contains (t , string (stderr ), "platform not installed" )
255
+ }
0 commit comments