Skip to content

Commit e015cc3

Browse files
committed
Fixed and added more 'core' commands tests
1 parent 74df3f6 commit e015cc3

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

commands/commands_test.go

+25-5
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,33 @@ func executeWithArgs(t *testing.T, args ...string) (exitCode int, output []byte)
117117
return
118118
}
119119

120+
var currDataDir *paths.Path
121+
120122
func makeTempDataDir(t *testing.T) func() {
121123
tmp, err := paths.MkTempDir("", "test")
122124
require.NoError(t, err, "making temporary staging dir")
123125
os.Setenv("ARDUINO_DATA_DIR", tmp.String())
126+
currDataDir = tmp
124127
fmt.Printf("ARDUINO_DATA_DIR = %s\n", os.Getenv("ARDUINO_DATA_DIR"))
125128
return func() {
126129
os.Unsetenv("ARDUINO_DATA_DIR")
130+
currDataDir = nil
127131
tmp.RemoveAll()
128132
fmt.Printf("ARDUINO_DATA_DIR = %s\n", os.Getenv("ARDUINO_DATA_DIR"))
129133
}
130134
}
131135

136+
var currSketchbookDir *paths.Path
137+
132138
func makeTempSketchbookDir(t *testing.T) func() {
133139
tmp, err := paths.MkTempDir("", "test")
134140
require.NoError(t, err, "making temporary staging dir")
135141
os.Setenv("ARDUINO_SKETCHBOOK_DIR", tmp.String())
142+
currSketchbookDir = tmp
136143
fmt.Printf("ARDUINO_SKETCHBOOK_DIR = %s\n", os.Getenv("ARDUINO_SKETCHBOOK_DIR"))
137144
return func() {
138145
os.Unsetenv("ARDUINO_SKETCHBOOK_DIR")
146+
currSketchbookDir = nil
139147
tmp.RemoveAll()
140148
fmt.Printf("ARDUINO_SKETCHBOOK_DIR = %s\n", os.Getenv("ARDUINO_SKETCHBOOK_DIR"))
141149
}
@@ -283,7 +291,7 @@ func updateCoreIndex(t *testing.T) {
283291
}
284292

285293
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")
287295
type index struct {
288296
Packages []struct {
289297
Name string
@@ -327,7 +335,7 @@ func TestCoreDownload(t *testing.T) {
327335

328336
updateCoreIndex(t)
329337
AVR := "arduino:avr@" + detectLatestAVRCore(t)
330-
return
338+
331339
// Download a specific core version
332340
exitCode, d := executeWithArgs(t, "core", "download", "arduino:[email protected]")
333341
require.Zero(t, exitCode, "exit code")
@@ -355,13 +363,25 @@ func TestCoreDownload(t *testing.T) {
355363
require.Contains(t, string(d), "invalid item")
356364

357365
// 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")
360368
require.Empty(t, strings.TrimSpace(string(d)))
361369

362370
// Install avr
363371
exitCode, d = executeWithArgs(t, "core", "install", "arduino:avr")
364372
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")
366378

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")
367387
}

commands/core/list.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
6464
}
6565
}
6666

67-
if len(res) == 0 {
68-
formatter.Print("No cores installed")
69-
} else {
67+
if len(res) > 0 {
7068
formatter.Print(res)
7169
}
7270
}

0 commit comments

Comments
 (0)