@@ -117,25 +117,33 @@ func executeWithArgs(t *testing.T, args ...string) (exitCode int, output []byte)
117
117
return
118
118
}
119
119
120
+ var currDataDir * paths.Path
121
+
120
122
func makeTempDataDir (t * testing.T ) func () {
121
123
tmp , err := paths .MkTempDir ("" , "test" )
122
124
require .NoError (t , err , "making temporary staging dir" )
123
125
os .Setenv ("ARDUINO_DATA_DIR" , tmp .String ())
126
+ currDataDir = tmp
124
127
fmt .Printf ("ARDUINO_DATA_DIR = %s\n " , os .Getenv ("ARDUINO_DATA_DIR" ))
125
128
return func () {
126
129
os .Unsetenv ("ARDUINO_DATA_DIR" )
130
+ currDataDir = nil
127
131
tmp .RemoveAll ()
128
132
fmt .Printf ("ARDUINO_DATA_DIR = %s\n " , os .Getenv ("ARDUINO_DATA_DIR" ))
129
133
}
130
134
}
131
135
136
+ var currSketchbookDir * paths.Path
137
+
132
138
func makeTempSketchbookDir (t * testing.T ) func () {
133
139
tmp , err := paths .MkTempDir ("" , "test" )
134
140
require .NoError (t , err , "making temporary staging dir" )
135
141
os .Setenv ("ARDUINO_SKETCHBOOK_DIR" , tmp .String ())
142
+ currSketchbookDir = tmp
136
143
fmt .Printf ("ARDUINO_SKETCHBOOK_DIR = %s\n " , os .Getenv ("ARDUINO_SKETCHBOOK_DIR" ))
137
144
return func () {
138
145
os .Unsetenv ("ARDUINO_SKETCHBOOK_DIR" )
146
+ currSketchbookDir = nil
139
147
tmp .RemoveAll ()
140
148
fmt .Printf ("ARDUINO_SKETCHBOOK_DIR = %s\n " , os .Getenv ("ARDUINO_SKETCHBOOK_DIR" ))
141
149
}
@@ -283,7 +291,7 @@ func updateCoreIndex(t *testing.T) {
283
291
}
284
292
285
293
func detectLatestAVRCore (t * testing.T ) string {
286
- jsonFile := paths . New ( os . Getenv ( "ARDUINO_DATA_DIR" )) .Join ("package_index.json" )
294
+ jsonFile := currDataDir .Join ("package_index.json" )
287
295
type index struct {
288
296
Packages []struct {
289
297
Name string
@@ -327,7 +335,7 @@ func TestCoreDownload(t *testing.T) {
327
335
328
336
updateCoreIndex (t )
329
337
AVR := "arduino:avr@" + detectLatestAVRCore (t )
330
- return
338
+
331
339
// Download a specific core version
332
340
exitCode ,
d := executeWithArgs (
t ,
"core" ,
"download" ,
"arduino:[email protected] " )
333
341
require .Zero (t , exitCode , "exit code" )
@@ -355,13 +363,25 @@ func TestCoreDownload(t *testing.T) {
355
363
require .Contains (t , string (d ), "invalid item" )
356
364
357
365
// Empty cores list
358
- exitCode , d = executeWithArgs (t , "core" , "download" , "wrongparameter " )
359
- require .NotZero (t , exitCode , "exit code" )
366
+ exitCode , d = executeWithArgs (t , "core" , "list " )
367
+ require .Zero (t , exitCode , "exit code" )
360
368
require .Empty (t , strings .TrimSpace (string (d )))
361
369
362
370
// Install avr
363
371
exitCode , d = executeWithArgs (t , "core" , "install" , "arduino:avr" )
364
372
require .Zero (t , exitCode , "exit code" )
365
- require .
Contains (
t ,
string (
d ),
"arduino:[email protected] downloaded" )
373
+ require .Contains (t , string (d ), AVR + " - Installed" )
374
+
375
+ exitCode , d = executeWithArgs (t , "core" , "list" )
376
+ require .Zero (t , exitCode , "exit code" )
377
+ require .Contains (t , string (d ), "arduino:avr" )
366
378
379
+ // Build sketch for arduino:avr:uno
380
+ exitCode , d = executeWithArgs (t , "sketch" , "new" , "Test1" )
381
+ require .Zero (t , exitCode , "exit code" )
382
+ require .Contains (t , string (d ), "Sketch created" )
383
+
384
+ exitCode , d = executeWithArgs (t , "compile" , "-b" , "arduino:avr:uno" , currSketchbookDir .Join ("Test1" ).String ())
385
+ require .Zero (t , exitCode , "exit code" )
386
+ require .Contains (t , string (d ), "Sketch uses" )
367
387
}
0 commit comments