@@ -28,6 +28,8 @@ import (
28
28
"runtime"
29
29
"testing"
30
30
31
+ "github.com/spf13/viper"
32
+
31
33
"github.com/arduino/arduino-cli/cli/feedback"
32
34
33
35
"bou.ke/monkey"
@@ -128,25 +130,10 @@ func executeWithArgs(args ...string) (int, []byte) {
128
130
var output []byte
129
131
var exitCode int
130
132
fmt .Printf ("RUNNING: %s\n " , args )
133
+ viper .Reset ()
131
134
132
135
// This closure is here because we won't that the defer are executed after the end of the "executeWithArgs" method
133
136
func () {
134
- // Create an empty config for the CLI test in the same dir of the test
135
- conf := paths .New ("arduino-cli.yaml" )
136
- if conf .Exist () {
137
- panic ("config file must not exist already" )
138
- }
139
-
140
- if err := conf .WriteFile ([]byte ("board_manager:\n additional_urls:\n " )); err != nil {
141
- panic (err )
142
- }
143
-
144
- defer func () {
145
- if err := conf .Remove (); err != nil {
146
- panic (err )
147
- }
148
- }()
149
-
150
137
redirect := & stdOutRedirect {}
151
138
redirect .Open ()
152
139
// re-init feedback so it'll write to our grabber
@@ -365,28 +352,7 @@ func TestCompileCommandsIntegration(t *testing.T) {
365
352
}
366
353
367
354
func TestInvalidCoreURLIntegration (t * testing.T ) {
368
- // override SetUp dirs
369
- tmp := tmpDirOrDie ()
370
- defer os .RemoveAll (tmp )
371
- os .Setenv ("ARDUINO_SKETCHBOOK_DIR" , tmp )
372
- currSketchbookDir = tmp
373
-
374
- configFile := filepath .Join (currDataDir , "arduino-cli.yaml" )
375
- err := ioutil .WriteFile (configFile , []byte (`
376
- board_manager:
377
- additional_urls:
378
- - http://www.invalid-domain-asjkdakdhadjkh.com/package_example_index.json
379
- ` ), os .FileMode (0644 ))
380
- require .NoError (t , err , "writing dummy config " + configFile )
381
-
382
- err = ioutil .WriteFile (filepath .Join (currDataDir , "package_index.json" ), []byte (`{ "packages": [] }` ), os .FileMode (0644 ))
383
- require .NoError (t , err , "Writing empty json index file" )
384
-
385
- err = ioutil .WriteFile (filepath .Join (currDataDir , "package_example_index.json" ), []byte (`{ "packages": [] }` ), os .FileMode (0644 ))
386
- require .NoError (t , err , "Writing empty json index file" )
387
-
388
- err = ioutil .WriteFile (filepath .Join (currDataDir , "library_index.json" ), []byte (`{ "libraries": [] }` ), os .FileMode (0644 ))
389
- require .NoError (t , err , "Writing empty json index file" )
355
+ configFile := filepath .Join ("testdata" , t .Name ())
390
356
391
357
// Dump config with cmd-line specific file
392
358
exitCode , d := executeWithArgs ("--config-file" , configFile , "config" , "dump" )
@@ -399,19 +365,7 @@ board_manager:
399
365
}
400
366
401
367
func Test3rdPartyCoreIntegration (t * testing.T ) {
402
- // override SetUp dirs
403
- tmp := tmpDirOrDie ()
404
- defer os .RemoveAll (tmp )
405
- os .Setenv ("ARDUINO_SKETCHBOOK_DIR" , tmp )
406
- currSketchbookDir = tmp
407
-
408
- configFile := filepath .Join (currDataDir , "arduino-cli.yaml" )
409
- err := ioutil .WriteFile (configFile , []byte (`
410
- board_manager:
411
- additional_urls:
412
- - https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
413
- ` ), os .FileMode (0644 ))
414
- require .NoError (t , err , "writing dummy config " + configFile )
368
+ configFile := filepath .Join ("testdata" , t .Name ())
415
369
416
370
// Update index and install esp32:esp32
417
371
exitCode , _ := executeWithArgs ("--config-file" , configFile , "core" , "update-index" )
@@ -422,7 +376,7 @@ board_manager:
422
376
423
377
// Build a simple sketch and check if all artifacts are copied
424
378
tmpSketch := paths .New (currSketchbookDir ).Join ("Blink" )
425
- err = paths .New ("testdata/Blink" ).CopyDirTo (tmpSketch )
379
+ err : = paths .New ("testdata/Blink" ).CopyDirTo (tmpSketch )
426
380
require .NoError (t , err , "copying test sketch into temp dir" )
427
381
exitCode , d = executeWithArgs ("--config-file" , configFile , "compile" , "-b" , "esp32:esp32:esp32" , tmpSketch .String ())
428
382
require .Zero (t , exitCode )
@@ -543,13 +497,15 @@ func TestSearchConfigTreeNotFound(t *testing.T) {
543
497
544
498
func TestSearchConfigTreeSameFolder (t * testing.T ) {
545
499
tmp := tmpDirOrDie ()
500
+ defer os .RemoveAll (tmp )
546
501
_ , err := os .Create (filepath .Join (tmp , "arduino-cli.yaml" ))
547
502
require .Nil (t , err )
548
503
require .Equal (t , searchConfigTree (tmp ), tmp )
549
504
}
550
505
551
506
func TestSearchConfigTreeInParent (t * testing.T ) {
552
507
tmp := tmpDirOrDie ()
508
+ defer os .RemoveAll (tmp )
553
509
target := filepath .Join (tmp , "foo" , "bar" )
554
510
err := os .MkdirAll (target , os .ModePerm )
555
511
require .Nil (t , err )
0 commit comments